-
Notifications
You must be signed in to change notification settings - Fork 0
/
.gitlab-ci.yml
46 lines (41 loc) · 1.57 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
image: docker:stable
services:
- docker:dind
variables:
DOCKER_DRIVER: overlay2
stages:
- test
- deploy
pytest:
stage: test
image: python:3.6-slim-stretch
services:
- redis:5-alpine
before_script:
- apt-get update
- apt-get install --no-install-recommends -q -y libsnmp-dev build-essential git
- pip install --no-cache-dir pipenv
- pipenv install --dev
script:
- export REDIS_HOST="redis"
- pipenv run pytest -x test_snmpbot.py
deploy to docker hub:
stage: deploy
when: manual
only:
variables:
- $CI_COMMIT_TAG =~ /^v[0-9]+[.][0-9]+[.][0-9]+([.][^.]+)?$/
variables:
CI_REGISTRY_IMAGE: grafolean/grafolean-snmp-bot
script:
- apk add --no-cache git
# check that we are deploying the latest version:
- export LAST_KNOWN_VERSION=`git tag -l --sort=-version:refname "v*.*.*" | head -n 1 | tr -d '[:space:]'`
- '[ "$LAST_KNOWN_VERSION" == "$CI_COMMIT_TAG" ] || (echo "Tag does not denote latest known version (which is $LAST_KNOWN_VERSION), aborting!" && exit 1)'
- echo "Deploying..."
- docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
- docker build -t "docker.io/$CI_REGISTRY_IMAGE:$CI_COMMIT_TAG" -t "docker.io/$CI_REGISTRY_IMAGE:latest" --build-arg VERSION=$CI_COMMIT_TAG --build-arg VCS_REF=$CI_COMMIT_SHA --build-arg BUILD_DATE=$(date -u +'%Y-%m-%dT%H:%M:%SZ') .
- docker push "docker.io/$CI_REGISTRY_IMAGE:$CI_COMMIT_TAG"
- docker push "docker.io/$CI_REGISTRY_IMAGE:latest"
- docker rmi $CI_REGISTRY_IMAGE:$CI_COMMIT_TAG
- docker rmi $CI_REGISTRY_IMAGE:latest