Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
tecnalia_robotics-public
templates
Commits
58a0bce5
Commit
58a0bce5
authored
Nov 23, 2021
by
Jon Azpiazu
Browse files
Add comments to script
parent
bb00a01f
Pipeline
#61126
passed with stage
in 10 seconds
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
scripts/enforce_labels.bash
View file @
58a0bce5
#!/bin/bash
#!/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
if
[
"$#"
-ne
1
]
;
then
echo
"Usage:
$0
IMAGE_NAME"
echo
"Usage:
$0
IMAGE_NAME"
...
@@ -7,6 +10,7 @@ fi
...
@@ -7,6 +10,7 @@ fi
image_name
=
"
$1
"
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"
)
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
if
!
docker inspect
--type
=
image
"
$1
"
>
/dev/null
;
then
...
@@ -14,14 +18,17 @@ if ! docker inspect --type=image "$1" > /dev/null ; then
...
@@ -14,14 +18,17 @@ if ! docker inspect --type=image "$1" > /dev/null ; then
exit
0
exit
0
fi
fi
# check if every label is defined
for
label
in
"
${
!enforced_labels[@]
}
"
;
do
for
label
in
"
${
!enforced_labels[@]
}
"
;
do
if
!
docker inspect
-f
"{{json .Config.Labels }}"
"
$image_name
"
| jq
-e
'.['
\"
"
$label
"
\"
']'
>
/dev/null
;
then
if
!
docker inspect
-f
"{{json .Config.Labels }}"
"
$image_name
"
| jq
-e
'.['
\"
"
$label
"
\"
']'
>
/dev/null
;
then
echo
"Key not found"
echo
"Key not found"
echo
"
$label
=
${
enforced_labels
[
$label
]
}
"
echo
"
$label
=
${
enforced_labels
[
$label
]
}
"
# add missing label to the arguments to be provided to `docker build`
label_args+
=
" --label
$label
=
\"
${
enforced_labels
[
$label
]
}
\"
"
label_args+
=
" --label
$label
=
\"
${
enforced_labels
[
$label
]
}
\"
"
fi
fi
done
done
# generate new image
if
[
-n
"
${
label_args
+x
}
"
]
;
then
if
[
-n
"
${
label_args
+x
}
"
]
;
then
run_command
=
"echo
\"
FROM
$image_name
\"
| docker build
$label_args
-t
$image_name
-"
run_command
=
"echo
\"
FROM
$image_name
\"
| docker build
$label_args
-t
$image_name
-"
eval
"
$run_command
"
eval
"
$run_command
"
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment