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
1diff --git a/README.multi-arch-tagger.md b/README.multi-arch-tagger.md
2index dd33eee..40a4d5d 100644
3--- a/README.multi-arch-tagger.md
4+++ b/README.multi-arch-tagger.md
5@@ -52,8 +52,10 @@ To install the package:
6 $ apt install awscli
7 ```
8
9-To configure the software, you will need to create two profiles in
10-order to use the tagger.
11+To login into AWS, you can either export `AWS_ACCESS_KEY_ID` and
12+`AWS_SECRET_ACCESS_KEY` or use a AWS profile.
13+When using a profile, you can export `AWS_PROFILE` to use a specific
14+profile name or configure two profiles (named like the used namespace):
15
16 ```
17 $ aws configure --profile ubuntu
18diff --git a/helpers/registry-login.sh b/helpers/registry-login.sh
19index 7071451..fa2b786 100644
20--- a/helpers/registry-login.sh
21+++ b/helpers/registry-login.sh
22@@ -87,13 +87,22 @@ _login_aws ()
23 exit 1
24 fi
25
26- if ! aws configure list --profile "$NAMESPACE" >& /dev/null; then
27- error "You must configure aws-cli with a profile named '$NAMESPACE'."
28+ # Use the provided access key ID & secret access key if they're available.
29+ if [ -n "$AWS_ACCESS_KEY_ID" ] && [ -n "$AWS_SECRET_ACCESS_KEY" ]; then
30+ info "Using \$AWS_ACCESS_KEY_ID and \$AWS_SECRET_ACCESS_KEY"
31+ return
32+ fi
33+
34+ # use given or default profile
35+ PROFILE_NAME=${AWS_PROFILE:-$NAMESPACE}
36+ if ! aws configure list --profile "$PROFILE_NAME" >& /dev/null; then
37+ error "You must configure aws-cli with a profile named '$PROFILE_NAME'"
38 error "Please refer to the README file for instructions."
39 exit 1
40+ else
41+ info "Using \$AWS_PROFILE"
42 fi
43-
44- export AWS_PROFILE="$NAMESPACE"
45+ export AWS_PROFILE="$PROFILE_NAME"
46 }
47
48 _login_aws_registry1 ()
49diff --git a/lib/tag.sh b/lib/tag.sh
50index b4b098a..da165cd 100644
51--- a/lib/tag.sh
52+++ b/lib/tag.sh
53@@ -35,6 +35,11 @@ tag_image ()
54 error "Unable to print manifest for ${image}:${source_tag}"
55 fi
56
57+ if [ "$DRY_RUN" -eq 1 ]; then
58+ info "dry-run: not tagging the image"
59+ return
60+ fi
61+
62 # We use "|| true" here because we want the command to complete
63 # even if it fails. We check for the HTTP response code below.
64 ret=$(curl -X PUT -H "Authorization: Bearer ${REGISTRY_AUTH_TOKEN}" \
65diff --git a/tag-images.sh b/tag-images.sh
66index b6fbb66..afeacc8 100755
67--- a/tag-images.sh
68+++ b/tag-images.sh
69@@ -86,6 +86,8 @@ Arguments:
70 -d|--debug Print debug statements. This includes printing
71 the authentication token if using Dockerhub.
72
73+ --dry-run Do a dry run
74+
75 -- IMAGE_1 IMAGE_2 ... IMAGE_N Images to tag. If not specified,
76 the script will obtain the list of
77 all images from REGISTRY/NAMESPACE
78@@ -99,6 +101,7 @@ EOF
79 #
80 # We perform the tagging of '_stable', '_beta', '_candidate', 'XX.YY'
81 # and 'RELEASE_NAME'.
82+# Don't tag the current devel release because it's not stable (it's under development)
83 do_tag_base_ubuntu_image ()
84 {
85 local image="ubuntu"
86@@ -106,6 +109,9 @@ do_tag_base_ubuntu_image ()
87
88 local -a IMAGE_TAGS EDGE_TAGS
89
90+ local DISTRONAME_DEVEL
91+ DISTRONAME_DEVEL=$(distro-info --devel)
92+
93 readarray -t IMAGE_TAGS < <(print_tags_for_image "${image}")
94
95 readarray -t EDGE_TAGS < <(printf '%s\n' "${IMAGE_TAGS[@]}" \
96@@ -125,16 +131,21 @@ do_tag_base_ubuntu_image ()
97
98 IMG_DISTRONAME=$(cut -d'-' -f1 <<< "$EDGE_TAG_PREFIX")
99 IMG_RELEASEVER=$(cut -d'-' -f2 <<< "$EDGE_TAG_PREFIX")
100- for tagsuffix in "${TAG_SUFFIXES[@]}"; do
101- # Tag each suffix.
102- if [ -n "$FORCE" ] || ! grep -Fwq "${IMG_RELEASEVER}_${tagsuffix}" <<< "${IMAGE_TAGS[@]}"; then
103- info "Invoking multi-arch tagger for ${NAMESPACE}/${image}:${IMG_RELEASEVER}_${tagsuffix} (source tag: ${EDGE_TAG_PREFIX}_edge) (on ${REGISTRY})"
104- tag_image \
105- "${image}" \
106- "${EDGE_TAG_PREFIX}_edge" \
107- "${IMG_RELEASEVER}_${tagsuffix}"
108- fi
109- done
110+
111+ if [ "$IMG_DISTRONAME" != "$DISTRONAME_DEVEL" ]; then
112+ for tagsuffix in "${TAG_SUFFIXES[@]}"; do
113+ # Tag each suffix.
114+ if [ -n "$FORCE" ] || ! grep -Fwq "${IMG_RELEASEVER}_${tagsuffix}" <<< "${IMAGE_TAGS[@]}"; then
115+ info "Invoking multi-arch tagger for ${NAMESPACE}/${image}:${IMG_RELEASEVER}_${tagsuffix} (source tag: ${EDGE_TAG_PREFIX}_edge) (on ${REGISTRY})"
116+ tag_image \
117+ "${image}" \
118+ "${EDGE_TAG_PREFIX}_edge" \
119+ "${IMG_RELEASEVER}_${tagsuffix}"
120+ fi
121+ done
122+ else
123+ info "Not adding stable/beta/candidate tags to current devel release $IMG_DISTRONAME"
124+ fi
125
126 # Tag the DISTRONAME.
127 if [ -n "$FORCE" ] || ! grep -Fwq "${IMG_DISTRONAME}" <<< "${IMAGE_TAGS[@]}"; then
128@@ -310,6 +321,11 @@ while [ -n "$1" ]; do
129 shift
130 ;;
131
132+ "--dry-run")
133+ export DRY_RUN=1
134+ shift
135+ ;;
136+
137 "-x"|"--exclude")
138 EXCLUDE_IMAGES+=( "$2" )
139 shift 2

Subscribers

People subscribed via source and target branches