-
Notifications
You must be signed in to change notification settings - Fork 13
/
.gitlab-ci.yml
91 lines (82 loc) · 2.87 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
image: python:3.11-slim
variables:
NAMESPACE_PROD: captcha
APP_NAME: captcha-api
PROD_TAG: latest
OPENSHIFT_SERVER_PROD: https://api.paas.okd.cern.ch
stages:
- lint
- test
- build_docker
- deploy
.docker_build_template: &docker_definition
stage: build_docker
image:
# We recommend using the CERN version of the Kaniko image: gitlab-registry.cern.ch/ci-tools/docker-image-builder
name: gitlab-registry.cern.ch/ci-tools/docker-image-builder
entrypoint: [""]
script:
# Prepare Kaniko configuration file
- echo "{\"auths\":{\"$CI_REGISTRY\":{\"username\":\"$CI_REGISTRY_USER\",\"password\":\"$CI_REGISTRY_PASSWORD\"}}}" > /kaniko/.docker/config.json
# Build and push the image from the Dockerfile at the root of the project.
# To push to a specific docker tag, amend the --destination parameter, e.g. --destination $CI_REGISTRY_IMAGE:$CI_BUILD_REF_NAME
# See https://docs.gitlab.com/ee/ci/variables/predefined_variables.html#variables-reference for available variables
- /kaniko/executor --context $CI_PROJECT_DIR --dockerfile $CI_PROJECT_DIR/Dockerfile --destination ${TO}
.deploy_template: &deploy_definition
stage: deploy
image: gitlab-registry.cern.ch/paas-tools/openshift-client:latest
script:
# Adding || true to disable the error message when the image already exists
- oc import-image ${APP_NAME} --from="${CI_REGISTRY_IMAGE}:${TAG}" --confirm --token=${OS_TOKEN} --server=${OPENSHIFT_SERVER} -n ${NAMESPACE} || true
- oc tag "${CI_REGISTRY_IMAGE}:${TAG}" "${APP_NAME}:latest" --token=${OS_TOKEN} --server=${OPENSHIFT_SERVER} -n ${NAMESPACE}
### Linting
flake8:
image: python:3.11-slim
stage: lint
before_script:
- apt-get update && apt-get install -y -qq gcc
- pip install flake8
script:
- python -m flake8 *.py captcha_api tests
allow_failure: true
### Testing
test:
stage: test
before_script:
- export PIP_CONFIG_FILE=$(pwd)/pip.conf
- apt-get update && apt-get install -y -qq libfreetype6 fontconfig-config espeak ffmpeg libtiff5-dev libopenjp2-7-dev zlib1g-dev python3-tk gcc libfreetype6-dev
- pip install -e '.[dev]'
script:
- coverage run -m pytest
- coverage html
- coverage xml
- coverage report
artifacts:
reports:
coverage_report:
coverage_format: cobertura
path: coverage.xml
paths:
- coverage_html_report
expire_in: 1 week
### Docker build definitions
build_docker_prod:
<<: *docker_definition
variables:
TO: ${CI_REGISTRY_IMAGE}:${PROD_TAG}
only:
- master # the branch you want to publish
### Deployment definitions
deploy_prod:
<<: *deploy_definition
variables:
ENVIRONMENT: prod
OS_TOKEN: ${OPENSHIFT_DEPLOY_TOKEN}
OPENSHIFT_SERVER: ${OPENSHIFT_SERVER_PROD}
NAMESPACE: ${NAMESPACE_PROD}
TAG: ${PROD_TAG}
environment:
name: prod
url: https://captcha.web.cern.ch
only:
- master