我正在尝试使用Deployer在我的Gitlab CI/CD
项目上设置Symfony
,但是我不能这样做。
在管道上执行部署后,我有一个Operation timed out error
,这意味着我的配置错误。
我的gitlab-ci.yml:
image: php:7.4-cli-alpine
stages:
- deploy
before_script:
- apk add --update git openssh-client
- mkdir -p ~/.ssh && echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config
- eval $(ssh-agent -s)
- echo "$SSH_PRIVATE_KEY" | ssh-add -
deploy:
stage: deploy
script:
- curl --show-error --silent https://getcomposer.org/installer | php
- php composer.phar install -d app/
- app/vendor/bin/dep deploy dev -vvv
environment:
name: prod
我的hosts.yml广告资源:
dev-server.com:
stage: dev
hostname: XX.XXX.XX.X
user: deployer
branch: develop
identityFile: ~/.ssh/gitlab
deploy_path: /var/www/recruitment_back
keep_releases: 1
我的Gitlab管道错误:
$ app/vendor/bin/dep deploy dev -vvv
✈︎ Deploying develop on XX.XXX.XX.X
• done on [dev-server.com]
➤ Executing task deploy:prepare
[dev-server.com] > export APP_ENV='prod'; echo $0
[dev-server.com] < ssh multiplexing initialization
[dev-server.com] < ssh: connect to host XX.XXX.XX.X port 22: Operation timed out
➤ Executing task deploy:failed
• done on [dev-server.com]
✔ Ok [0ms]
我还在SSH_PRIVATE_KEY
设置中添加了变量Gitlab CI/CD
,并在服务器上的authorized_keys
中添加了公共ssh密钥。
在本地计算机上执行时,部署工作正常。
我的配置出了什么问题?
答案 0 :(得分:0)
我的解决方案:
PRIVATE_KEY
变量 git clone
操作ssh-keyscan -t rsa gitlab.com >> ~/.ssh/known_hosts
我的gitlab-ci.yml:
image: php:7.4
stages:
- deploy
before_script:
- 'which ssh-agent || ( apt-get update -y && apt-get install openssh-client -y )'
- eval $(ssh-agent -s)
- ssh-add <(echo "$PRIVATE_KEY")
- mkdir -p ~/.ssh
- '[[ -f /.dockerenv ]] && echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config'
- apt-get install -y curl git
- curl -LO https://deployer.org/deployer.phar
- mv deployer.phar /usr/local/bin/dep
- chmod +x /usr/local/bin/dep
deploy:
stage: deploy
script:
- dep deploy dev -vvv
only:
- develop
如果有更好的解决方案。请让我知道。