-
Notifications
You must be signed in to change notification settings - Fork 18
/
.gitlab-ci.yml
103 lines (89 loc) · 3.03 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
---
variables:
GROUP_NAME: "Alan Turing Institute"
PROJECT_NAME: "autspaces"
REGISTRY: "registry.gitlab.com"
IMAGE_FULL_NAME: "${REGISTRY}/${GROUP_NAME}/${PROJECT_NAME}"
# Base scripts
# ============
.docker:
image: docker:latest
interruptible: true
cache: # We use cache to speed up `pip` installs for CI build tasks:
key:
files:
- .gitlab-ci.yml
paths:
- "$PIP_CACHE_DIR"
services:
- docker:dind
variables:
DOCKER_DRIVER: overlay2
PIP_CACHE_DIR: "$CI_PROJECT_DIR/.cache/pip"
before_script: &docker-before-script
# Making sure we are in the right directory, does nothing by default:
- pwd && echo "$CI_PROJECT_DIR" && cd "$CI_PROJECT_DIR"
# Installing global dependencies:
- apk update && apk upgrade
- apk add python3 python3-dev py3-pip py3-wheel
libffi-dev openssl-dev build-base git
- pip3 install dump-env docker-image-size-limit docker-compose
# Creating `.env` configuration file:
- dump-env -t config/.env.template -p 'SECRET_' > config/.env
# Login into Docker registry:
- echo "$CI_JOB_TOKEN" | docker login "$REGISTRY"
-u gitlab-ci-token --password-stdin
# Debug information:
- docker info && docker-compose --version && git --version
# Test scripts
# ============
test:
stage: test
extends: .docker
before_script:
- *docker-before-script
# Pulling cache:
- docker pull "${IMAGE_FULL_NAME}:dev" || true
- docker tag "${IMAGE_FULL_NAME}:dev" "${PROJECT_NAME}:dev" || true
script:
# Checking config:
- docker-compose -f docker-compose.yml
-f docker/docker-compose.prod.yml config --quiet
# The logic itself:
- docker-compose build
- docker-compose run --user=root --rm web sh ./docker/ci.sh
- disl "${PROJECT_NAME}:dev" 800MiB
# Pushing back the result for future runs:
- docker tag "${PROJECT_NAME}:dev" "${IMAGE_FULL_NAME}:dev"
- docker push "${IMAGE_FULL_NAME}:dev"
only:
- merge_requests
# Release scripts
# ===============
# Releasing image, when in `master` branch,
# can be replaced with `kira-release` bot:
# https://github.com/wemake-services/kira-release
release-image:
extends: .docker
stage: deploy
allow_failure: false
before_script:
# Build local image to be released to gitlab registry,
# modify it to suite your needs as you wish.
# We only care about the name of the image:
- *docker-before-script
# Now we need the latest images for cache and improved build times:
- docker pull "${IMAGE_FULL_NAME}:latest" || true
- docker pull "${IMAGE_FULL_NAME}:dev" || true
# Create correct tags:
- docker tag "${IMAGE_FULL_NAME}:latest" "${PROJECT_NAME}:latest" || true
- docker tag "${IMAGE_FULL_NAME}:dev" "${PROJECT_NAME}:dev" || true
# Building the image itself:
- docker-compose -f docker-compose.yml
-f docker/docker-compose.prod.yml build
script:
- docker push "${IMAGE_FULL_NAME}:latest"
only:
- master
environment:
name: production # used to track time with 'cycle analytics'