Gitlab CI部署AWS EC2 [英] Gitlab CI deploy AWS EC2
本文介绍了Gitlab CI部署AWS EC2的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我们有一个流明应用程序,将项目移至GitLab,如果一切正常,我们希望将其拉出.
we have a lumen application we move the project to GitLab we wanna pull the project if all is ok.
我们添加了两个脚本:
.gitlab-ci.yml:
.gitlab-ci.yml:
variables:
- All or variables
stages:
- test
- production
testing:
type: test
image: php:7.1
script:
- echo "ok"
#Production stage
production:
stage: production
before_script:
- mkdir -p ~/.ssh
- echo -e "$SSH_PRIVATE_KEY" > ~/.ssh/id_rsa
- chmod 600 ~/.ssh/id_rsa
- '[[ -f /.dockerenv ]] && echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config'
script:
- bash .gitlab-deploy.sh
environment:
name: production
url: https://alpha.merci.network/
when: manual
我们的部署脚本".gitlab-deploy.sh"如下所示:
our deploy script ".gitlab-deploy.sh" looks like:
#!/bin/bash
#Get servers list
set -f
string=$DEPLOY_SERVER
array=(${string//,/ })
#Iterate servers for deploy and pull last commit
for i in "${!array[@]}"do
echo "Deploy project on server ${array[i]}"
ssh ubuntu@${array[i]} "cd /var/www && git pull origin master"
done
我们已经添加了配置:
当我们将更改推送到仓库/主数据库时,我们在仪表板上看到了下一个错误:
When we push changes to the repo/master we saw on the dashboard log the next error:
那么我们缺少了什么?有什么建议吗?
So what we are missing? Any advice?
推荐答案
我只是为此更改了for使其起作用:
I just change the for to this for make it work:
for i in "${!array[@]}"; do
echo "Deploying information to EC2 and Gitlab"
echo "Deploy project on server ${array[i]}"
ssh ubuntu@${array[i]} "cd /var/www/merci_deploy_api && git pull origin master"
done
这篇关于Gitlab CI部署AWS EC2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文