-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.gitlab-ci.yml
130 lines (120 loc) · 4.55 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
# as documented here https://gitlab.gwdg.de/gfbio/cicd :
include:
- project: gfbio/cicd
file:
- '.create_merge_request_v3.yml'
- '.web_test_v2.yml'
- '.tag_release.yml'
- '.hotfix_workflow.yml'
# TODO: unit-tests is conflicting with release, since both currently run on the same machine and cause errors when using the same docker network
# - unit_tests
stages:
- check_issue_type
- create_merge_request
- create_hotfix_merge_request
- tag_release_check
- tag_release
- web_test_check
- web_test_update
- web_test_stop
- deploy_dev
#run_unit_tests:
# stage: unit_tests
# before_script:
# - sudo rm -rf .pytest_cache
# - rsync -a /home/gitlab-runner/.envs .
# - docker-compose -f local.yml build
# # - docker-compose -f local.yml run --rm django python manage.py migrate
# script:
# - docker-compose -f local.yml run django pytest
# after_script:
# - sudo rm -rf .pytest_cache
# tags:
# - gfbio-dmp-prod
create_merge_request:
variables:
PROJECT_NAME: "gfbio-dmp"
tags:
- dev-denbi
tag_release_check:
variables:
MAIN_BRANCH_NAME: "production"
tags:
- dev-denbi
tag_release:
script:
- rsync -a /home/gitlab-runner/.envs .
- docker-compose -f production.yml down
- docker-compose -f production.yml build
- docker-compose -f production.yml up -d postgres
- docker-compose -f production.yml run --rm postgres backup
- docker-compose -f production.yml run --rm django python manage.py migrate
# - TODO: add js built and copy commands here
- docker-compose -f production.yml run --rm django python manage.py collectstatic --noinput
- docker-compose -f production.yml down
- docker-compose -f production.yml up -d
environment:
name: production
url: https://dmp.gfbio.org
tags:
- gfbio-dmp-prod
# ------------------------- WEBTEST ---------------------------
# add your commands under "your custom commands" section
# example: 123-foo-bar with project name ammod will create stack named 123-ammod
# in this example you can also see how to get ISSUE_ID from branch
# PROJECT_NAME - should be specified, default is project-id
# COMPOSE_FILE - should be specified, default is production.yml
web_test_update:
variables:
PROJECT_NAME: "gfbio-dmp"
COMPOSE_FILE: "web-test.yml"
script:
# get issue id and test name
- ISSUE_ID=$(awk -F- '{print $2}' <<< ${CI_COMMIT_REF_NAME})
- TEST_NAME=$ISSUE_ID-$PROJECT_NAME
# your custom commands
- rm -r ./.envs/
- cp -r /home/gitlab-runner/.gfbio_dmp_envs/ ./.envs/
- sed -i s/DJANGO_ALLOWED_HOSTS=.*/DJANGO_ALLOWED_HOSTS=\.$TEST_NAME\.test.gfbio\.dev/g .envs/.production/.django
- sed -i s/BRANCH/${TEST_NAME}/g $COMPOSE_FILE
# remove email verification requirements from web-test
- sed -i 's/ACCOUNT_EMAIL_VERIFICATION = "mandatory"/ACCOUNT_EMAIL_VERIFICATION = "none"/g' config/settings/base.py
# set super user credentials from GitLab CI/CD Variables
- sed -i s/ADMIN_NICKNAME=/ADMIN_NICKNAME=${ADMIN_NICKNAME}/g ./compose/production/django/ci_start
- sed -i s/ADMIN_EMAIL=/ADMIN_EMAIL=${ADMIN_EMAIL}/g ./compose/production/django/ci_start
- sed -i s/ADMIN_PASSWORD=/ADMIN_PASSWORD=${ADMIN_PASSWORD}/g ./compose/production/django/ci_start
# TODO: add dmpt-app specific build and copy commands
# - cd ammod_ui && npm i && npm run collect
# - cd ../
- docker-compose -f $COMPOSE_FILE build
# run docker stack
- docker stack rm $TEST_NAME || true
- while [[ $(docker ps | grep $TEST_NAME | wc -l) > 0 ]]; do sleep 1; done
- docker stack deploy -c $COMPOSE_FILE $TEST_NAME
# will stop running environmnet
web_test_stop:
variables:
MAIN_BRANCH_NAME: "master"
PROJECT_NAME: "gfbio-dmp"
deploy_dev:
stage: deploy_dev
variables:
MAIN_BRANCH_NAME: "master"
rules:
- if: '$CI_COMMIT_BRANCH == $MAIN_BRANCH_NAME && $CI_COMMIT_MESSAGE =~ /.*Merge branch.*\w+-\d+.*into.*/'
script:
- rsync -a /home/gitlab-runner/.envs .
- docker-compose -f production.yml down
- docker-compose -f production.yml build
- docker-compose -f production.yml up -d postgres
- docker-compose -f production.yml run --rm postgres backup
- docker-compose -f production.yml run --rm django python manage.py migrate
# - TODO: add js built and copy commands here
- docker-compose -f production.yml run --rm django python manage.py collectstatic --noinput
- docker-compose -f production.yml down
- docker-compose -f production.yml up -d
environment:
name: development
url: https://dmp.gfbio.dev
tags:
- gfbio-dmp-dev