forked from sciapp/sampledb
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path.gitlab-ci.yml
More file actions
178 lines (168 loc) · 5.45 KB
/
.gitlab-ci.yml
File metadata and controls
178 lines (168 loc) · 5.45 KB
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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
stages:
- test
- build
- deploy
variables:
POSTGRES_HOST: postgres
POSTGRES_DB: postgres
POSTGRES_USER: postgres
POSTGRES_PASSWORD: ""
SAMPLEDB_SQLALCHEMY_DATABASE_URI: "postgresql+psycopg2://postgres:@postgres:5432/postgres"
POSTGRES_HOST_AUTH_METHOD: trust
test:
stage: test
image: ubuntu:20.04
services:
- postgres:12
tags:
- kubernetes-executor
script:
- apt-get update
# set up Python 3
- DEBIAN_FRONTEND=noninteractive apt-get install -y git python3-pip postgresql-client libpangocairo-1.0-0 gettext
- mkdir ${CI_PROJECT_DIR}/test_files/
- for i in 0 1 2 3; do
psql -h "postgres" -U "$POSTGRES_USER" -d "$POSTGRES_DB" -c "CREATE DATABASE testdb_$i;";
mkdir ${CI_PROJECT_DIR}/test_files/$i/;
done
# install dependencies
- python3 -m pip install -r requirements.txt
# build translations once instead of with each test
- python3 -m sampledb build_translations
# set up configuration values for testing
- export SAMPLEDB_FILE_STORAGE_PATH=${CI_PROJECT_DIR}/test_files/
- export SAMPLEDB_BUILD_TRANSLATIONS=
# run tests and gather coverage data
- python3 -m pytest -x -s -n=4 --cov=sampledb/ --junitxml=pytest.xml tests
artifacts:
reports:
junit: pytest.xml
analyze:
stage: test
image: ubuntu:20.04
script:
- apt-get update
# set up Python 3
- apt-get install -y git python3-pip
# install static analysis packages
- python3 -m pip install pycodestyle pyflakes
- python3 -m pycodestyle --ignore=E402,E501,W504,W601 sampledb
- python3 -m pyflakes sampledb
documentation:
stage: test
image: debian:11
services:
- postgres:latest
tags:
- kubernetes-executor
script:
- apt-get update
# set up Python 3
- apt-get install -y git python3-pip libpython3-dev chromium libpangocairo-1.0-0 gettext
# install dependencies
- python3 -m pip install -r requirements.txt
# generate documentation images using current version
- python3 docs/utils/generate_images.py
# build documentation
- python3 -m sphinx -b html -t iffSamples docs/ build_documentation/
artifacts:
paths:
- build_documentation
build:
stage: build
image: docker:stable
tags:
- privileged-executor
script:
- apk add git
- export VERSION=`git describe`
- docker build --build-arg SAMPLEDB_VERSION="$VERSION" -t $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA .
- docker login -u gitlab-ci-token -p $CI_JOB_TOKEN $CI_REGISTRY
- docker push $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA
- if echo "$CI_COMMIT_TAG" | grep -Eq '^v[0-9]+\.[0-9]+\.[0-9]+$'; then
export VERSION=`echo "$CI_COMMIT_TAG" | sed 's/^v//'`;
docker tag $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA $CI_REGISTRY_IMAGE:$VERSION;
docker push $CI_REGISTRY_IMAGE:$VERSION;
fi
pages:
stage: deploy
image: ubuntu:20.04
only:
- master
- tags
- develop
script:
- mv build_documentation public
artifacts:
paths:
- public
expire_in: 1 day
deploy-to-dev:
stage: deploy
image: ubuntu:20.04
environment: staging
only:
- develop@Scientific-IT-Systems/SampleDB
script:
- apt-get update
- apt-get install -y ssh
# set up SSH for access to deployment server
- mkdir -p --mode=700 ~/.ssh/
- echo "$DEPLOYMENT_PRIVATE_KEY" > ~/.ssh/deployment_key
- chmod 400 ~/.ssh/deployment_key
- echo "$SSH_SERVER_HOSTKEYS" > ~/.ssh/known_hosts
- chmod 400 ~/.ssh/known_hosts
# actual deployment is handled via authorized_keys command
- ssh -i ~/.ssh/deployment_key iffregistry@iffweb.iff.kfa-juelich.de "$CI_COMMIT_SHA"
deploy-to-github:
stage: deploy
image: ubuntu:20.04
variables:
GIT_STRATEGY: none
only:
- branches@Scientific-IT-Systems/SampleDB
- tags@Scientific-IT-Systems/SampleDB
script:
- apt-get update
- apt-get install -y git
- mkdir --mode=700 ~/.ssh/
- echo "$SCIAPP_SAMPLEDB_PRIVATE_KEY" > ~/.ssh/id_rsa
- echo "github.com $GITHUB_HOST_KEY" >> ~/.ssh/known_hosts
- chmod 400 ~/.ssh/*
- git clone --mirror "$CI_REPOSITORY_URL" repo
- cd repo && git push --mirror git@github.com:sciapp/sampledb.git && cd -
deploy-to-dockerhub:
stage: deploy
image: docker:stable
tags:
- privileged-executor
only:
- tags@Scientific-IT-Systems/SampleDB
- develop@Scientific-IT-Systems/SampleDB
script:
- docker login -u gitlab-ci-token -p $CI_JOB_TOKEN $CI_REGISTRY
- docker pull $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA
- cat $DOCKERHUB_PASSWORD_FILE | docker login --username $DOCKERHUB_USERNAME --password-stdin
- if [ "$CI_COMMIT_REF_NAME" = "develop" ]; then
docker tag $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA sciapp/sampledb:develop;
docker push sciapp/sampledb:develop;
fi
- if echo "$CI_COMMIT_TAG" | grep -Eq '^v[0-9]+\.[0-9]+\.[0-9]+$'; then
export VERSION=`echo "$CI_COMMIT_TAG" | sed 's/^v//'`;
docker tag $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA sciapp/sampledb:$VERSION;
docker push sciapp/sampledb:$VERSION;
docker tag sciapp/sampledb:$VERSION sciapp/sampledb:latest;
docker push sciapp/sampledb:latest;
fi
deploy-to-pypi:
stage: deploy
image: python:3
only:
- tags@Scientific-IT-Systems/SampleDB
script:
- python3 -m pip install setuptools wheel twine
- python3 setup.py sdist
- if echo "$CI_COMMIT_TAG" | grep -Eq '^v[0-9]+\.[0-9]+\.[0-9]+$'; then
export VERSION=`echo "$CI_COMMIT_TAG" | sed 's/^v//'`;
python3 -m twine upload dist/sampledb-$VERSION.tar.gz;
fi