This repository has been archived by the owner on Sep 16, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
.gitlab-ci.yml
154 lines (144 loc) · 4.74 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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
# Note: all "environment:" assignments in this file
# refers to gitlab-ci environments, which are:
#
# - {{ feature_branch }}
# - master
# - release
#
# This "environment:" assignment is separate from
# Fairdata environments, which are:
#
# - staging
# - test
# - stable
# - demo
workflow:
rules:
- if: $CI_COMMIT_BRANCH =~ /^(master|release)$/
- if: $CI_PIPELINE_SOURCE == "merge_request_event" && $CI_MERGE_REQUEST_SOURCE_BRANCH_NAME !~ /^(master|release)$/
stages:
- clean_previous_build
- deploy
- test
- update
- clean_env
# Clean any previous build from [test/stable], if deploying [master/release] branch
job_clean_previous_build:
stage: clean_previous_build
rules:
- if: $CI_COMMIT_BRANCH =~ /^(master|release)$/
# Note: "environment" in this case refers to a "gitlab-ci-environment", not a "fairdata environment"
environment: $CI_COMMIT_BRANCH
script:
# repo_version must be passed in order to correctly delete previous build
- ansible-playbook -i $ANSIBLE_INVENTORY $DELETE_PLAYBOOK --vault-id $ANSIBLE_VAULT_FILE -e "repo_version=$CI_COMMIT_REF_NAME"
# Deploy master/release branch to test/stable environment
job_deploy_protected_branch:
stage: deploy
rules:
- if: $CI_COMMIT_BRANCH =~ /^(master|release)$/
# Note: "environment" in this case refers to a "gitlab-ci-environment", not a "fairdata environment"
environment: $CI_COMMIT_BRANCH
script:
- ansible-playbook -i $ANSIBLE_INVENTORY $DEPLOY_PLAYBOOK --vault-id $ANSIBLE_VAULT_FILE
# Deploy MR branch to test environment
job_deploy_feature_branch:
stage: deploy
rules:
- if: $CI_PIPELINE_SOURCE == "merge_request_event" && $CI_MERGE_REQUEST_SOURCE_BRANCH_NAME !~ /^(master|release)$/
# Note: "environment" in this case refers to a "gitlab-ci-environment", not a "fairdata environment"
environment: $CI_COMMIT_REF_NAME
script:
# repo_version must be passed in order to correctly deploy the build
- ansible-playbook -i $ANSIBLE_INVENTORY $DEPLOY_PLAYBOOK -e "repo_version=$CI_COMMIT_REF_NAME" --vault-id $ANSIBLE_VAULT_FILE
job_update:
stage: update
rules:
- if: $CI_COMMIT_BRANCH =~ /^(master|release)$/
# Note: "environment" in this case refers to a "gitlab-ci-environment", not a "fairdata environment"
environment: $CI_COMMIT_BRANCH
script:
- ansible-playbook -i $ANSIBLE_INVENTORY $UPDATE_PROXY_PLAYBOOK --vault-id $ANSIBLE_VAULT_FILE
- ansible-playbook -i $ANSIBLE_INVENTORY $MANAGE_PLAYBOOK --vault-id $ANSIBLE_VAULT_FILE
job_sonarqube_check:
tags:
- docker
stage: test
image:
name: sonarsource/sonar-scanner-cli:latest
entrypoint: [""]
variables:
SONAR_USER_HOME: "${CI_PROJECT_DIR}/.sonar" # Defines the location of the analysis task cache
GIT_DEPTH: "0" # Tells git to fetch all the branches of the project, required by the analysis task
cache:
key: "${CI_JOB_NAME}"
paths:
- .sonar/cache
script:
- sonar-scanner
allow_failure: true
needs:
- job: job_integration_test
artifacts: true
only:
- merge_requests
- master
- release
job_integration_test:
environment: $CI_COMMIT_REF_NAME
stage: test
tags:
- docker
image:
name: python:3.8
services:
- postgres:9.6
- rabbitmq:3
- redis:latest
- name: elasticsearch:7.9.2
alias: elasticsearch
command: [ "bin/elasticsearch", "-Expack.security.enabled=false", "-Ediscovery.type=single-node" ]
variables:
POSTGRES_USER: metax_user
POSTGRES_PASSWORD: password
POSTGRES_DB: metax_db
METAX_DATABASE: metax_db
METAX_DATABASE_PASSWORD: password
METAX_DATABASE_USER: metax_user
METAX_DATABASE_HOST: postgres
ELASTIC_SEARCH_HOSTS: elasticsearch
RABBIT_MQ_HOSTS: rabbitmq
REDIS_HOST: redis
REDIS_PORT: 6379
DJANGO_SECRET_KEY: django-insecure-22388&4#2_#u0e%$%!)5vo3mpys)#f7@vsk9az354!jgze--&e
DJANGO_ENV: unittests
script:
- apt-get update && apt-get install -y xqilla libxerces-c-dev build-essential libssl-dev libffi-dev python-dev libxqilla-dev
- mkdir -p /var/log/metax-api/errors
- pip install -r requirements.txt
- cd src
- python manage.py first_time_setup
- coverage run manage.py test --parallel
- coverage combine
- coverage report -m
- coverage xml
artifacts:
reports:
coverage_report:
coverage_format: cobertura
path: src/coverage.xml
paths:
- src/coverage.xml
job_clean_gitlab_env:
environment:
name: $CI_COMMIT_REF_NAME
action: stop
rules:
- if: $CI_PIPELINE_SOURCE == "merge_request_event" && $CI_MERGE_REQUEST_SOURCE_BRANCH_NAME !~ /^(master|release)$/
- if: $CI_COMMIT_BRANCH =~ /^(release)$/
when: never
stage: clean_env
variables:
GIT_STRATEGY: none
script:
- echo "Cleaning deleted branches from environments"