-
Notifications
You must be signed in to change notification settings - Fork 67
/
.gitlab-ci.kaniko.yml
51 lines (50 loc) · 2.24 KB
/
.gitlab-ci.kaniko.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
.kaniko_build_template:
stage: build
image:
name: "gcr.io/kaniko-project/executor:v1.19.2-debug"
entrypoint: [""]
variables:
VERSION_FILE: version
before_script:
- if [ -e "$ENV/$VERSION_FILE" ];
then ARG_IMAGE_VERSION=$(grep -E -o "(.*)" ${ENV}/${VERSION_FILE} | cut -d\" -f2);
else ARG_IMAGE_VERSION="latest";
fi
- echo $ARG_IMAGE_VERSION
- echo "{\"auths\":{\"$CI_REGISTRY\":{\"username\":\"$CI_REGISTRY_USER\",\"password\":\"$CI_REGISTRY_PASSWORD\"}}}" > /kaniko/.docker/config.json
script:
- if [ "$CI_COMMIT_BRANCH" == "$CI_DEFAULT_BRANCH" ];
then /kaniko/executor --context $CI_PROJECT_DIR/$ENV --dockerfile Dockerfile --build-arg IMAGE_VERSION=$ARG_IMAGE_VERSION --destination $CI_REGISTRY_IMAGE/$ENV:$ARG_IMAGE_VERSION --destination $CI_REGISTRY_IMAGE/$ENV:latest;
else /kaniko/executor --context $CI_PROJECT_DIR/$ENV --dockerfile Dockerfile --build-arg IMAGE_VERSION=$ARG_IMAGE_VERSION --destination $CI_REGISTRY_IMAGE/$ENV:$CI_COMMIT_REF_SLUG;
fi
rules:
- if: '$CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH || $CI_COMMIT_BRANCH == "dev"'
changes:
- '${ENV}/**/*'
.crane_push_docker_template:
stage: push
image:
name: "gcr.io/go-containerregistry/crane:debug"
entrypoint: [""]
variables:
# GIT_STRATEGY: none
DOCKER_REGISTRY: "docker.io"
VERSION_FILE: version
before_script:
- if [ -e "$ENV/$VERSION_FILE" ];
then ARG_IMAGE_VERSION=$(grep -E -o "(.*)" ${ENV}/${VERSION_FILE} | cut -d\" -f2);
else ARG_IMAGE_VERSION="latest";
fi
- echo $ARG_IMAGE_VERSION
- crane auth login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
- crane auth login -u $DOCKER_REGISTRY_USER -p $DOCKER_REGISTRY_TOKEN $DOCKER_REGISTRY
script:
- if [ "$ARG_IMAGE_VERSION" == "latest" ];
then crane copy $CI_REGISTRY_IMAGE/$ENV:$ARG_IMAGE_VERSION $DOCKER_REGISTRY/$DOCKER_REGISTRY_USER/$ENV:latest;
else crane copy $CI_REGISTRY_IMAGE/$ENV:$ARG_IMAGE_VERSION $DOCKER_REGISTRY/$DOCKER_REGISTRY_USER/$ENV:$ARG_IMAGE_VERSION && crane tag $DOCKER_REGISTRY/$DOCKER_REGISTRY_USER/$ENV:$ARG_IMAGE_VERSION latest;
fi
rules:
- if: '$CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH'
changes:
- '${ENV}/**/*'
when: manual