-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy path.gitlab-ci.yml
102 lines (86 loc) · 2.13 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
include:
- template: Dependency-Scanning.gitlab-ci.yml
- template: Container-Scanning.gitlab-ci.yml
- template: Security/SAST.gitlab-ci.yml
container_scanning:
variables:
GIT_STRATEGY: fetch
DOCKER_IMAGE: "$CI_REGISTRY_IMAGE:$CI_COMMIT_BRANCH-test"
image: docker:latest
services:
- docker:dind
stages:
- build
- test
- docker_test
- push
variables:
PIP_CACHE_DIR: "$CI_PROJECT_DIR/.cache/pip"
TEST_IMAGE: "$CI_REGISTRY_IMAGE:$CI_COMMIT_BRANCH-test"
GIT_SUBMODULE_STRATEGY: recursive
workflow:
rules:
- changes:
- .gitlab-ci.yml
- Dockerfile
- cnc/*
- src/*
- requirements.txt
cache:
paths:
- .cache/pip
- env/
- .tox/
docker-build:
stage: build
script:
- docker login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD" $CI_REGISTRY
- docker pull $TEST_IMAGE || true
- docker build --pull --cache-from $TEST_IMAGE -t "$TEST_IMAGE" .
- docker push $TEST_IMAGE
test:
image: python:3.8-slim
stage: test
variables:
CNC_TEST: 'TRUE'
before_script:
- python -V
- python3 -m venv env
- source env/bin/activate
- apt update && apt-get install -y --no-install-recommends git
- pip install --upgrade pip
- pip install --upgrade -r requirements.txt
- pip install tox flake8
script:
- tox -e py38, flake8-ph, flake8-cnc
docker_test:
variables:
GIT_STRATEGY: none
image: $TEST_IMAGE
stage: test
before_script:
- python3 -m venv env
- source env/bin/activate
- pip install tox
script:
- cd /app
- ls -al
- tox -e docker_env --workdir=$CI_PROJECT_DIR/.tox
push_dev:
stage: push
script:
- docker login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD" $CI_REGISTRY
- docker pull $TEST_IMAGE
- docker tag $TEST_IMAGE "$CI_REGISTRY_IMAGE:dev"
- docker push "$CI_REGISTRY_IMAGE:dev"
only:
- develop
push_master:
stage: push
script:
- docker login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD" $CI_REGISTRY
- docker pull $TEST_IMAGE
- docker tag $TEST_IMAGE "$CI_REGISTRY_IMAGE:latest"
- docker push "$CI_REGISTRY_IMAGE:latest"
only:
- master