Deploy using SCP

This guide will show you how to deploy your files to a remote host using the SCP-deploy pipe in Bitbucket Pipelines.

For this example we created simple ReactApp and deployed it to production with the SCP-deploy pipe.

A full end-to-end example is available in this repository if you prefer a more hands-on experimentation with deploying to your host using Pipelines and Pipes.

Prerequisites:

  • Remote host with ssh access

  • Bitbucket repository

Step 1: Configure your Bitbucket repository for the project

Add your credentials and configuration settings in Bitbucket as variables (see: how to configure Pipelines variables).

名前
USER

The user that is configured on the remote host.

SERVER

The remote host to transfer the files to.


You can define these variables at the deployment environment, repository, or team level. The example below is shown with a repository variable.

Step 2: Configure your SSH keys

Set up an SSH key in Bitbucket Pipelines or provide it as a secured variable: SSH_KEY (see using multiple ssh keys). By default, the SCP-deploy pipe will use your configured SSH key and known_hosts file.

Step 3: Configure your server

On your remote host (sometimes called a production node):

  • Allow users to connect on HTTP (port 80).
  • Configure ssh keys to allow access.

Here's a configuration example using NGINX on the server. Note: this configuration is intended for demo purposes only.

server {
        listen 80;
        listen [::]:80;

        root /var/www/scp-deploy/html;
        index index.html index.htm;

        server_name <your_host_public_DNS_name>, <example.com>;

        location / {
                try_files $uri $uri/ =404;
        }
}

Step 4: Setup your CI/CD configuration

Edit your bitbucket-pipelines.yml file:

To find out more about the SCP-deploy pipe, select it in the right of the editor.

Add these steps to bitbucket-pipelines.yml :

image: node:10.15.3

pipelines:
  default:
    - step:
        name: Build and test
        caches:
          - node
        script:
          - npm install 
          - npm test
          - npm run build
        artifacts:
          - build/**
    - step:
        name: Deploy artifacts using SCP to PROD
        deployment: production
        script:
          - pipe: atlassian/scp-deploy:0.3.3
            variables:
              USER: $USER
              SERVER: $SERVER
              REMOTE_PATH: '/var/www/scp-deploy/html'
              LOCAL_PATH: 'build/*'

This configuration allows you to run tests, build, and deploy your files to the remote host using the SCP-deploy pipe after each push to the Bitbucket repository. Learn more about how to edit and configure your Bitbucket pipelines configuration.


Step 5: Deploy application to production

Push your application’s code to your Bitbucket repository which will trigger the pipeline. You can then select Pipelines  to check pipeline progress. 

Now you can focus on building your great application, everything else is handled with Bitbucket Pipelines!


最終更新日 2019 年 6 月 20 日

この内容はお役に立ちましたか?

はい
いいえ
この記事についてのフィードバックを送信する
Powered by Confluence and Scroll Viewport.