google-cloud-platform - 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:
...
解决方案
I've managed to deploy to FTP with ncftp
:
- first patch
/etc/apt/sources.list
. - then install
ncftp
withapt-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.
推荐阅读
- arduino - 如何获得 +IPD 响应的值
- fortran - 如何在 Fortran 中使用 bignum
- rabbitmq - 如何从独占队列迁移消息?
- python - 编写一个函数,将 2D 数组作为输入并返回 'Square' 、 'Rectangular' 或 'Invalid'
- laravel - 这些路线有什么区别?
- bootstrap-4 - 如何选择多个国家
- angular6 - 模拟点击的 jquery().trigger 方法不起作用,但 nativeElement.click 可以
- c++ - 将 &variable 传递给函数
- javascript - 构建 Microsoft CodePush 时收到 javascript 堆内存不足
- python - PySide2/QML 在给定的根索引处过滤分层数据