bash Gitlab CI 部署 AWS EC2

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/51032256/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 16:57:24  来源:igfitidea点击:

Gitlab CI deploy AWS EC2

bashamazon-web-servicescontinuous-integrationgitlab-ci

提问by Ulises

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

我们有一个 lumen 应用程序,我们将项目移动到 GitLab,如果一切正常,我们想拉动项目。

We add the two scripts:

我们添加两个脚本:

.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

our deploy script ".gitlab-deploy.sh" looks like:

我们的部署脚本“.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

We already add the configuration:

我们已经添加了配置:

enter image description here

在此处输入图片说明

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

当我们将更改推送到 repo/master 时,我们在仪表板上看到了下一个错误:

enter image description here

在此处输入图片说明

So what we are missing? Any advice?

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

回答by Ulises

I just change the for to this for make it work:

我只是将 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