-
Notifications
You must be signed in to change notification settings - Fork 15
/
.gitlab-ci.yml
119 lines (106 loc) · 3.75 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
variables:
GET_SOURCES_ATTEMPTS: 3
stages:
- build
- generate_api_spec
- test
#################### BUILD STAGE ####################
build_mist_image:
stage: build
before_script:
# Configure registries.
- |
rm ~/.docker/config.json
export REGISTRIES=""
# Login to gitlab docker registry.
if [ -n "$CI_REGISTRY_IMAGE" ]; then
echo "Logging in to gitlab registry."
docker login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD" \
$CI_REGISTRY
export REGISTRIES="$REGISTRIES $CI_REGISTRY_IMAGE"
echo "Logged in to gitlab registry."
else
echo "No credentials provided for gitlab registry, skipping."
fi
# Login to other registry.
if [ -n "$EXT_REGISTRY" ] && \
[ -n "$EXT_REGISTRY_IMAGE" ] && \
[ -n "$EXT_REGISTRY_USER" ] && \
[ -n "$EXT_REGISTRY_PASSWORD" ]
then
echo "Logging in to $EXT_REGISTRY."
docker login -u "$EXT_REGISTRY_USER" -p "$EXT_REGISTRY_PASSWORD" \
"$EXT_REGISTRY"
export REGISTRIES="$REGISTRIES $EXT_REGISTRY_IMAGE"
echo "Logged in to $EXT_REGISTRY."
else
echo "No credentials provided for external registry, skipping."
fi
# Login to dockerhub.
if [ -n "$DOCKERHUB_IMAGE" ] && \
[ -n "$DOCKERHUB_USER" ] && \
[ -n "$DOCKERHUB_PASSWORD" ]
then
echo "Logging in to dockerhub."
docker login -u "$DOCKERHUB_USER" -p "$DOCKERHUB_PASSWORD"
export REGISTRIES="$REGISTRIES $DOCKERHUB_IMAGE"
echo "Logged in to dockerhub."
else
echo "No credentials provided for dockerhub, skipping."
fi
# Check if any registry configured.
if [ -z "$REGISTRIES" ]; then
echo "No registries configured, exiting."
exit 1
fi
variables:
GIT_SUBMODULE_STRATEGY: recursive
script:
- docker build --rm -t registry.ops.mist.io/mistio/mist.api:$CI_COMMIT_SHA --build-arg API_VERSION_SHA=$CI_COMMIT_SHA --build-arg API_VERSION_NAME=$CI_COMMIT_REF_NAME --build-arg CI_API_V4_URL=$CI_API_V4_URL .
- docker tag registry.ops.mist.io/mistio/mist.api:$CI_COMMIT_SHA registry.ops.mist.io/mistio/mist.api:$CI_COMMIT_REF_SLUG
- docker tag registry.ops.mist.io/mistio/mist.api:$CI_COMMIT_SHA mist/api:$CI_COMMIT_SHA
- docker tag registry.ops.mist.io/mistio/mist.api:$CI_COMMIT_SHA mist/api:$CI_COMMIT_REF_SLUG
- docker push registry.ops.mist.io/mistio/mist.api:$CI_COMMIT_SHA
- docker push registry.ops.mist.io/mistio/mist.api:$CI_COMMIT_REF_SLUG
- docker push mist/api:$CI_COMMIT_SHA
- docker push mist/api:$CI_COMMIT_REF_SLUG
tags:
- builder
dependencies: []
#################### GENERATE_API_SPEC STAGE ####################
generate_api_spec:
stage: generate_api_spec
image: registry.ops.mist.io/mistio/mist.api:$CI_COMMIT_SHA
before_script:
- cd /mist.api
script:
- python3 openapi/generate_api_spec.py
- ls -l openapi
#################### TEST STAGE ####################
flake8:
stage: test
image: registry.ops.mist.io/mistio/mist.api:$CI_COMMIT_SHA
variables:
GIT_STRATEGY: none
before_script:
- cd /mist.api
script:
- flake8 --ignore=E402,E722,F632,F841,W504,W605 --exclude=v2,paramiko,lc
uniq:
stage: test
image: registry.ops.mist.io/mistio/mist.api:$CI_COMMIT_SHA
variables:
GIT_STRATEGY: none
before_script:
- cd /mist.api
script:
- ls migrations/ | uniq -c -d -w 4 | grep . && exit 1 || exit 0
unit_tests:
stage: test
image: registry.ops.mist.io/mistio/mist.api:$CI_COMMIT_SHA
variables:
GIT_STRATEGY: none
before_script:
- cd /mist.api
script:
- python -m unittest discover tests/unit_tests/ -v