Alexandre Hausherr's Blog

Alexandre Hausherr's Blog

Static website SFTP deployment with Bitbucket Pipelines

I have a web hosting at OVH which allows me to deploy only with SFTP (or FTP but it is not secure).

The sources of my website are verisonned with Git on Bitbucket and I have an automatic deployment at every push on the master branch. The build is simple : it makes a NodeJS build followed by an SFTP upload using the SFTP Pipe from Bitbucket :

pipelines:
  default:
    - step:
        deployment: production
        caches:
          - node
        script:
          - npm install
          - npm run build
          - pipe: atlassian/sftp-deploy:0.5.6
            variables:
              USER: 'toto'
              SERVER: 'ftp.moncluster.ovh.net'
              REMOTE_PATH: '/home/toto/www/' 
              LOCAL_PATH: '-r dist/.'
              PASSWORD: 'password'
              EXTRA_ARGS: '-oStrictHostKeyChecking=no'

The configuration above is equal to the following commands :

$> sftp -oStrictHostKeyChecking=no toto@ftp.moncluster.ovh.net
sftp> cd www
sftp> mput -r dist/.

The -r option recursively copies directories. The local path dist/. includes local folders even if they don't exist on remote host, and dotfiles like '.htaccess'.

I had difficulties to find this path trick allowing me to send everything in one step. Before that I was using the dist/* local path but it was ignoring .htaccess and local folders if they didn't exist remotely.

 
Share this