首页 > 解决方案 > Cloud Build Trigger for FTP or SSH deployment

问题描述

How can I deploy a directory to a FTP or SSH server, with a trigger and cloudbuild.yaml?

So far I can already generate a listing of the files which I'd like to upload:

steps:
  - name: 'ubuntu'
    entrypoint: 'bash'
    args:
      - '-c'
      - |-
        find $_UPLOAD_DIRNAME -exec echo {} >> batch.txt \;
        cat ./batch.txt
    env:
      ...

标签: google-cloud-platformsshgoogle-compute-enginegoogle-cloud-buildgoogle-source-repositories

解决方案


I've managed to deploy to FTP with ncftp:

  • first patch /etc/apt/sources.list.
  • then install ncftp with apt-get.
  • create the file ~/.ncftp with variable substitutions.
  • optional step: replace text in files with sed.
  • recursively upload the directory with ncftpput.

Here's my cloudbuild.yaml (it is working, but the next answer might offer a better solution):

steps:
  - name: 'ubuntu'
    entrypoint: 'bash'
    args:
      - '-c'
      - |-
        echo Deploying ${_UPLOAD_DIRNAME} @ ${SHORT_SHA} 
        echo to ftp://${_REMOTE_ADDRESS}${_REMOTE_PATH}
        echo "deb http://archive.ubuntu.com/ubuntu/ focal universe" > /etc/apt/sources.list
        apt-get update -y && apt-get install -y ncftp
        cat << EOF > ~/.ncftp
        host $_REMOTE_ADDRESS
        user $_FTP_USERNAME
        pass $_FTP_PASSWORD
        EOF
        # sed -i "s/##_GIT_COMMIT_##/${SHORT_SHA}/g" ./${_UPLOAD_DIRNAME}/plugin.php 
        ncftpput -f ~/.ncftp -R $_REMOTE_PATH $_UPLOAD_DIRNAME
    env:
      - '_UPLOAD_DIRNAME=$_UPLOAD_DIRNAME'
      - '_REMOTE_ADDRESS=$_REMOTE_ADDRESS'
      - '_REMOTE_PATH=$_REMOTE_PATH'
      - '_FTP_USERNAME=$_FTP_USERNAME'
      - '_FTP_PASSWORD=$_FTP_PASSWORD'
      - 'SHORT_SHA=$SHORT_SHA'

Where _REMOTE_PATH is eg. /wp-content/plugins (the variable requires at least one slash) and the _UPLOAD_DIRNAME is the name of the directory within the local Git repository, with no slashes.


推荐阅读