gitlab-cicd
CICD 工具
RedisLive
容器间通信
1 | version: '2' |
gitlab cicd docker-compose
.gitlab-ci.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71image: creatiwww/docker-compose:latest
services:
- docker:dind
variables:
STAGE_SERVER_IP: 10.10.10.1
PROD_SERVER_IP: 10.10.10.2
STAGE_SERVER_USER: gitlab
PROD_SERVER_USER: gitlab
STAGE_IMAGE_APP_TAG: registry.my_organiation.org/development/amazing_app/app:stage
PROD_IMAGE_APP_TAG: registry.my_organiation.org/development/amazing_app/app:prod
EXTERNAL_SERVICE_STAGE_API_BASE_URL: https://test.some-service.com/
EXTERNAL_SERVICE_PROD_API_BASE_URL: https://some-service.com/
stages:
- build
- staging
- release
- deploy
build:
stage: build
script:
- docker login -u gitlab-ci-token -p $CI_BUILD_TOKEN $CI_REGISTRY_IMAGE
- echo "IMAGE_APP_TAG=$STAGE_IMAGE_APP_TAG" >> .env
- docker-compose build
- docker-compose push
only:
- pre-prod
- master
deploy-to-stage:
stage: staging
script:
- eval $(ssh-agent -s)
- echo "$SSH_STAGE_SERVER_PRIVATE_KEY" | tr -d '\r' | ssh-add - > /dev/null
- docker login -u gitlab-ci-token -p $CI_BUILD_TOKEN $CI_REGISTRY_IMAGE
- echo "EXTERNAL_SERVICE_KEY=$EXTERNAL_SERVICE_STAGE_KEY" >> .env
- echo "IMAGE_APP_TAG=$STAGE_IMAGE_APP_TAG" >> .env
- docker-compose -H "ssh://$STAGE_SERVER_USER@$STAGE_SERVER_IP" down --remove-orphans
- docker-compose -H "ssh://$STAGE_SERVER_USER@$STAGE_SERVER_IP" pull
- docker-compose -H "ssh://$STAGE_SERVER_USER@$STAGE_SERVER_IP" up -d
only:
- pre-prod
- master
release:
stage: release
script:
- docker login -u gitlab-ci-token -p $CI_BUILD_TOKEN $CI_REGISTRY_IMAGE
- echo "IMAGE_APP_TAG=$PROD_IMAGE_APP_TAG" >> .env
- docker-compose build
- docker-compose push
only:
- master
deploy-to-prod:
stage: deploy
script:
- eval $(ssh-agent -s)
- echo "$SSH_PROD_SERVER_PRIVATE_KEY" | tr -d '\r' | ssh-add - > /dev/null
- docker login -u gitlab-ci-token -p $CI_BUILD_TOKEN $CI_REGISTRY_IMAGE
- echo "EXTERNAL_SERVICE_KEY=$EXTERNAL_SERVICE_PROD_KEY" >> .env
- echo "IMAGE_APP_TAG=$PROD_IMAGE_APP_TAG" >> .env
- docker-compose -H "ssh://$PROD_SERVER_USER@$PROD_SERVER_IP" down --remove-orphans
- docker-compose -H "ssh://$PROD_SERVER_USER@$PROD_SERVER_IP" pull
- docker-compose -H "ssh://$PROD_SERVER_USER@$PROD_SERVER_IP" up -d
only:
- master
when: manual
本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来自 Jacker-zzk's Blog!