-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy path.gitlab-ci.yml
94 lines (89 loc) · 4.56 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#
# Copyright 2020-present, Nuance, Inc. and its contributors.
# All rights reserved.
#
# This source code is licensed under the Apache Version 2.0 license found in
# the LICENSE.md file in the root directory of this source tree.
#
# Set the tag so all the jobs in this pipeline get assigned to the appropriate runner
default:
tags:
- some_job_tag
stages:
- create_build_image
- create_target_image_content
- create_target_image
create_build_image:
only:
# Trigger this stage when a "build-x.y.z" tag is committed to the repo
- /^build-[0-9]+\.[0-9]+\.[0-9]+/
stage: create_build_image
image:
# Use the Kaniko image
name: gcr.io/kaniko-project/executor:debug
entrypoint: ["/busybox/sh"]
script:
# Create the full build image names including the repository and the project (if defined)
- if [ -z "$ACR_PROJECT" ]; then export ACR_NAME="$ACR_REGISTRY/$JANUS_BUILD_IMAGE"; else export ACR_NAME="$ACR_REGISTRY/$ACR_PROJECT/$JANUS_BUILD_IMAGE"; fi
- if [ -z "$NCR_PROJECT" ]; then export NCR_NAME="$NCR_REGISTRY/$JANUS_BUILD_IMAGE"; else export NCR_NAME="$NCR_REGISTRY/$NCR_PROJECT/$JANUS_BUILD_IMAGE"; fi
# Create the registry credentials file that will be used by Kaniko to push the images
- echo "{\"auths\":{\"$ACR_REGISTRY\":{\"auth\":\"$ACR_AUTH\"},\"$NCR_REGISTRY\":{\"auth\":\"$NCR_AUTH\"}}}" > /kaniko/.docker/config.json
# The CI_COMMIT_TAG is set to the current tag by GitLab, IMAGE_TOOL is not set to force using "external" the images are tagged with the tag that
# has been pushed and the "latest" tag
- /kaniko/executor --build-arg CI_COMMIT_TAG=$CI_COMMIT_TAG --context . --dockerfile Dockerfile.build
--destination $ACR_NAME:$CI_COMMIT_TAG
--destination $ACR_NAME:latest
--destination $NCR_NAME:$CI_COMMIT_TAG
--destination $NCR_NAME:latest
create_target_image_content:
only:
# Trigger this stage when a "x.y.z" tag is commited to the repo
- /^([0-9]+\.[0-9]+\.[0-9]+)/
# Or if this is a development branch to create a development image
- /^dev-.*$/
stage: create_target_image_content
image:
# Use the Janus build imgae
name: some.registry.com/some_project/janus_build:some_version
entrypoint: ["/bin/bash"]
artifacts:
paths:
# Define which artifact that will be used in the next stage
- image/
expire_in: 1 hour
variables:
# Set the Janus repo and Janus version in the revision controlled script (vs in the gitlab CI/CD variables) to track the variables content
JANUS_REPO: https://github.com/meetecho/janus-gateway.git
JANUS_VERSION: master
script:
# The IMAGE_TOOL is set to "external" to ensure that the "build.sh" script does not attempt to crate the image
- export IMAGE_TOOL=external
- cd /image
- ./build.sh
# The artifacts are moved to the current project root so they are persisted by GitLab
- mv /image $CI_PROJECT_DIR
create_target_image:
only:
# Trigger this stage when a "x.y.z" tag is commited to the repo
- /^([0-9]+\.[0-9]+\.[0-9]+)/
# Or if this is a development branch to create a development image
- /^dev-.*$/
stage: create_target_image
image:
# Use the Kaniko image
name: gcr.io/kaniko-project/executor:debug
entrypoint: ["/busybox/sh"]
script:
# If this is a development branch commit, this branch does not have a commit tag, we set the empty commit tag with the development branch name
- if [ -z "$CI_COMMIT_TAG" ]; then export CI_COMMIT_TAG=$CI_COMMIT_BRANCH; fi
# Create the full target image names including the repository and the project (if defined)
- if [ -z "$ACR_PROJECT" ]; then export ACR_NAME="$ACR_REGISTRY/$JANUS_TARGET_IMAGE"; else export ACR_NAME="$ACR_REGISTRY/$ACR_PROJECT/$JANUS_TARGET_IMAGE"; fi
- if [ -z "$NCR_PROJECT" ]; then export NCR_NAME="$NCR_REGISTRY/$JANUS_TARGET_IMAGE"; else export NCR_NAME="$NCR_REGISTRY/$NCR_PROJECT/$JANUS_TARGET_IMAGE"; fi
# Create the registry credentials file that will be used by Kaniko to push the images
- echo "{\"auths\":{\"$ACR_REGISTRY\":{\"auth\":\"$ACR_AUTH\"},\"$NCR_REGISTRY\":{\"auth\":\"$NCR_AUTH\"}}}" > /kaniko/.docker/config.json
# Use the artifacts from the previous stage ("image" folder), the images are tagged with the tag that has been pushed and the "latest" tag
- /kaniko/executor --context ./image --dockerfile Dockerfile.exec
--destination $ACR_NAME:$CI_COMMIT_TAG
--destination $ACR_NAME:latest
--destination $NCR_NAME:$CI_COMMIT_TAG
--destination $NCR_NAME:latest