Gitlab CI deploy AWS EC2

ⅰ亾dé卋堺 提交于 2020-01-11 12:33:33

问题


we have a lumen application we move the project to GitLab we wanna pull the project if all is ok.

We add the two scripts:

.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

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

We already add the configuration:

When we push changes to the repo/master we saw on the dashboard log the next error:

So what we are missing? Any advice?


回答1:


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


来源:https://stackoverflow.com/questions/51032256/gitlab-ci-deploy-aws-ec2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!