Repository navigation
Expand file tree
/
Copy path.gitlab-ci.yml
More file actions
38 lines (32 loc) · 1.58 KB
/
Copy path.gitlab-ci.yml
File metadata and controls
38 lines (32 loc) · 1.58 KB
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
image: docker:stable
services:
- docker:dind
variables:
DOCKER_DRIVER: overlay2
stages:
- deploy
deploy_to_docker_hub:
stage: deploy
when: manual
only:
# We only want master branch AND when tag looks like 'vX.Y.Z', however GitLab doesn't support conjunctive conditions yet:
# https://gitlab.com/gitlab-org/gitlab-ce/issues/27818
# refs:
# - master # Yeah, that doesn't work... The job for a commit with a tag and on a master branch is not being created.
#
# However we can mark tags 'v*.*.*' as protected, which also allows us to (somewhat) safely use Private-Token as protected
# CI variable.
variables:
- $CI_COMMIT_TAG =~ /^v[0-9]+[.][0-9]+[.][0-9]+$/
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 "$CI_REGISTRY_IMAGE:$CI_COMMIT_TAG" -t "$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 "$CI_REGISTRY_IMAGE:$CI_COMMIT_TAG"
- docker push "$CI_REGISTRY_IMAGE:latest"
- docker rmi grafolean/grafolean-ping-bot:$CI_COMMIT_TAG
- docker rmi grafolean/grafolean-ping-bot:latest