Pour tout problème contactez-nous par mail : support@froggit.fr | La FAQ :grey_question: | Rejoignez-nous sur le Chat :speech_balloon:

Skip to content
Snippets Groups Projects
Commit 7c64809e authored by Christophe Chaudier's avatar Christophe Chaudier :rocket:
Browse files

Merge branch '53-container-build-on-feature-branch' into 'master'

Resolve "(container) build on feature branch"

Closes #53

See merge request lydra/gitlab-ci-templates!37
parents 76b8b132 a1d853a6
No related branches found
No related tags found
No related merge requests found
......@@ -6,9 +6,10 @@ include:
- '/templates/activate-dind.yml'
- '/templates/stages.yml'
- '/templates/job/java/lint.yml'
- '/templates/job/container/build.yml'
- '/templates/job/container/lint.yml'
- '/templates/job/container/delivery.yml'
# Deprecated templates
- '/gci-templates/activate-dind.yml'
- '/gci-templates/stages.yml'
- '/gci-templates/job/info.yml'
- '/gci-templates/job/.base.yml'
- '/gci-templates/job/ansible/lint.yml'
......@@ -16,8 +17,6 @@ include:
- '/gci-templates/job/bash/lint.yml'
- '/gci-templates/job/bash/test.yml'
- '/gci-templates/job/yaml-lint.yml'
- '/gci-templates/job/container/lint.yml'
- '/gci-templates/job/container/delivery.yml'
- '/gci-templates/job/terraform/lint.yml'
- '/gci-templates/job/node/build.yml'
- '/gci-templates/job/node/lint.yml'
......@@ -56,8 +55,16 @@ terraform-lint:
variables:
working_directory: "test/terraform"
# --------[ Containers ]--------
container:build:
variables:
working_directory: "test/container"
container:build:my-image:
extends: container:build
variables:
IMAGE_NAME: "my-image"
container::lint:
variables:
working_directory: "test/container"
......
......@@ -252,6 +252,14 @@ node::build:
- npm ci
```
## Registre de conteneurs
Si vous utilisez le registre de conteneurs, avec le job `container:build:` pensez à purger les images temporaires, taguées `tmp`.
![](doc/img/container_cleanup_policy.png)
Source : https://docs.gitlab.com/ee/user/packages/container_registry/#delete-images-by-using-a-cleanup-policy
## Pour aller plus loin
- [La référence de `.gitlab-ci.yml`](https://docs.gitlab.com/ce/ci/yaml).
......
doc/img/container_cleanup_policy.png

13.2 KiB

# doc: https://github.com/hadolint/hadolint
container::lint:
extends: .base_tpl
image: hadolint/hadolint
image: hadolint/hadolint:2.0.0-alpine
stage: lint
variables:
files_to_lint: ""
......
diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 963966d..ca4f195 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -63,6 +63,11 @@ container:delivery:
variables:
working_directory: "test/container"

+container:delivery:my_image:
+ variables:
+ working_directory: "test/container"
+ IMAGE_NAME: "my-image"
+
# --------[ Node ]--------
node::build:
variables:
diff --git a/gci-templates/job/container/delivery.yml b/gci-templates/job/container/delivery.yml
index 687b5d1..dba60c9 100644
--- a/gci-templates/job/container/delivery.yml
+++ b/gci-templates/job/container/delivery.yml
@@ -1,4 +1,6 @@
# doc: https://docs.gitlab.com/ee/ci/docker/using_kaniko.html
+# IMAGE_NAME may contain the name of the image.
+
container:delivery:
extends: .base_tpl
image:
@@ -10,5 +12,10 @@ container:delivery:
script:
- mkdir -p /kaniko/.docker
- echo "{\"auths\":{\"${CI_REGISTRY}\":{\"username\":\"${CI_REGISTRY_USER}\",\"password\":\"${CI_REGISTRY_PASSWORD}\"}}}" > /kaniko/.docker/config.json
- - echo /kaniko/executor --context "." --destination ${CI_REGISTRY_IMAGE}:${CI_COMMIT_TAG:-latest}
- - /kaniko/executor --context "." --destination ${CI_REGISTRY_IMAGE}:${CI_COMMIT_TAG:-latest}
+ - if (( ${#IMAGE_NAME} == 0 )); then
+ container_image=${CI_REGISTRY_IMAGE}:${CI_COMMIT_TAG:-latest}
+ else
+ container_image=${CI_REGISTRY_IMAGE}/${IMAGE_NAME}:${CI_COMMIT_TAG:-latest}
+ fi
+ - echo "Build image ${container_image}"
+ - /kaniko/executor --context "." --destination ${container_image}
# doc: https://docs.gitlab.com/ee/ci/docker/using_kaniko.html
# variables:
# IMAGE_NAME: is the name of the image to build
# The image is taged tmp-latest-${CI_COMMIT_SHA}
# Activate the container registery cleanup policy if you are on GitLab
# doc : https://docs.gitlab.com/ee/user/packages/container_registry/#delete-images-by-using-a-cleanup-policy
container:build:
extends: .container:build
stage: package
# doc: https://docs.gitlab.com/ee/ci/docker/using_kaniko.html
# variables:
# IMAGE_NAME: is the name of the image to build
# The image is taged like the git tag or latest if the tag don't exist.
container:delivery:
extends: .base_tpl
image:
name: gcr.io/kaniko-project/executor:debug
entrypoint: [""]
stage: delivery
only:
- master
script:
- mkdir -p /kaniko/.docker
- echo "{\"auths\":{\"${CI_REGISTRY}\":{\"username\":\"${CI_REGISTRY_USER}\",\"password\":\"${CI_REGISTRY_PASSWORD}\"}}}" > /kaniko/.docker/config.json
- echo /kaniko/executor --context "." --destination ${CI_REGISTRY_IMAGE}:${CI_COMMIT_TAG:-latest}
- /kaniko/executor --context "." --destination ${CI_REGISTRY_IMAGE}:${CI_COMMIT_TAG:-latest}
extends: .container:build
stage: delivery
rules:
- if: $CI_COMMIT_TAG
- if: '$CI_COMMIT_BRANCH == "master"'
- if: '$CI_COMMIT_BRANCH == "main"'
# doc: https://github.com/hadolint/hadolint
container::lint:
extends: .base_tpl
image: hadolint/hadolint
image: hadolint/hadolint:2.0.0-alpine
stage: lint
variables:
files_to_lint: ""
......
stages:
- info
- build
- package
- lint
- test
- delivery
......@@ -74,6 +75,29 @@ variables:
script:
- mvn ${MAVEN_CLI_OPTS} ${MAVEN_ACTION}
# --------[ Container ]--------
.container:build:
extends: .base_tpl
image:
name: gcr.io/kaniko-project/executor:debug
entrypoint: [""]
script:
- mkdir -p /kaniko/.docker
- echo "{\"auths\":{\"${CI_REGISTRY}\":{\"username\":\"${CI_REGISTRY_USER}\",\"password\":\"${CI_REGISTRY_PASSWORD}\"}}}" > /kaniko/.docker/config.json
- |- # Image name and tags, use tmp tag on release branch
if [[ ${CI_COMMIT_BRANCH} != "master" ]] && [[ ${CI_COMMIT_BRANCH} != "main" ]]; then
IMAGE_NAME="${CI_COMMIT_BRANCH}/${IMAGE_NAME:-default}"
CI_COMMIT_TAG="tmp-${CI_COMMIT_TAG:-latest}-$(echo ${CI_COMMIT_SHA} | cut -c1-8)"
fi
if [[ -z ${IMAGE_NAME} ]]; then
container_image_name=${CI_REGISTRY_IMAGE}:${CI_COMMIT_TAG:-latest}
else
container_image_name=${CI_REGISTRY_IMAGE}/${IMAGE_NAME}:${CI_COMMIT_TAG:-latest}
fi
echo "Build image : ${container_image_name}"
- /kaniko/executor --context "." --destination ${container_image_name}
# --------[ Info ]--------
.info:
stage: info
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment