-
Notifications
You must be signed in to change notification settings - Fork 2
/
swarm.yml
42 lines (40 loc) · 1.55 KB
/
swarm.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
variables:
DEPLOY_BASE_DOMAIN: 127.0.0.1.xip.io
DEPLOY_NAME: $CI_PROJECT_ID-$CI_ENVIRONMENT_SLUG
DEPLOY_DOMAIN: $DEPLOY_NAME.$DEPLOY_BASE_DOMAIN
DEPLOY_STACK_FILE: docker-compose.yml
DEPLOY_USER: $CI_REGISTRY_USER
DEPLOY_PASSWORD: $CI_JOB_TOKEN
DEPLOY_WAIT_TIME:
value: '30'
description: 'The time to wait docker swarm download image'
.deploy:
image: docker:stable
stage: deploy
environment:
url: $DEPLOY_DOMAIN
before_script:
- echo -e "\e[0Ksection_start:`date +%s`:setup_docker[collapsed=true]\r\e[0KSetup Docker"
- if [[ -v CI_DEPLOY_USER ]] && [[ -v CI_DEPLOY_PASSWORD ]]; then export DEPLOY_USER=$CI_DEPLOY_USER; DEPLOY_PASSWORD=$CI_DEPLOY_PASSWORD; fi
- echo "$DEPLOY_PASSWORD" | docker login -u $DEPLOY_USER --password-stdin $CI_REGISTRY
- apk -Uuv add curl
- curl -LO https://github.com/sudo-bmitch/docker-stack-wait/raw/main/docker-stack-wait.sh
- chmod +x docker-stack-wait.sh
- if [[ "$CI_ENVIRONMENT_NAME" == "production" ]]; then export RAILS_MASTER_KEY=${RAILS_PRODUCTION_KEY:-$RAILS_MASTER_KEY}; fi
- echo -e "\e[0Ksection_end:`date +%s`:setup_docker\r\e[0K"
script:
- docker stack deploy -c $DEPLOY_STACK_FILE --with-registry-auth --prune $DEPLOY_NAME
- sleep $DEPLOY_WAIT_TIME
- ./docker-stack-wait.sh -r $DEPLOY_NAME
- echo "DEPLOY_DOMAIN=http://$DEPLOY_DOMAIN" >> deploy.env
resource_group: deploy
artifacts:
reports:
dotenv: deploy.env
.deploy:stop:
image: docker:stable
stage: deploy
environment:
action: stop
script:
- docker stack rm $DEPLOY_NAME