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
Commits
c873c66a
Commit
c873c66a
authored
3 years ago
by
Jon Azpiazu
Browse files
Options
Downloads
Plain Diff
Merge branch '43-force-ddeploy-options-e-g-image-retention' into 'master'
Resolve "Force `ddeploy` options (e.g. image retention)" Closes
#43
See merge request
!73
parents
3c95d5eb
d3a1ed95
No related branches found
Branches containing commit
No related tags found
1 merge request
!73
Resolve "Force `ddeploy` options (e.g. image retention)"
Pipeline
#61146
passed
3 years ago
Stage: test
Changes
2
Pipelines
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
ci-templates/industrial-ci-templates.yml
+2
-1
2 additions, 1 deletion
ci-templates/industrial-ci-templates.yml
scripts/enforce_labels.bash
+35
-0
35 additions, 0 deletions
scripts/enforce_labels.bash
with
37 additions
and
1 deletion
ci-templates/industrial-ci-templates.yml
+
2
−
1
View file @
c873c66a
...
...
@@ -22,7 +22,7 @@
DOCKER_PUSH_TAG
:
${CI_COMMIT_REF_SLUG}
DDEPLOY_YAML
:
ddeploy.yaml
before_script
:
-
apk add --update python3 git py3-pip git-lfs
-
apk add --update python3 git py3-pip git-lfs
bash curl jq
# forward the SSH authentication into the Docker executor
-
"
which
ssh-agent
||
(
apk
update
&&
apk
add
openssh-client
)"
-
eval $(ssh-agent -s)
...
...
@@ -42,6 +42,7 @@
-
ddeploy --yaml ${DDEPLOY_YAML}
# Get ID of image created by ddeploy
-
'
DOCKER_ID=$(docker
images
--format="{{.ID}}"
|
head
-1)'
-
curl -Ls https://git.code.tecnalia.com/tecnalia_robotics-public/gitlab_templates/raw/master/scripts/enforce_labels.bash | bash -s -- ${DOCKER_ID}
# Tag and push with the branch or tag name.
-
echo "Pushing to ${DOCKER_PUSH_REGISTRY}/${DOCKER_PUSH_NAME}:${DOCKER_PUSH_TAG}"
-
docker tag ${DOCKER_ID} ${DOCKER_PUSH_REGISTRY}/${DOCKER_PUSH_NAME}:${DOCKER_PUSH_TAG}
...
...
This diff is collapsed.
Click to expand it.
scripts/enforce_labels.bash
0 → 100644
+
35
−
0
View file @
c873c66a
#!/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"
exit
1
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
echo
"Error: image does not exist"
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
"
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