Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
T
tango
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Jira issues
Open Jira
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
LOFAR2.0
tango
Commits
fad0c693
Commit
fad0c693
authored
3 years ago
by
Corné Lukken
Browse files
Options
Downloads
Patches
Plain Diff
L2SS-205
: Different images for tagged master and other pipelines
parent
10b3866d
No related branches found
No related tags found
1 merge request
!183
Docker image building & pushing with CI pipeline caching
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
.gitlab-ci.yml
+66
-48
66 additions, 48 deletions
.gitlab-ci.yml
sbin/tag_and_push_docker_image.sh
+48
-10
48 additions, 10 deletions
sbin/tag_and_push_docker_image.sh
with
114 additions
and
58 deletions
.gitlab-ci.yml
+
66
−
48
View file @
fad0c693
# TODO(Corne): Update this image to use our own registry once building
image
:
git.astron.nl:5000/lofar2.0/tango/tango-itango:9.3.5
# images is in place.
image
:
artefact.skao.int/ska-tango-images-tango-itango:9.3.5
variables
:
variables
:
GIT_SUBMODULE_STRATEGY
:
recursive
GIT_SUBMODULE_STRATEGY
:
recursive
PIP_CACHE_DIR
:
"
$CI_PROJECT_DIR/.cache/pip"
PIP_CACHE_DIR
:
"
$CI_PROJECT_DIR/.cache/pip"
...
@@ -13,7 +11,7 @@ stages:
...
@@ -13,7 +11,7 @@ stages:
# - linting
# - linting
# - static-analysis
# - static-analysis
# - unit-tests
# - unit-tests
#
- integration-tests
-
integration-tests
# - packaging
# - packaging
-
images
-
images
.base_docker_images
:
.base_docker_images
:
...
@@ -26,6 +24,14 @@ stages:
...
@@ -26,6 +24,14 @@ stages:
variables
:
variables
:
DOCKER_TLS_CERTDIR
:
"
/certs"
DOCKER_TLS_CERTDIR
:
"
/certs"
before_script
:
before_script
:
-
|
if [[ "$CI_COMMIT_BRANCH" == "$CI_DEFAULT_BRANCH" && -z "$CI_COMMIT_TAG" ]]; then
tag=""
echo "Running on tagged default branch '$CI_DEFAULT_BRANCH': tag = 'latest'"
else
tag=":$CI_COMMIT_REF_SLUG"
echo "Running on branch '$CI_COMMIT_BRANCH': tag = $tag"
fi
-
apk add --update make bash docker-compose
-
apk add --update make bash docker-compose
-
docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
-
docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
-
touch /root/.Xauthority
-
touch /root/.Xauthority
...
@@ -33,7 +39,7 @@ stages:
...
@@ -33,7 +39,7 @@ stages:
-
export BASH_SOURCE=$(pwd)/bootstrap/etc/lofar20rc.sh
-
export BASH_SOURCE=$(pwd)/bootstrap/etc/lofar20rc.sh
# source the lofarrc file and mask its non zero exit code
# source the lofarrc file and mask its non zero exit code
-
. bootstrap/etc/lofar20rc.sh ||
true
-
. bootstrap/etc/lofar20rc.sh ||
true
# Allow docker image script
test
to execute
# Allow docker image script to execute
-
chmod u+x $CI_PROJECT_DIR/sbin/tag_and_push_docker_image.sh
-
chmod u+x $CI_PROJECT_DIR/sbin/tag_and_push_docker_image.sh
.base_docker_store_images
:
.base_docker_store_images
:
extends
:
.base_docker_images
extends
:
.base_docker_images
...
@@ -64,8 +70,8 @@ docker_build_image_elk:
...
@@ -64,8 +70,8 @@ docker_build_image_elk:
-
docker-compose/elk-configure-host/*
-
docker-compose/elk-configure-host/*
script
:
script
:
# Do not remove 'bash' or statement will be ignored by primitive docker shell
# Do not remove 'bash' or statement will be ignored by primitive docker shell
-
bash $CI_PROJECT_DIR/sbin/tag_and_push_docker_image.sh elk
-
bash $CI_PROJECT_DIR/sbin/tag_and_push_docker_image.sh elk
$tag
-
bash $CI_PROJECT_DIR/sbin/tag_and_push_docker_image.sh elk-configure-host
-
bash $CI_PROJECT_DIR/sbin/tag_and_push_docker_image.sh elk-configure-host
$tag
docker_build_image_lofar_device_base
:
docker_build_image_lofar_device_base
:
extends
:
.base_docker_images
extends
:
.base_docker_images
only
:
only
:
...
@@ -74,7 +80,7 @@ docker_build_image_lofar_device_base:
...
@@ -74,7 +80,7 @@ docker_build_image_lofar_device_base:
-
docker-compose/lofar-device-base/*
-
docker-compose/lofar-device-base/*
script
:
script
:
# Do not remove 'bash' or statement will be ignored by primitive docker shell
# Do not remove 'bash' or statement will be ignored by primitive docker shell
-
bash $CI_PROJECT_DIR/sbin/tag_and_push_docker_image.sh lofar-device-base
-
bash $CI_PROJECT_DIR/sbin/tag_and_push_docker_image.sh lofar-device-base
$tag
docker_build_image_prometheus
:
docker_build_image_prometheus
:
extends
:
.base_docker_images
extends
:
.base_docker_images
only
:
only
:
...
@@ -83,7 +89,7 @@ docker_build_image_prometheus:
...
@@ -83,7 +89,7 @@ docker_build_image_prometheus:
-
docker-compose/prometheus/*
-
docker-compose/prometheus/*
script
:
script
:
# Do not remove 'bash' or statement will be ignored by primitive docker shell
# Do not remove 'bash' or statement will be ignored by primitive docker shell
-
bash $CI_PROJECT_DIR/sbin/tag_and_push_docker_image.sh prometheus
-
bash $CI_PROJECT_DIR/sbin/tag_and_push_docker_image.sh prometheus
$tag
#docker_build_image_docker-compose_itango:
#docker_build_image_docker-compose_itango:
# extends: .base_docker_images
# extends: .base_docker_images
# only:
# only:
...
@@ -100,7 +106,7 @@ docker_build_image_grafana:
...
@@ -100,7 +106,7 @@ docker_build_image_grafana:
-
docker-compose/grafana/*
-
docker-compose/grafana/*
script
:
script
:
# Do not remove 'bash' or statement will be ignored by primitive docker shell
# Do not remove 'bash' or statement will be ignored by primitive docker shell
-
bash $CI_PROJECT_DIR/sbin/tag_and_push_docker_image.sh grafana
-
bash $CI_PROJECT_DIR/sbin/tag_and_push_docker_image.sh grafana
$tag
docker_build_image_jupyter
:
docker_build_image_jupyter
:
extends
:
.base_docker_images
extends
:
.base_docker_images
only
:
only
:
...
@@ -109,7 +115,7 @@ docker_build_image_jupyter:
...
@@ -109,7 +115,7 @@ docker_build_image_jupyter:
-
docker-compose/jupyter/*
-
docker-compose/jupyter/*
script
:
script
:
# Do not remove 'bash' or statement will be ignored by primitive docker shell
# Do not remove 'bash' or statement will be ignored by primitive docker shell
-
bash $CI_PROJECT_DIR/sbin/tag_and_push_docker_image.sh jupyter
-
bash $CI_PROJECT_DIR/sbin/tag_and_push_docker_image.sh jupyter
$tag
#newline_at_eof:
#newline_at_eof:
# stage: linting
# stage: linting
# before_script:
# before_script:
...
@@ -149,35 +155,47 @@ docker_build_image_jupyter:
...
@@ -149,35 +155,47 @@ docker_build_image_jupyter:
# script:
# script:
# - cd tangostationcontrol
# - cd tangostationcontrol
# - tox -e py37
# - tox -e py37
#integration_test_docker:
integration_test_docker
:
# stage: integration-tests
stage
:
integration-tests
# image: docker:latest
image
:
docker:latest
# tags:
tags
:
# - privileged
-
privileged
# services:
services
:
# - name: docker:dind
-
name
:
docker:dind
# variables:
variables
:
# DOCKER_TLS_CERTDIR: "/certs"
DOCKER_TLS_CERTDIR
:
"
/certs"
# before_script:
before_script
:
# - apk add --update make bash docker-compose
-
|
# - apk add --update bind-tools
if [[ "$CI_COMMIT_BRANCH" == "$CI_DEFAULT_BRANCH" && -z "$CI_COMMIT_TAG" ]]; then
# - docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
tag=""
# script:
echo "Running on tagged default branch '$CI_DEFAULT_BRANCH': tag = 'latest'"
# - touch /root/.Xauthority
else
## Hack BASH_SOURCE into sourced files, docker its sh shell won't set this
tag=":$CI_COMMIT_REF_SLUG"
# - export BASH_SOURCE=$(pwd)/bootstrap/etc/lofar20rc.sh
echo "Running on branch '$CI_COMMIT_BRANCH': tag = $tag"
## Hack HOSTNAME env variable into host.docker.internal, set in docker-compose
fi
# - export HOSTNAME=host.docker.internal
-
apk add --update make bash docker-compose
## - export HOSTNAME=$(hostname -i)
-
apk add --update bind-tools
## - export HOSTNAME=$(cat /run/systemd/netif/leases/2 | grep ^ADDRESS= | awk -F'=' '{print $2}')
-
docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
## source the lofarrc file and mask its non zero exit code
# Allow docker image script to execute
# - . bootstrap/etc/lofar20rc.sh || true
-
chmod u+x $CI_PROJECT_DIR/sbin/tag_and_push_docker_image.sh
## TANGO_HOST must be unset our databaseds will be unreachable
# Do not remove 'bash' or statement will be ignored by primitive docker shell
# - unset TANGO_HOST
-
bash $CI_PROJECT_DIR/sbin/tag_and_push_docker_image.sh pull $tag
## Allow integration test to execute
script
:
# - chmod u+x $CI_PROJECT_DIR/sbin/run_integration_test.sh
-
touch /root/.Xauthority
## Do not remove 'bash' or statement will be ignored by primitive docker shell
# Hack BASH_SOURCE into sourced files, docker its sh shell won't set this
# - bash $CI_PROJECT_DIR/sbin/run_integration_test.sh
-
export BASH_SOURCE=$(pwd)/bootstrap/etc/lofar20rc.sh
# Hack HOSTNAME env variable into host.docker.internal, set in docker-compose
-
export HOSTNAME=host.docker.internal
# - export HOSTNAME=$(hostname -i)
# - export HOSTNAME=$(cat /run/systemd/netif/leases/2 | grep ^ADDRESS= | awk -F'=' '{print $2}')
# source the lofarrc file and mask its non zero exit code
-
. bootstrap/etc/lofar20rc.sh ||
true
# TANGO_HOST must be unset our databaseds will be unreachable
-
unset TANGO_HOST
# Allow integration test to execute
-
chmod u+x $CI_PROJECT_DIR/sbin/run_integration_test.sh
# Do not remove 'bash' or statement will be ignored by primitive docker shell
-
bash $CI_PROJECT_DIR/sbin/run_integration_test.sh
#wheel_packaging:
#wheel_packaging:
# stage: packaging
# stage: packaging
# artifacts:
# artifacts:
...
...
This diff is collapsed.
Click to expand it.
sbin/tag_and_push_docker_image.sh
+
48
−
10
View file @
fad0c693
#!/bin/bash -e
#!/bin/bash -e
# Tag and push which image version?
DOCKER_TAG
=
latest
# Change to git tag or git hash if no tag
VERSION
=
$(
date
+
"%Y-%M-%d"
)
if
[
-z
"
${
LOFAR20_DIR
+x
}
"
]
;
then
if
[
-z
"
${
LOFAR20_DIR
+x
}
"
]
;
then
echo
"LOFAR20_DIR not set, did you forget to source lofar20rc.sh?"
echo
"LOFAR20_DIR not set, did you forget to source lofar20rc.sh?"
exit
1
exit
1
...
@@ -25,6 +19,8 @@ REMOTE_IMAGES=(
...
@@ -25,6 +19,8 @@ REMOTE_IMAGES=(
# If first argument of bash script not set run first stage
# If first argument of bash script not set run first stage
if
[
-z
"
${
1
+x
}
"
]
;
then
if
[
-z
"
${
1
+x
}
"
]
;
then
echo
"Pulling and retagging remote images"
# Iterate over al the REMOTE_IMAGES and pull them from remote and push local
# Iterate over al the REMOTE_IMAGES and pull them from remote and push local
for
image
in
"
${
REMOTE_IMAGES
[@]
}
"
;
do
for
image
in
"
${
REMOTE_IMAGES
[@]
}
"
;
do
# Set, splits tuple into $1 and $2
# Set, splits tuple into $1 and $2
...
@@ -36,6 +32,8 @@ if [ -z "${1+x}" ]; then
...
@@ -36,6 +32,8 @@ if [ -z "${1+x}" ]; then
docker tag
"
${
remote_url
}
"
"
${
local_url
}
"
docker tag
"
${
remote_url
}
"
"
${
local_url
}
"
docker push
"
${
local_url
}
"
docker push
"
${
local_url
}
"
done
done
exit
0
fi
fi
# Tuple of images and queries to detect changes
# Tuple of images and queries to detect changes
...
@@ -48,17 +46,57 @@ LOCAL_IMAGES=(
...
@@ -48,17 +46,57 @@ LOCAL_IMAGES=(
# If first argument set run second stage, determine LOCAL_IMAGE to build and
# If first argument set run second stage, determine LOCAL_IMAGE to build and
# push from the argument
# push from the argument
if
[
!
-z
"
${
1
+x
}
"
]
;
then
if
[
!
-z
"
${
1
+x
}
"
]
&&
[
"
${
1
}
"
!=
"pull"
]
;
then
# The second argument must pass the tag variable must be set
if
[
-z
"
${
2
+x
}
"
]
;
then
echo
"Error, second argument must pass tag variable"
exit
1
fi
# Set the tag variable
tag
=
"
${
2
}
"
cd
"
${
LOFAR20_DIR
}
/docker-compose"
||
exit
1
cd
"
${
LOFAR20_DIR
}
/docker-compose"
||
exit
1
# Loop through images and find the specified one
for
image
in
"
${
LOCAL_IMAGES
[@]
}
"
;
do
for
image
in
"
${
LOCAL_IMAGES
[@]
}
"
;
do
if
[
"
${
1
}
"
==
"
${
image
}
"
]
;
then
if
[
"
${
1
}
"
==
"
${
image
}
"
]
;
then
echo
"Building image for
${
image
}
container"
local_url
=
"
${
LOCAL_DOCKER_REGISTRY_HOST
}
/
${
LOCAL_DOCKER_REGISTRY_USER
}
/
${
image
}
"
# If tag is not latest, than it is not a tagged master build and we can
# pull the latest image as cache.
if
[
"
${
tag
}
"
!=
"latest"
]
;
then
docker pull
"
${
local_url
}
:latest"
fi
make build
"
${
image
}
"
make build
"
${
image
}
"
local_url
=
"
${
LOCAL_DOCKER_REGISTRY_HOST
}
/
${
LOCAL_DOCKER_REGISTRY_USER
}
/
${
image
}
:latest"
docker tag
"
${
image
}
"
"
${
local_url
}
:
${
tag
}
"
docker tag
"
${
image
}
"
"
${
local_url
}
"
docker push
"
${
local_url
}
:
${
tag
}
"
docker push
"
${
local_url
}
"
fi
done
exit
0
fi
fi
# Final stage, pull images for integration cache try special tag image first
# if it fails download latest instead
if
[
-z
"
${
1
+x
}
"
]
&&
[
"
${
1
}
"
==
"pull"
]
;
then
echo
"Pulling images for integration test cache"
# The second argument must pass the tag variable must be set
if
[
-z
"
${
2
+x
}
"
]
;
then
echo
"Error, second argument must pass tag variable"
exit
1
fi
# Set the tag variable
tag
=
"
${
2
}
"
for
image
in
"
${
LOCAL_IMAGES
[@]
}
"
;
do
docker pull
"
${
local_url
}
:
${
tag
}
"
||
docker pull
"
${
local_url
}
:latest"
done
done
exit
0
fi
fi
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