Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
templates
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD 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
Show more breadcrumbs
tecnalia_robotics-public
templates
Merge requests
!73
Resolve "Force `ddeploy` options (e.g. image retention)"
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
Resolve "Force `ddeploy` options (e.g. image retention)"
43-force-ddeploy-options-e-g-image-retention
into
master
Overview
8
Commits
12
Pipelines
12
Changes
1
Merged
Jon Azpiazu
requested to merge
43-force-ddeploy-options-e-g-image-retention
into
master
3 years ago
Overview
8
Commits
12
Pipelines
12
Changes
1
Expand
Closes
#43 (closed)
Edited
3 years ago
by
Jon Azpiazu
0
0
Merge request reports
Viewing commit
58a0bce5
Prev
Next
Show latest version
1 file
+
7
−
0
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
58a0bce5
Add comments to script
· 58a0bce5
Jon Azpiazu
authored
3 years ago
scripts/enforce_labels.bash
+
7
−
0
Options
#!/bin/bash
# From a given list of labels, check which of them are already defined in the provided docker image; if any of the labels
# is not defined, a new image with the same name is generated with the label(s) added.
# Labels already defined are not modified.
if
[
"$#"
-ne
1
]
;
then
echo
"Usage:
$0
IMAGE_NAME"
@@ -7,6 +10,7 @@ fi
image_name
=
"
$1
"
# list of labels to be enforced
declare
-A
enforced_labels
=(
[
"com.jfrog.artifactory.retention.maxCount"
]=
"10"
[
"com.jfrog.artifactory.retention.maxDays"
]=
"7"
)
if
!
docker inspect
--type
=
image
"
$1
"
>
/dev/null
;
then
@@ -14,14 +18,17 @@ if ! docker inspect --type=image "$1" > /dev/null ; then
exit
0
fi
# check if every label is defined
for
label
in
"
${
!enforced_labels[@]
}
"
;
do
if
!
docker inspect
-f
"{{json .Config.Labels }}"
"
$image_name
"
| jq
-e
'.['
\"
"
$label
"
\"
']'
>
/dev/null
;
then
echo
"Key not found"
echo
"
$label
=
${
enforced_labels
[
$label
]
}
"
# add missing label to the arguments to be provided to `docker build`
label_args+
=
" --label
$label
=
\"
${
enforced_labels
[
$label
]
}
\"
"
fi
done
# generate new image
if
[
-n
"
${
label_args
+x
}
"
]
;
then
run_command
=
"echo
\"
FROM
$image_name
\"
| docker build
$label_args
-t
$image_name
-"
eval
"
$run_command
"
Loading