Skip to content

Commit 4fbae1b

Browse files
authored
Add script to compare target version with latest dockerhub tag. (#797)
1 parent 11801e2 commit 4fbae1b

File tree

5 files changed

+127
-26
lines changed

5 files changed

+127
-26
lines changed

.github/workflows/CD.yml

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,6 @@ on:
2222
sha:
2323
description: 'the github sha to release'
2424
required: true
25-
update-latest:
26-
description: 'update the latest tag in the repos (default: true)'
27-
required: false
28-
default: 'true'
29-
mirror-operator:
30-
description: 'mirror the operator (default: true)'
31-
required: false
32-
default: 'true'
3325

3426
env:
3527
IMAGE_NAME: aws-otel-collector
@@ -344,22 +336,26 @@ jobs:
344336
curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
345337
unzip awscliv2.zip
346338
sudo ./aws/install --update
347-
348-
- name: Load Image
339+
- name: Compare version with Dockerhub latest
340+
id: version
349341
run: |
350-
docker load < build/packages/$IMAGE_NAME.tar
342+
TAG=`cat build/packages/VERSION`
343+
TARGET_VERSION=$TAG bash tools/workflow/docker-version-compare.sh
344+
345+
- name: Load Image
346+
run: docker load < build/packages/$IMAGE_NAME.tar
351347

352348
- name: upload to ECR
353349
run: |
354350
TAG=`cat build/packages/VERSION`
355351
aws ecr-public get-login-password --region us-east-1 | docker login --username AWS --password-stdin public.ecr.aws/aws-observability
356352
docker tag $IMAGE_NAME public.ecr.aws/$ECR_REPO:$TAG
357353
docker push public.ecr.aws/$ECR_REPO:$TAG
358-
if [ ${{ github.event.inputs.update-latest }} == 'true' ]; then
354+
if [ ${{ steps.version.outputs.any-update }} == 'true' ]; then
359355
docker tag $IMAGE_NAME public.ecr.aws/$ECR_REPO:latest
360356
docker push public.ecr.aws/$ECR_REPO:latest
361357
fi
362-
if [ ${{ github.event.inputs.mirror-operator }} == 'true' ]; then
358+
if [ ${{ steps.version.outputs.major-update }} == 'true' ] || [ ${{ steps.version.outputs.minor-update }} == 'true' ]; then
363359
cd adot/tools/release/adot-operator-images-mirror && go run ./
364360
fi
365361
@@ -376,12 +372,11 @@ jobs:
376372
REPO_NAME="$IMAGE_NAMESPACE/$IMAGE_NAME"
377373
docker tag $IMAGE_NAME $REPO_NAME:$TAG
378374
docker push $REPO_NAME:$TAG
379-
if [ ${{ github.event.inputs.update-latest }} == 'true' ]; then
375+
if [ ${{ steps.version.outputs.any-update }} == 'true' ]; then
380376
docker tag $IMAGE_NAME $REPO_NAME:latest
381377
docker push $REPO_NAME:latest
382378
fi
383379
384-
385380
release-validation-ecs:
386381
runs-on: ubuntu-latest
387382
needs: [get-testing-suites, release-image]
@@ -496,7 +491,6 @@ jobs:
496491
run: |
497492
cd testing-framework/terraform/eks && terraform destroy -auto-approve
498493
499-
500494
release-to-github:
501495
runs-on: ubuntu-latest
502496
needs: [release-image, release-to-s3]

tools/release/s3-release.sh

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#! /bin/bash
2+
13
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
24
#
35
# Licensed under the Apache License, Version 2.0 (the "License").
@@ -11,9 +13,6 @@
1113
# express or implied. See the License for the specific language governing
1214
# permissions and limitations under the License.
1315

14-
15-
#! /bin/bash
16-
1716
set -e
1817

1918
##########################################

tools/workflow/clean-artifact.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#! /bin/bash
2+
13
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
24
#
35
# Licensed under the Apache License, Version 2.0 (the "License").
@@ -11,8 +13,6 @@
1113
# express or implied. See the License for the specific language governing
1214
# permissions and limitations under the License.
1315

14-
#! /bin/bash
15-
1616
# this is the command to send the dispatch event to the nightly-clean-artifact workflow
1717
# please specify the TOKEN with the github token
1818
# example of how to use it: TOKEN=e7*******************************3d0d ./clean-artifact.sh

tools/workflow/clean-terraform-resources.sh

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,23 @@
11
#! /bin/bash
22

3+
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License").
6+
# You may not use this file except in compliance with the License.
7+
# A copy of the License is located at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# or in the "license" file accompanying this file. This file is distributed
12+
# on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
13+
# express or implied. See the License for the specific language governing
14+
# permissions and limitations under the License.
15+
316
set -ex
417

518
bucket_name="soaking-terraform-state"
619
# ensure we are using gnudate
7-
yesterday=`docker run ubuntu date -d 'yesterday' '+%Y-%m-%d'`
20+
yesterday=$(docker run ubuntu date -d 'yesterday' '+%Y-%m-%d')
821

922
terraform_destroy() {
1023
key_name=${1}
@@ -20,16 +33,16 @@ terraform_destroy() {
2033
fi
2134
echo "remove s3 key: ${key_name}"
2235
# use hard code bucket name here in case we mistakenly delete false bucket
23-
aws s3 rm s3://soaking-terraform-state/${key_name}
36+
aws s3 rm s3://soaking-terraform-state/"${key_name}"
2437
rm -rf testing-framework
2538
}
2639

2740

28-
s3_keys=$(aws s3api list-objects-v2 --bucket ${bucket_name} --query 'Contents[?LastModified < `${yesterday}`].Key')
41+
s3_keys=$(aws s3api list-objects-v2 --bucket ${bucket_name} --query "Contents[?LastModified < ${yesterday}].Key")
2942

3043

31-
echo ${s3_keys} | docker run -i stedolan/jq -c '.[]' | while read i; do
44+
echo "${s3_keys}" | docker run --rm -i stedolan/jq -c '.[]' | while read i; do
3245
key_name=${i:1:$((${#i}-2))}
33-
terraform_destroy ${key_name}
46+
terraform_destroy "${key_name}"
3447
done
3548

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
#! /bin/bash
2+
3+
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License").
6+
# You may not use this file except in compliance with the License.
7+
# A copy of the License is located at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# or in the "license" file accompanying this file. This file is distributed
12+
# on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
13+
# express or implied. See the License for the specific language governing
14+
# permissions and limitations under the License.
15+
16+
set -e
17+
18+
##########################################
19+
# This script is used in CD workflow
20+
# to check to see what type of version
21+
# release is being done
22+
#
23+
# Env vars
24+
# 1. TARGET_VERSION
25+
# 2. REPO_NAME
26+
#
27+
# Step outputs
28+
# (All booleans: true/false)
29+
# 1. any-update
30+
# 2. major-update
31+
# 3. minor-update
32+
# 4. patch-update
33+
##########################################
34+
35+
# splits the semver v{major}.{minor}.{patch}
36+
split_version() {
37+
if [[ $1 =~ ^v([0-9]+)\.([0-9]+)\.([0-9]+)$ ]]; then
38+
echo "${BASH_REMATCH[1]} ${BASH_REMATCH[2]} ${BASH_REMATCH[3]}"
39+
fi
40+
}
41+
42+
# check environment vars
43+
if [ -z "${TARGET_VERSION}" ]; then
44+
echo "Must have TARGET_VERSION set"
45+
exit 1
46+
fi
47+
48+
if [ -z "${REPO_NAME}" ]; then
49+
REPO_NAME="amazon/aws-otel-collector"
50+
fi
51+
52+
TOKEN=$(curl -s "https://auth.docker.io/token?service=registry.docker.io&scope=repository:${REPO_NAME}:pull" | docker run --rm -i stedolan/jq -c ".token" | sed 's/"//g')
53+
# retrieves all the available tags and sorts them in reverse version order
54+
TAGS=$(curl -s "https://registry.hub.docker.com/v2/${REPO_NAME}/tags/list" -H "Authorization: Bearer ${TOKEN}" | docker run --rm -i stedolan/jq -c ".tags[]" | sed 's/"//g' | sort -V -r)
55+
# get the first tag in the reversed list
56+
LATEST_VERSION=$(echo "${TAGS}" | sed -n '1p')
57+
58+
echo "Comparing ${LATEST_VERSION}(latest) / ${TARGET_VERSION}(target)"
59+
60+
LATEST_PARTS=($(split_version "${LATEST_VERSION}"))
61+
TARGET_PARTS=($(split_version "${TARGET_VERSION}"))
62+
63+
if [ -z "${LATEST_PARTS}" ] || [ -z "${TARGET_PARTS}" ]; then
64+
echo "Unable to split versions: ${LATEST_VERSION}(latest) / ${TARGET_VERSION}(target)"
65+
exit 1
66+
fi
67+
68+
LATEST_MAJOR=${LATEST_PARTS[0]}
69+
LATEST_MINOR=${LATEST_PARTS[1]}
70+
LATEST_PATCH=${LATEST_PARTS[2]}
71+
72+
TARGET_MAJOR=${TARGET_PARTS[0]}
73+
TARGET_MINOR=${TARGET_PARTS[1]}
74+
TARGET_PATCH=${TARGET_PARTS[2]}
75+
76+
MAJOR_UPDATE=false
77+
MINOR_UPDATE=false
78+
PATCH_UPDATE=false
79+
80+
if [ "${TARGET_MAJOR}" -gt "${LATEST_MAJOR}" ]; then
81+
MAJOR_UPDATE=true
82+
elif [ "${TARGET_MAJOR}" -eq "${LATEST_MAJOR}" ]; then
83+
if [ "${TARGET_MINOR}" -gt "${LATEST_MINOR}" ]; then
84+
MINOR_UPDATE=true
85+
elif [ "${TARGET_MINOR}" -eq "${LATEST_MINOR}" ] && [ "${TARGET_PATCH}" -gt "${LATEST_PATCH}" ]; then
86+
PATCH_UPDATE=true
87+
fi
88+
fi
89+
90+
[ ${MAJOR_UPDATE} == "true" ] || [ ${MINOR_UPDATE} == "true" ] || [ ${PATCH_UPDATE} == "true" ] && ANY_UPDATE=true || ANY_UPDATE=false
91+
92+
echo "::set-output name=major-update::${MAJOR_UPDATE}"
93+
echo "::set-output name=minor-update::${MINOR_UPDATE}"
94+
echo "::set-output name=patch-update::${PATCH_UPDATE}"
95+
echo "::set-output name=any-update::${ANY_UPDATE}"

0 commit comments

Comments
 (0)