-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.gitlab-ci.yml
95 lines (84 loc) · 3.96 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
stages:
- build
- lint
- test
- cleanup
# Use a base image that contains Docker-Compose as well as Docker
image: tmaier/docker-compose:19.03
# Make sure that the container is allowed access to use Docker to build and run new images
services:
- docker:dind
variables:
APP: "mrn"
ENV: "prd"
SECRET_KEY: "eequ8AhYakLV9fmNKbgrQi3kieShoFai0TaCjgzD"
DOMAIN: "meron.localdomain"
GIT_SUBMODULE_STRATEGY: recursive
# Create the certificates inside this directory for both the server
# and client. The certificates used by the client will be created in
# /certs/client so we only need to share this directory with the
# volume mount in `config.toml`.
DOCKER_TLS_CERTDIR: '/certs/client'
# Use a unique name for the network and and containers so that we can run multiple builds simultaneously
COMPOSE_PROJECT_NAME: ci_${APP}_${CI_PIPELINE_ID}
# Tag the images and push them to the Registry
BUILD_IMAGES: "django_api nginx"
# linting should happen in container, because CI is running under the shell executor and you would need to install
# libjpeg-dev etc. to build pillow on the shell executor. So better to just check the files inside the container.
# This means we have to run build step first though.
lint:
variables:
SERVICE: "django_api"
script:
# docker-compose.ci.yml instructs docker-compose to use the image just built in this pipeline
# it then uses the entrypoint script to install requirements/test.txt and then executes `flake8 meron_api/`
- docker-compose -f docker-compose.yml -f docker-compose.ci.yml run --entrypoint="/install_dependencies_and_run_command.sh" --rm $SERVICE test flake8 meron_api/
after_script:
- docker-compose -f docker-compose.yml -f docker-compose.ci.yml down
stage: lint
build_django_api:
variables:
SERVICE: "django_api"
script:
- docker-compose -f docker-compose.yml build --pull --force-rm $SERVICE
after_script:
- docker login -u gitlab-ci-token -p $CI_BUILD_TOKEN $CI_REGISTRY
- docker tag ci_${APP}_${CI_PIPELINE_ID}_${SERVICE}:latest ${CI_REGISTRY_IMAGE}:ci-${SERVICE}-${CI_PIPELINE_ID}
- docker push ${CI_REGISTRY_IMAGE}:ci-${SERVICE}-${CI_PIPELINE_ID}
- if [ "${CI_BUILD_TAG}" != "" ]; then docker tag ci_${APP}_${CI_PIPELINE_ID}_${SERVICE}:latest ${CI_REGISTRY_IMAGE}:${SERVICE}-${CI_BUILD_TAG}; fi
- if [ "${CI_BUILD_TAG}" != "" ]; then docker push ${CI_REGISTRY_IMAGE}:${SERVICE}-${CI_BUILD_TAG}; fi
stage: build
tags:
- docker_images
build_nginx:
variables:
SERVICE: "nginx"
script:
- docker-compose -f docker-compose.yml build --pull --force-rm $SERVICE
after_script:
- docker login -u gitlab-ci-token -p $CI_BUILD_TOKEN $CI_REGISTRY
- docker tag ci_${APP}_${CI_PIPELINE_ID}_${SERVICE}:latest ${CI_REGISTRY_IMAGE}:ci-${SERVICE}-${CI_PIPELINE_ID}
- docker push ${CI_REGISTRY_IMAGE}:ci-${SERVICE}-${CI_PIPELINE_ID}
- if [ "${CI_BUILD_TAG}" != "" ]; then docker tag ci_${APP}_${CI_PIPELINE_ID}_${SERVICE}:latest ${CI_REGISTRY_IMAGE}:${SERVICE}-${CI_BUILD_TAG}; fi
- if [ "${CI_BUILD_TAG}" != "" ]; then docker push ${CI_REGISTRY_IMAGE}:${SERVICE}-${CI_BUILD_TAG}; fi
stage: build
tags:
- docker_images
test_django_api:
variables:
SERVICE: "django_api"
DJANGO_SETTINGS_MODULE: "meron_api.settings.test"
script:
# docker-compose.ci.yml instructs docker-compose to use the image just built in this pipeline
# it then uses the entrypoint script to install requirements/test.txt and then executes `python manage.py test`
- docker-compose -f docker-compose.yml -f docker-compose.ci.yml run --entrypoint="/install_dependencies_and_run_command.sh" --rm $SERVICE test python manage.py test
after_script:
- docker-compose -f docker-compose.yml -f docker-compose.ci.yml down
stage: test
cleanup:
before_script:
- docker login -u gitlab-ci-token -p $CI_BUILD_TOKEN $CI_REGISTRY
script:
- for SERVICE in ${BUILD_IMAGES}; do docker rmi ${CI_REGISTRY_IMAGE}:ci-${SERVICE}-${CI_PIPELINE_ID}; done
stage: cleanup
when: always