-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.gitlab-ci.yml
61 lines (58 loc) · 1.53 KB
/
.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
stages:
- dockerize
- deploy
.base_rules:
rules:
- &staging_tag
if: $CI_COMMIT_TAG =~ /^v\d+-beta$/
variables:
ENVIRONMENT: "staging"
APP_VERSION: $CI_COMMIT_TAG
- &prod_tag
if: $CI_COMMIT_TAG =~ /^v\d+$/
variables:
ENVIRONMENT: "production"
APP_VERSION: $CI_COMMIT_TAG
dockerize:
stage: dockerize
image: docker:25
services:
- docker:25-dind
environment:
name: $ENVIRONMENT
url: $ENVIRONMENT_URL
variables:
# Extra slash '/' is needed properly append the project path see docker-compose.yml
REGISTRY_PATH: $CI_REGISTRY/$CI_PROJECT_PATH/
VERSION: $CI_ENVIRONMENT_SLUG
COMMIT_REF: $CI_COMMIT_TAG
script:
- mv $ENV_FILE ./.env
- export REGISTRY_PATH=$(echo "$REGISTRY_PATH" | tr '[:upper:]' '[:lower:]')
- docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
- docker compose build
- docker compose push
rules:
- *staging_tag
- *prod_tag
deploy:
stage: deploy
image: docker:25
services:
- docker:25-dind
environment:
name: $ENVIRONMENT
url: $ENVIRONMENT_URL
before_script:
- "which ssh-agent || ( apt-get update -y && apt-get install openssh-client -y )"
- mkdir -p ~/.ssh
- eval $(ssh-agent -s)
- '[[ -f /.dockerenv ]] && echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config'
script:
- mv $ENV_FILE ./prod/.env
- ssh-add <(echo "$SSH_PRIVATE_KEY" | tr -d '\r')
- cd prod
- sh docker_deploy.sh
rules:
- *staging_tag
- *prod_tag