Gitlab CI部署AWS EC2

时间:2018-06-25 21:49:41

标签: bash amazon-web-services continuous-integration gitlab

我们有一个流明应用程序,将项目移至GitLab,如果一切正常,我们希望将其拉出。

我们添加了两个脚本:

.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”如下所示:

#!/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

我们已经添加了配置:

enter image description here

当我们将更改推送到仓库/主数据库时,我们在仪表板上看到了下一个错误:

enter image description here

那么我们缺少了什么?有什么建议吗?

1 个答案:

答案 0 :(得分:1)

我只是为此更改了for使其起作用:

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