Merge ~toabctl/ubuntu-docker-images/+git/utils:tag-images-dry-run into ~ubuntu-docker-images/ubuntu-docker-images/+git/utils:main

Proposed by Thomas Bechtold
Status: Merged
Merged at revision: b8b5b74c292dd4b449e05317db7df27b909acfa5
Proposed branch: ~toabctl/ubuntu-docker-images/+git/utils:tag-images-dry-run
Merge into: ~ubuntu-docker-images/ubuntu-docker-images/+git/utils:main
Diff against target: 139 lines (+48/-16)
4 files modified
README.multi-arch-tagger.md (+4/-2)
helpers/registry-login.sh (+13/-4)
lib/tag.sh (+5/-0)
tag-images.sh (+26/-10)
Reviewer Review Type Date Requested Status
Sergio Durigan Junior Approve
Review via email: mp+405685@code.launchpad.net

Commit message

Improve base image tagging and AWS login

To post a comment you must log in.
Revision history for this message
Sergio Durigan Junior (sergiodj) wrote :

Thank you for the MP, Thomas.

I'm adding a few comments that I'd like you to address, but overall it LGTM and can be merged after we iron out the nits. I also appreciate the descriptive commit messages; thanks a lot for those.

review: Needs Fixing
Revision history for this message
Thomas Bechtold (toabctl) :
Revision history for this message
Thomas Bechtold (toabctl) wrote :

all comments fixed.

Revision history for this message
Sergio Durigan Junior (sergiodj) wrote :

Thanks, LGTM.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
diff --git a/README.multi-arch-tagger.md b/README.multi-arch-tagger.md
index dd33eee..40a4d5d 100644
--- a/README.multi-arch-tagger.md
+++ b/README.multi-arch-tagger.md
@@ -52,8 +52,10 @@ To install the package:
52 $ apt install awscli52 $ apt install awscli
53```53```
5454
55To configure the software, you will need to create two profiles in55To login into AWS, you can either export `AWS_ACCESS_KEY_ID` and
56order to use the tagger.56`AWS_SECRET_ACCESS_KEY` or use a AWS profile.
57When using a profile, you can export `AWS_PROFILE` to use a specific
58profile name or configure two profiles (named like the used namespace):
5759
58```60```
59 $ aws configure --profile ubuntu61 $ aws configure --profile ubuntu
diff --git a/helpers/registry-login.sh b/helpers/registry-login.sh
index 7071451..fa2b786 100644
--- a/helpers/registry-login.sh
+++ b/helpers/registry-login.sh
@@ -87,13 +87,22 @@ _login_aws ()
87 exit 187 exit 1
88 fi88 fi
8989
90 if ! aws configure list --profile "$NAMESPACE" >& /dev/null; then90 # Use the provided access key ID & secret access key if they're available.
91 error "You must configure aws-cli with a profile named '$NAMESPACE'."91 if [ -n "$AWS_ACCESS_KEY_ID" ] && [ -n "$AWS_SECRET_ACCESS_KEY" ]; then
92 info "Using \$AWS_ACCESS_KEY_ID and \$AWS_SECRET_ACCESS_KEY"
93 return
94 fi
95
96 # use given or default profile
97 PROFILE_NAME=${AWS_PROFILE:-$NAMESPACE}
98 if ! aws configure list --profile "$PROFILE_NAME" >& /dev/null; then
99 error "You must configure aws-cli with a profile named '$PROFILE_NAME'"
92 error "Please refer to the README file for instructions."100 error "Please refer to the README file for instructions."
93 exit 1101 exit 1
102 else
103 info "Using \$AWS_PROFILE"
94 fi104 fi
95105 export AWS_PROFILE="$PROFILE_NAME"
96 export AWS_PROFILE="$NAMESPACE"
97}106}
98107
99_login_aws_registry1 ()108_login_aws_registry1 ()
diff --git a/lib/tag.sh b/lib/tag.sh
index b4b098a..da165cd 100644
--- a/lib/tag.sh
+++ b/lib/tag.sh
@@ -35,6 +35,11 @@ tag_image ()
35 error "Unable to print manifest for ${image}:${source_tag}"35 error "Unable to print manifest for ${image}:${source_tag}"
36 fi36 fi
3737
38 if [ "$DRY_RUN" -eq 1 ]; then
39 info "dry-run: not tagging the image"
40 return
41 fi
42
38 # We use "|| true" here because we want the command to complete43 # We use "|| true" here because we want the command to complete
39 # even if it fails. We check for the HTTP response code below.44 # even if it fails. We check for the HTTP response code below.
40 ret=$(curl -X PUT -H "Authorization: Bearer ${REGISTRY_AUTH_TOKEN}" \45 ret=$(curl -X PUT -H "Authorization: Bearer ${REGISTRY_AUTH_TOKEN}" \
diff --git a/tag-images.sh b/tag-images.sh
index b6fbb66..afeacc8 100755
--- a/tag-images.sh
+++ b/tag-images.sh
@@ -86,6 +86,8 @@ Arguments:
86 -d|--debug Print debug statements. This includes printing86 -d|--debug Print debug statements. This includes printing
87 the authentication token if using Dockerhub.87 the authentication token if using Dockerhub.
8888
89 --dry-run Do a dry run
90
89 -- IMAGE_1 IMAGE_2 ... IMAGE_N Images to tag. If not specified,91 -- IMAGE_1 IMAGE_2 ... IMAGE_N Images to tag. If not specified,
90 the script will obtain the list of92 the script will obtain the list of
91 all images from REGISTRY/NAMESPACE93 all images from REGISTRY/NAMESPACE
@@ -99,6 +101,7 @@ EOF
99#101#
100# We perform the tagging of '_stable', '_beta', '_candidate', 'XX.YY'102# We perform the tagging of '_stable', '_beta', '_candidate', 'XX.YY'
101# and 'RELEASE_NAME'.103# and 'RELEASE_NAME'.
104# Don't tag the current devel release because it's not stable (it's under development)
102do_tag_base_ubuntu_image ()105do_tag_base_ubuntu_image ()
103{106{
104 local image="ubuntu"107 local image="ubuntu"
@@ -106,6 +109,9 @@ do_tag_base_ubuntu_image ()
106109
107 local -a IMAGE_TAGS EDGE_TAGS110 local -a IMAGE_TAGS EDGE_TAGS
108111
112 local DISTRONAME_DEVEL
113 DISTRONAME_DEVEL=$(distro-info --devel)
114
109 readarray -t IMAGE_TAGS < <(print_tags_for_image "${image}")115 readarray -t IMAGE_TAGS < <(print_tags_for_image "${image}")
110116
111 readarray -t EDGE_TAGS < <(printf '%s\n' "${IMAGE_TAGS[@]}" \117 readarray -t EDGE_TAGS < <(printf '%s\n' "${IMAGE_TAGS[@]}" \
@@ -125,16 +131,21 @@ do_tag_base_ubuntu_image ()
125131
126 IMG_DISTRONAME=$(cut -d'-' -f1 <<< "$EDGE_TAG_PREFIX")132 IMG_DISTRONAME=$(cut -d'-' -f1 <<< "$EDGE_TAG_PREFIX")
127 IMG_RELEASEVER=$(cut -d'-' -f2 <<< "$EDGE_TAG_PREFIX")133 IMG_RELEASEVER=$(cut -d'-' -f2 <<< "$EDGE_TAG_PREFIX")
128 for tagsuffix in "${TAG_SUFFIXES[@]}"; do134
129 # Tag each suffix.135 if [ "$IMG_DISTRONAME" != "$DISTRONAME_DEVEL" ]; then
130 if [ -n "$FORCE" ] || ! grep -Fwq "${IMG_RELEASEVER}_${tagsuffix}" <<< "${IMAGE_TAGS[@]}"; then136 for tagsuffix in "${TAG_SUFFIXES[@]}"; do
131 info "Invoking multi-arch tagger for ${NAMESPACE}/${image}:${IMG_RELEASEVER}_${tagsuffix} (source tag: ${EDGE_TAG_PREFIX}_edge) (on ${REGISTRY})"137 # Tag each suffix.
132 tag_image \138 if [ -n "$FORCE" ] || ! grep -Fwq "${IMG_RELEASEVER}_${tagsuffix}" <<< "${IMAGE_TAGS[@]}"; then
133 "${image}" \139 info "Invoking multi-arch tagger for ${NAMESPACE}/${image}:${IMG_RELEASEVER}_${tagsuffix} (source tag: ${EDGE_TAG_PREFIX}_edge) (on ${REGISTRY})"
134 "${EDGE_TAG_PREFIX}_edge" \140 tag_image \
135 "${IMG_RELEASEVER}_${tagsuffix}"141 "${image}" \
136 fi142 "${EDGE_TAG_PREFIX}_edge" \
137 done143 "${IMG_RELEASEVER}_${tagsuffix}"
144 fi
145 done
146 else
147 info "Not adding stable/beta/candidate tags to current devel release $IMG_DISTRONAME"
148 fi
138149
139 # Tag the DISTRONAME.150 # Tag the DISTRONAME.
140 if [ -n "$FORCE" ] || ! grep -Fwq "${IMG_DISTRONAME}" <<< "${IMAGE_TAGS[@]}"; then151 if [ -n "$FORCE" ] || ! grep -Fwq "${IMG_DISTRONAME}" <<< "${IMAGE_TAGS[@]}"; then
@@ -310,6 +321,11 @@ while [ -n "$1" ]; do
310 shift321 shift
311 ;;322 ;;
312323
324 "--dry-run")
325 export DRY_RUN=1
326 shift
327 ;;
328
313 "-x"|"--exclude")329 "-x"|"--exclude")
314 EXCLUDE_IMAGES+=( "$2" )330 EXCLUDE_IMAGES+=( "$2" )
315 shift 2331 shift 2

Subscribers

People subscribed via source and target branches