forked from wrike/callisto
-
Notifications
You must be signed in to change notification settings - Fork 0
/
.gitlab-ci.yml
119 lines (104 loc) · 3.53 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:
DOCKER_HOST: "tcp://docker:2375"
# Instruct Docker not to start over TLS.
DOCKER_TLS_CERTDIR: ""
DOCKER_DRIVER: overlay2
DIND_IMAGE: docker:24.0.2-dind
workflow:
rules:
- if: $CI_COMMIT_BRANCH
before_script:
- set -u
- date
after_script:
- date
stages:
- run_checks
- publish
run_checks:
image: python:3.12.3-alpine3.19
stage: run_checks
coverage: '/^TOTAL\s+\d+\s+\d+\s+(\d+%)$/'
cache:
key: $CI_COMMIT_REF_SLUG
paths:
- .venv/
script:
- apk add --no-cache make curl gcc musl-dev libffi-dev
- make prepare
- source .venv/bin/activate
- make lint
- make test
smoke_tests:
image: $DIND_IMAGE
stage: run_checks
services:
- name: $DIND_IMAGE
# explicitly disable tls to avoid docker startup interruption
command: ["--tls=false"]
alias: docker
variables:
KUBECTL: v1.27.1
KIND: v0.19.0
tags:
- dind
script:
- set -u
- date
# build image
- VERSION=`grep '^version = "' pyproject.toml | cut -d '"' -f 2`
- CALLISTO_IMAGE=${CI_REGISTRY_IMAGE}:${VERSION}-${CI_PIPELINE_IID}
- docker build -t $CALLISTO_IMAGE --build-arg ENVIRONMENT="prod" .
- date
# Download kind and kubectl
- apk add --update-cache --upgrade curl jq make sed
- curl https://github.com/kubernetes-sigs/kind/releases/download/${KIND}/kind-linux-amd64 -sLfSo /usr/local/bin/kind && chmod +x /usr/local/bin/kind
- curl https://storage.googleapis.com/kubernetes-release/release/${KUBECTL}/bin/linux/amd64/kubectl -sLfSo /usr/local/bin/kubectl && chmod +x /usr/local/bin/kubectl
# Run kind cluster
- kind create cluster --config=tests/smoke/kind-config.yaml
- sed -i -e 's/0\.0\.0\.0/kubernetes/g' "${HOME}/.kube/config"
- cat /etc/hosts | sed -e 's/\tdocker/\tdocker kubernetes/g' > /tmp/hosts && cat /tmp/hosts > /etc/hosts
- date
# Run callisto in kind
- VERSION=`grep '^version = "' pyproject.toml | cut -d '"' -f 2`
- CALLISTO_IMAGE=${CI_REGISTRY_IMAGE}:${VERSION}-${CI_PIPELINE_IID}
- kind load docker-image $CALLISTO_IMAGE
- cat tests/smoke/callisto-kind.yaml | sed "s|{{CALLISTO_IMAGE}}|${CALLISTO_IMAGE}|g" | kubectl apply -f -
- while [[ "$(kubectl get deployments callisto -o 'jsonpath={..status.readyReplicas}')" != "1" ]]; do echo "waiting for callisto..." && sleep 10; done
- kubectl port-forward deployment/callisto 8080:80 > /dev/null &2>1 &
- sleep 5 # waiting port-forward
- kubectl get all
- date
# Run smoke tests
- apk add -U python3 python3-dev libffi-dev build-base gcc
- make prepare
- . .venv/bin/activate
- make test_smoke || (kubectl logs deployment/callisto --all-containers=true; false)
- kubectl get all
publish_image:
image: $DIND_IMAGE
stage: publish
services:
- name: $DIND_IMAGE
# explicitly disable tls to avoid docker startup interruption
command: [ "--tls=false" ]
alias: docker
needs:
- run_checks
- smoke_tests
tags:
- dind
rules:
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
when: on_success
- when: manual
variables:
ENVIRONMENT: 'prod'
script:
- docker login -u gitlab-ci-token -p $CI_JOB_TOKEN $CI_REGISTRY
- docker build -t callisto --build-arg ENVIRONMENT="$ENVIRONMENT" .
- VERSION=`grep '^version = "' pyproject.toml | cut -d '"' -f 2`
- docker tag callisto ${CI_REGISTRY_IMAGE}:${VERSION}-${CI_PIPELINE_IID}
- |
echo docker push ${CI_REGISTRY_IMAGE}:$VERSION-${CI_PIPELINE_IID}
docker push ${CI_REGISTRY_IMAGE}:$VERSION-${CI_PIPELINE_IID}