-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.gitlab-ci.yml
133 lines (119 loc) · 3.98 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
130
131
132
133
include:
- project: gfbio/cicd
file:
- '.create_merge_request_v3.yml'
- '.web_test_v2.yml'
- '.tag_release.yml'
- '.hotfix_workflow.yml'
stages:
- check_issue_type
- create_merge_request
- create_hotfix_merge_request
- lint
- test
- update_stage
- web_test_check
- web_test_update
- web_test_stop
- tag_release_check
- tag_release
variables:
POSTGRES_USER: 'collection_service'
POSTGRES_PASSWORD: ''
POSTGRES_DB: 'test_collection_service'
POSTGRES_HOST_AUTH_METHOD: trust
CELERY_BROKER_URL: 'redis://redis:6379/0'
DOCKER_TLS_CERTDIR: ''
create_merge_request:
tags:
- development-denbi
flake8:
stage: lint
image: python:3.9-alpine
before_script:
- pip install -q flake8
script:
- flake8
tags:
- col-svc
pytest:
stage: test
image: docker/compose:1.29.2
tags:
- col-svc
services:
- docker:dind
before_script:
- docker-compose -f local.yml build
# Ensure celerybeat does not crash due to non-existent tables
- docker-compose -f local.yml run --rm django python manage.py migrate
- docker-compose -f local.yml up -d
script:
- docker-compose -f local.yml run django pytest
# 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: "collections"
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 -rf .envs && cp -r /home/gitlab-runner/.collection_envs ./.envs/
- sed -i s/BRANCH/${TEST_NAME}/g $COMPOSE_FILE
- sed -i s/BRANCH/${TEST_NAME}/g ./.envs/.production/.django
- sed -i "s/VERSION =.*/VERSION ='$(git describe --tags | egrep -o '[0-9]+\.[0-9]+\.[0-9]+')'/g" config/settings/base.py
- sed -i "s/http:\/\/localhost:8000/https:\/\/${TEST_NAME}.test.gfbio.dev/g" config/settings/base.py
- 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: "collection"
update_staging:
stage: update_stage
tags:
- col-svc-shell
script:
- rm -r .envs && cp -r /home/gitlab-runner/.envs/ .envs
- sed -i "s/VERSION =.*/VERSION ='$(git describe --tags | egrep -o '[0-9]+\.[0-9]+\.[0-9]+')'/g" config/settings/base.py
- sed -i "s/http:\/\/localhost:8000/https:\/\/collections.gfbio.dev/g" config/settings/base.py
- docker-compose -f staging.yml build
- docker-compose -f staging.yml up -d postgres
- docker-compose -f staging.yml run --rm postgres backup
- docker-compose -f staging.yml down
- docker-compose -f staging.yml up -d
environment:
name: staging
url: https://collections.gfbio.dev/
rules:
- if: '$CI_COMMIT_BRANCH == "master"'
tag_release_check:
variables:
MAIN_BRANCH_NAME: "production"
tags:
- col-svc-prod
tag_release:
script:
- rm -r .envs && cp -r /home/gitlab-runner/.envs/ .envs
- sed -i "s/VERSION =.*/VERSION ='$(git describe --tags | egrep -o '[0-9]+\.[0-9]+\.[0-9]+')'/g" config/settings/base.py
- sed -i "s/http:\/\/localhost:8000/https:\/\/collections.gfbio.org/g" config/settings/base.py
- 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 down
- docker-compose -f production.yml up -d
environment:
name: production
url: https://collections.gfbio.org
tags:
- col-svc-prod