Skip to content

Commit

Permalink
Deploy to docker hub
Browse files Browse the repository at this point in the history
  • Loading branch information
Anze committed Sep 14, 2019
1 parent 65240f7 commit 5f0f9ff
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ variables:

stages:
- test
- deploy

pytest:
stage: test
Expand All @@ -19,3 +20,24 @@ pytest:
- pipenv install --dev
script:
- pipenv run pytest -x test_snmpcollector.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-collector-snmp
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

0 comments on commit 5f0f9ff

Please sign in to comment.