git - 使用 rsync 部署 Gitlab 管道
问题描述
我正在尝试部署当前 git 存储库的所有内容(包括分支和提交)并使用 rsync 将其部署到远程服务器。
现在我有我的 gitlab-ci 文件,其中包含以下内容:
image: ubuntu:18.04
.init_development_ssh: &init_development_ssh |
eval $(ssh-agent -s)
mkdir -p ~/.ssh
chmod 700 ~/.ssh
[[ -f /.dockerenv ]] && echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config
ssh-add <(echo "$STAGING_PRIVATE_KEY")
.tag: &tag
tags:
- pixel-rp
stages:
- lint
- deploy
linting code:
# Use the LUA image
image: mhndev/docker-lua
<<: *tag
stage: lint
before_script:
- luarocks install luacheck
script: luacheck fx-server-data
allow_failure: true
deploy to testing:
<<: *tag
stage: deploy
before_script:
- apt -y update && apt -y upgrade && apt install -y openssh-client rsync sshpass
- *init_development_ssh
script:
- sshpass -p "$SSH_PASS" -e "ssh -p 2222" rsync -rav --exclude='.git/' --exclude='.gitlab-ci.yml' --delete-excluded /builds/pixel-rp/pixel-server/ user@IP:/home/user/FXServer/server-data/
我得到的错误是
> Usage: sshpass [-f|-d|-p|-e] [-hV] command parameters
-f filename Take password to use from file
-d number Use number as file descriptor for getting password
-p password Provide password as argument (security unwise)
-e Password is passed as env-var "SSHPASS"
With no parameters - password will be taken from stdin
-P prompt Which string should sshpass search for to detect a password prompt
-v Be verbose about what you're doing
-h Show help (this screen)
-V Print version information
At most one of -f, -d, -p or -e should be used
Conflicting password source
现在我不是 linux 专家,但“需要”记住的参数如下:
- SSH 端口:2222
- SSH 密钥(据我所知)已成功导入
任何知道我如何获取所有内容(不包括某些文件)并将其“推送”到我的远程服务器作为“持续交付”的人吗?
解决方案
根据sshpass的手册页,您可以使用该选项在命令行中指定密码,并在使用该选项时-p
告诉 sshpass 使用环境变量中的密码。SSHPASS
-e
由于您只能指定一次密码,但同时使用了这两个选项,sshpass 不知道从哪里获取密码(从命令行或环境变量),因此失败。
选项-f
(从文件中读取)和-d
(从文件描述符中读取)也不能与任何其他选项结合使用。
推荐阅读
- google-colaboratory - TFF:自定义模型实现
- laravel - 作曲家需要 laravel/ui --dev
- cakephp - PhpStorm 2019.3 读取 CakePhp 翻译为 SQL 命令
- azure-cosmosdb - 更新文档时 ttl 是否刷新?
- java - Java spring boot 更新实体导致超时和错误实体
- search - 安装记录管理后,Alfresco solr/search 停止工作
- css - CSS Grid:在特定 x 位置开始列
- python - 列表理解甚至列表元素而不是循环以及如何仅引用索引
- php - 选择所有帖子及其类别和标签以显示在主页中
- reactjs - 将反应组件加载到与包含其链接的 div 不同的 div 中