Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
U
ubuntu_20_04
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
HZB
EPICS
base
ubuntu_20_04
Commits
cee48555
Commit
cee48555
authored
1 year ago
by
(INACTIVE) Marcel Bajdel (new marcel.bajdel)
Browse files
Options
Downloads
Patches
Plain Diff
New build
parent
2ceb9c19
No related branches found
Branches containing commit
No related tags found
Tags containing commit
3 merge requests
!20
Release
,
!13
Docker image branch
,
!12
Docker image branch
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
.gitlab-ci.yml
+29
-13
29 additions, 13 deletions
.gitlab-ci.yml
with
29 additions
and
13 deletions
.gitlab-ci.yml
+
29
−
13
View file @
cee48555
stages
:
# List of stages for jobs, and their order of execution
-
check_image
# Check whether the image is already existing or not
-
check_image
_branch
# Check whether the image is already existing or not
for the branch
-
initial_build
# builds if the image does not exist
-
build_main
# builds when the merge request is made into main
-
check_image_tag
# Check whether the image is already existing or not for the tag
-
build_tag
# builds when the tag is pushed
-
test_main
# tests when the merge request is made into main
-
test_latest
# tests when the image with tag latest is pushed
-
test_tag
# tests when the tag is pushed
check_image
:
stage
:
check_image
check_image
_branch
:
# Check whether the image is already existing or not
stage
:
check_image
_branch
image
:
name
:
gcr.io/go-containerregistry/crane:debug
entrypoint
:
[
"
"
]
...
...
@@ -20,8 +21,8 @@ check_image:
paths
:
-
docker_latest_image.txt
initial_build
:
stage
:
initial_build
build_branch
:
stage
:
build_branch
image
:
name
:
gcr.io/kaniko-project/executor:debug
entrypoint
:
[
"
"
]
...
...
@@ -30,14 +31,17 @@ initial_build:
-
echo "{\"auths\":{\"$CI_REGISTRY\":{\"username\":\"$CI_REGISTRY_USER\",\"password\":\"$CI_REGISTRY_PASSWORD\"}}}" > /kaniko/.docker/config.json
# Read the value of DOCKER_LATEST_IMAGE_EXISTS from the artifact
-
export DOCKER_LATEST_IMAGE_EXISTS=$(cat docker_latest_image.txt)
# if the image does not exist, build it
-
if [ "$DOCKER_LATEST_IMAGE_EXISTS" == "false" ]; then /kaniko/executor --context $CI_PROJECT_DIR --dockerfile $CI_PROJECT_DIR/Dockerfile --destination $CI_REGISTRY_IMAGE:$CI_COMMIT_BRANCH; else echo "Docker image already exists"; fi
rules
:
# if the image is pushed into main branch, the build_main job will run
-
if
:
$CI_COMMIT_BRANCH
# Check for changes (excluding README.md)
-
CHANGED_FILES=$(git diff --name-only $CI_COMMIT_BEFORE_SHA $CI_COMMIT_SHA | grep -v README.md)
# if the image does not exist and there are changes (excluding README.md), build it
-
if [ "$DOCKER_LATEST_IMAGE_EXISTS" == "false" ] && [ -n "$CHANGED_FILES" ]; then /kaniko/executor --context $CI_PROJECT_DIR --dockerfile $CI_PROJECT_DIR/Dockerfile --destination $CI_REGISTRY_IMAGE:$CI_COMMIT_BRANCH; else echo "Docker image already exists or no relevant changes"; fi
# Run tests (assuming you have a command for running tests)
-
./run_tests.sh
# Replace this with your actual test command
rules
:
-
if
:
'
$CI_COMMIT_BRANCH
&&
$CI_MERGE_REQUEST_TARGET_BRANCH_NAME
!=
"main"'
changes
:
-
"
**/*"
-
if
:
'
$CI_MERGE_REQUEST_TARGET_BRANCH_NAME
==
"main"'
when
:
never
build_main
:
# This build will run only for main branch
stage
:
build_main
...
...
@@ -52,6 +56,18 @@ build_main: # This build will run only for main branch
rules
:
-
if
:
'
$CI_MERGE_REQUEST_TARGET_BRANCH_NAME
==
"main"'
check_image_tag
:
# Check whether the image is already existing or not for the tag
stage
:
check_image_tag
image
:
name
:
gcr.io/go-containerregistry/crane:debug
entrypoint
:
[
"
"
]
script
:
-
crane auth login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
-
if crane manifest $CI_REGISTRY_IMAGE:$CI_COMMIT_BRANCH; then echo "true" > docker_latest_image.txt; else echo "false" > docker_latest_image.txt; fi
artifacts
:
paths
:
-
docker_latest_image.txt
build_tag
:
# This build will run only for tags
stage
:
build_tag
image
:
...
...
@@ -65,7 +81,7 @@ build_tag: # This build will run only for tags
# check if dockers images exists
-
if crane manifest $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_NAME; then export DOCKER_TAG_IMAGE_EXISTS=true; else export DOCKER_TAG_IMAGE_EXISTS=false; fi
# if the image does not exist, build it with the added tag
-
if $DOCKER_
TAG
_IMAGE_EXISTS
=
false; then /kaniko/executor --context $CI_PROJECT_DIR --dockerfile $CI_PROJECT_DIR/Dockerfile --destination $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_NAME; else echo "Docker image already exists"; fi
-
if
[ "
$DOCKER_
LATEST
_IMAGE_EXISTS
" == "
false
" ]
; then /kaniko/executor --context $CI_PROJECT_DIR --dockerfile $CI_PROJECT_DIR/Dockerfile --destination $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_NAME; else echo "Docker image already exists"; fi
test_main
:
stage
:
test_main
...
...
@@ -90,7 +106,7 @@ test_latest: # This test will run only for tag latest
entrypoint
:
[
"
"
]
script
:
# specify auths for crane executor
-
if DOCKER_
TAG
_IMAGE_EXISTS
=true
; then echo "Docker image already exists"; else crane auth login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY; fi
-
if
[ "$
DOCKER_
LATEST
_IMAGE_EXISTS
" == "false" ]
; then echo "Docker image already exists"; else crane auth login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY; fi
# validate the image with tag latest
-
if ! crane validate --remote $CI_REGISTRY_IMAGE:$CI_COMMIT_BRANCH; then exit 1; fi > test_latest.log
artifacts
:
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment