forked from sameersbn/docker-gitlab
-
Notifications
You must be signed in to change notification settings - Fork 0
/
.gitlab-ci.yml
59 lines (54 loc) · 1.74 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
image: docker:18-git
stages:
- build
before_script:
- export VERSION=$(cat VERSION)
- export CI_REGISTRY=${CI_REGISTRY:-hub.docker.com}
- export CI_REGISTRY_USER=${CI_REGISTRY_USER:-gitlab-ci-token}
- export CI_REGISTRY_PASSWORD=${CI_REGISTRY_PASSWORD:-${CI_JOB_TOKEN}}
- export DOCKER_IMAGE=${DOCKER_IMAGE:-${CI_REGISTRY}/${CI_PROJECT_PATH}}
- |
if [ "${DOCKER_IMAGE}" = "/" ]; then
export DOCKER_IMAGE=sameersbn/gitlab
fi
docker:build:
stage: build
only:
- master
script:
- docker login -u ${CI_REGISTRY_USER} -p ${CI_REGISTRY_PASSWORD} ${CI_REGISTRY}
- docker build
--pull
--cache-from=${DOCKER_IMAGE}
--build-arg=VCS_REF=$(git rev-parse --short HEAD)
--build-arg=BUILD_DATE="$(date +"%Y-%m-%d %H:%M:%S%:z")"
--tag ${DOCKER_IMAGE} .
- docker push ${DOCKER_IMAGE}
docker:build:branches:
stage: build
only:
- branches
except:
- master
script:
- docker login -u ${CI_REGISTRY_USER} -p ${CI_REGISTRY_PASSWORD} ${CI_REGISTRY}
- docker build
--pull
--cache-from=${DOCKER_IMAGE}:${CI_COMMIT_REF_SLUG}
--build-arg=VCS_REF=$(git rev-parse --short HEAD)
--build-arg=BUILD_DATE="$(date +"%Y-%m-%d %H:%M:%S%:z")"
--tag ${DOCKER_IMAGE}:${CI_COMMIT_REF_SLUG} .
- docker push ${DOCKER_IMAGE}:${CI_COMMIT_REF_SLUG}
docker:build:release:
stage: build
only:
- tags
script:
- docker login -u ${CI_REGISTRY_USER} -p ${CI_REGISTRY_PASSWORD} ${CI_REGISTRY}
- docker build
--pull
--cache-from=${DOCKER_IMAGE}:${VERSION}
--build-arg=VCS_REF=$(git rev-parse --short HEAD)
--build-arg=BUILD_DATE="$(date +"%Y-%m-%d %H:%M:%S%:z")"
--tag ${DOCKER_IMAGE}:${VERSION} .
- docker push ${DOCKER_IMAGE}:${VERSION}