-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy path.gitlab-ci.yml
83 lines (76 loc) · 2.29 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
stages:
- test
- build
- tag
.python:
image: registry.gitlab.com/janw/python-poetry:3.7
stage: test
cache:
key: pip-${CI_JOB_NAME}
paths:
- .pytest_cache
- "$CI_PROJECT_DIR/.cache/pip"
- "$CI_PROJECT_DIR/.cache/pre-commit"
variables:
PIP_CACHE_DIR: "$CI_PROJECT_DIR/.cache/pip"
PRE_COMMIT_HOME: "$CI_PROJECT_DIR/.cache/pre-commit"
before_script:
- poetry debug
- poetry config virtualenvs.create false
- poetry install --no-interaction
pytest:
extends: .python
services:
- postgres:latest
variables:
POSTGRES_DB: tapedrive_testing
POSTGRES_USER: gitlabci
POSTGRES_PASSWORD: tapedrive
DATABASE_URL: "postgres://${POSTGRES_USER}:${POSTGRES_PASSWORD}@postgres/$POSTGRES_DB"
# Required for coverage to pick up correct branch name
GIT_BRANCH: "${CI_COMMIT_REF_NAME}"
script:
- wget -O ./cc-test-reporter https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64
- chmod +x cc-test-reporter
- ./cc-test-reporter before-build
- pytest --junitxml=pytest.xml --vcr-record=none --cov --cov-report term --cov-report xml
- ./cc-test-reporter after-build
artifacts:
reports:
junit: pytest.xml
coverage: '/^TOTAL\s+\d+\s+\d+\s+([\d\.]+\%)$/'
pre-commit:
extends: .python
image: python:3.7
before_script:
- pip install -U pre-commit
script:
- pre-commit run --all-files
.docker:
image: docker:stable
stage: build
services:
- docker:dind
variables:
DOCKER_TLS_CERTDIR: ""
DOCKER_DRIVER: overlay2
before_script:
- docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
build:
extends: .docker
script:
- docker pull $CI_REGISTRY_IMAGE:latest || true
- docker build
--cache-from $CI_REGISTRY_IMAGE:latest
--tag $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_SLUG .
- if [[ "$CI_COMMIT_REF_SLUG" == master ]]; then docker tag $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_SLUG $CI_REGISTRY_IMAGE:master-$CI_COMMIT_SHORT_SHA; fi
- docker push $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_SLUG
tag latest:
extends: .docker
stage: tag
script:
- docker pull $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_SLUG
- docker tag $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_SLUG $CI_REGISTRY_IMAGE:latest
- docker push $CI_REGISTRY_IMAGE:latest
only:
- master