-
Notifications
You must be signed in to change notification settings - Fork 67
/
.gitlab-ci.docker.yml
59 lines (56 loc) · 2.19 KB
/
.gitlab-ci.docker.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
.docker_build_template:
stage: build
image: docker:latest
# variables:
# REGPATH: $CI_REGISTRY/$CI_PROJECT_PATH
services:
- docker:dind
before_script:
- echo "project $CI_PROJECT_PATH stage $CI_JOB_STAGE"
- echo "starting new job for $CI_REGISTRY/$CI_PROJECT_PATH"
script:
- docker login -u gitlab-ci-token -p $CI_JOB_TOKEN $CI_REGISTRY
- docker pull $CI_REGISTRY/$CI_PROJECT_PATH/$ENV:$CI_COMMIT_REF_SLUG || true
- docker build --pull -t $CI_REGISTRY/$CI_PROJECT_PATH/$ENV:$CI_COMMIT_SHA -t $CI_REGISTRY/$CI_PROJECT_PATH/$ENV:$CI_COMMIT_REF_SLUG ./$ENV
- docker push $CI_REGISTRY/$CI_PROJECT_PATH/$ENV:$CI_COMMIT_SHA
- docker push $CI_REGISTRY/$CI_PROJECT_PATH/$ENV:$CI_COMMIT_REF_SLUG
rules:
- if: '$CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH || $CI_COMMIT_BRANCH == "dev"'
changes:
- '${ENV}/**/*'
.docker_push_template_latest:
stage: push
image: docker:latest
variables:
DOCKER_REGISTRY: "docker.io"
services:
- docker:dind
script:
- docker login -u gitlab-ci-token -p $CI_JOB_TOKEN $CI_REGISTRY
- docker pull $CI_REGISTRY/$CI_PROJECT_PATH/$ENV:$CI_COMMIT_REF_SLUG || true
- docker login -u $DOCKER_REGISTRY_USER -p $DOCKER_REGISTRY_TOKEN $DOCKER_REGISTRY
- docker tag $CI_REGISTRY/$CI_PROJECT_PATH/$ENV:$CI_COMMIT_REF_SLUG $DOCKER_REGISTRY/$DOCKER_REGISTRY_USER/$ENV:latest
- docker push $DOCKER_REGISTRY/$DOCKER_REGISTRY_USER/$ENV:latest
rules:
- if: '$CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH'
changes:
- '${ENV}/**/*'
when: manual
.docker_push_template_dev:
stage: push
image: docker:latest
variables:
DOCKER_REGISTRY: "docker.io"
services:
- docker:dind
script:
- docker login -u gitlab-ci-token -p $CI_JOB_TOKEN $CI_REGISTRY
- docker pull $CI_REGISTRY/$CI_PROJECT_PATH/$ENV:$CI_COMMIT_REF_SLUG || true
- docker login -u $DOCKER_REGISTRY_USER -p $DOCKER_REGISTRY_TOKEN $DOCKER_REGISTRY
- docker tag $CI_REGISTRY/$CI_PROJECT_PATH/$ENV:$CI_COMMIT_REF_SLUG $DOCKER_REGISTRY/$DOCKER_REGISTRY_USER/$ENV:$CI_COMMIT_REF_SLUG
- docker push $DOCKER_REGISTRY/$DOCKER_REGISTRY_USER/$ENV:$CI_COMMIT_REF_SLUG
rules:
- if: '$CI_COMMIT_BRANCH == "dev"'
changes:
- '${ENV}/**/*'
when: manual