自托管 gitlab 自动部署到 aws ec2 服务器
Self-hosting gitlab autodeploy to aws ec2 server
我问这个是因为我找不到与我的情况相似的 运行ning 示例。我在 AWS EC2 机器上有这个自托管的 Gitlab(我们称之为 "machine 1",我想将自动部署设置到我的 AWS EC2 远程服务器,称为 "machine 2".
我的 Gitlabs 安装显示(机器 1):
gitlab-ce 10.4.4
gitlab 配置模板 10.4.4
gitlab-食谱 10.4.4
gitlab-ctl 10.4.4
gitlab-healthcheck
gitlab-monitor
gitlab-页面
gitlab-psql
gitlab-rails
gitlab-脚本
gitlab-selinux
gitlab-shell
gitlab-workhorse
我已按照 gitlab 说明在我的项目中设置 CI 和 gitlab 文档上的 CD 我想设置自动部署。以下步骤如下:
1.I 已经在 gitlabs 文档之后创建了 运行ner,除了 (machine 2):
url: https://url.to.my.compute.amazonaws.com
Token : token given by gitlab
Executor: shell
Tags: build deploy qa stage
2.I 已经创建了我的 .gitlab-ci.yml (在根项目中)文件(即使我尝试创建了两个 yml 文件版本):
yml 2:
stages:
- build
- deploy
build:
stage: build
script: echo "Building the app"
deploy_staging:
stage: deploy
script:
- echo "Deploy to staging server"
yml 1:
#develop stage
deploy:
stage: deploy
before_script:
#generate ssh key
- mkdir -p ~/.ssh
- echo -e "$SSH_PRIVATE_KEY" > ~/.ssh/id_rsa
- chmod 600 ~/.ssh/id_rsa
script:
- bash .gitlab-deploy.sh
environment:
name: develop
url: https://my.domain.com
when: manual
3.I 设置了两个秘密变量
SSH_PRIVATE_KEY 和 DEPLOY_SERVERS(分别带有密钥和 ips)
4.I 添加了一个 deploy.sh 文件(在我的项目的根目录中)
#!/bin/bash
#Get servers list
set -f
string=$DEPLOY_SERVERS
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/html/app && git pull origin develop"
done
我的 gitlab-运行ner 在这个时刻向我展示:
gitlab-运行ner验证
警告:运行 在用户模式下。
警告:用户模式 requires 你手动启动 builds 处理:
警告:$ gitlab-运行ner 运行
警告:对系统模式使用 sudo:
警告:$ sudo gitlab-运行ner...
并且 运行 像 sudo 一样显示我的 运行ner :
Verifying runner... is alive runner=
Verifying runner... is alive runner=
Verifying runner... is alive runner=
但仍在 gitlabs ui 正在获取 "STUCK" 标签,工作告诉我 "job is stuck, check runners"
问题:
这是所有要遵循的步骤吗?
你看到我在所有这些配置中遗漏的任何东西(或过程)吗?
在我的 gitlab 远程我有 "master" 权限,这是我需要 运行 一个 运行ner 吗?
此时我该如何调试(我正在使用 gitlab-运行ner --debug verify )我能做到吗?
在此先感谢您的帮助。
当跑步者是 "specific" 时,阶段需要 "tag" 如:
stages:
- build
- deploy
build:
stage: build
script: echo "Building the app"
deploy_staging:
stage: deploy
script:
- echo "Deploy to staging server"
tags:
- deploy
我问这个是因为我找不到与我的情况相似的 运行ning 示例。我在 AWS EC2 机器上有这个自托管的 Gitlab(我们称之为 "machine 1",我想将自动部署设置到我的 AWS EC2 远程服务器,称为 "machine 2".
我的 Gitlabs 安装显示(机器 1):
gitlab-ce 10.4.4
gitlab 配置模板 10.4.4
gitlab-食谱 10.4.4
gitlab-ctl 10.4.4
gitlab-healthcheck
gitlab-monitor
gitlab-页面
gitlab-psql
gitlab-rails
gitlab-脚本
gitlab-selinux
gitlab-shell
gitlab-workhorse
我已按照 gitlab 说明在我的项目中设置 CI 和 gitlab 文档上的 CD 我想设置自动部署。以下步骤如下:
1.I 已经在 gitlabs 文档之后创建了 运行ner,除了 (machine 2):
url: https://url.to.my.compute.amazonaws.com
Token : token given by gitlab
Executor: shell
Tags: build deploy qa stage
2.I 已经创建了我的 .gitlab-ci.yml (在根项目中)文件(即使我尝试创建了两个 yml 文件版本):
yml 2:
stages:
- build
- deploy
build:
stage: build
script: echo "Building the app"
deploy_staging:
stage: deploy
script:
- echo "Deploy to staging server"
yml 1:
#develop stage
deploy:
stage: deploy
before_script:
#generate ssh key
- mkdir -p ~/.ssh
- echo -e "$SSH_PRIVATE_KEY" > ~/.ssh/id_rsa
- chmod 600 ~/.ssh/id_rsa
script:
- bash .gitlab-deploy.sh
environment:
name: develop
url: https://my.domain.com
when: manual
3.I 设置了两个秘密变量
SSH_PRIVATE_KEY 和 DEPLOY_SERVERS(分别带有密钥和 ips)
4.I 添加了一个 deploy.sh 文件(在我的项目的根目录中)
#!/bin/bash
#Get servers list
set -f
string=$DEPLOY_SERVERS
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/html/app && git pull origin develop"
done
我的 gitlab-运行ner 在这个时刻向我展示:
gitlab-运行ner验证
警告:运行 在用户模式下。
警告:用户模式 requires 你手动启动 builds 处理:
警告:$ gitlab-运行ner 运行
警告:对系统模式使用 sudo:
警告:$ sudo gitlab-运行ner...
并且 运行 像 sudo 一样显示我的 运行ner :
Verifying runner... is alive runner=
Verifying runner... is alive runner=
Verifying runner... is alive runner=
但仍在 gitlabs ui 正在获取 "STUCK" 标签,工作告诉我 "job is stuck, check runners"
问题:
这是所有要遵循的步骤吗?
你看到我在所有这些配置中遗漏的任何东西(或过程)吗?
在我的 gitlab 远程我有 "master" 权限,这是我需要 运行 一个 运行ner 吗?
此时我该如何调试(我正在使用 gitlab-运行ner --debug verify )我能做到吗?
在此先感谢您的帮助。
当跑步者是 "specific" 时,阶段需要 "tag" 如:
stages:
- build
- deploy
build:
stage: build
script: echo "Building the app"
deploy_staging:
stage: deploy
script:
- echo "Deploy to staging server"
tags:
- deploy