Skip to content

Commit

Permalink
add release script and roll-back to ubuntu-20.04 runners
Browse files Browse the repository at this point in the history
  • Loading branch information
CCOLLOT committed Dec 18, 2023
1 parent 7621ea0 commit 1e4744c
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ permissions:

jobs:
build-publish:
runs-on: ubuntu-latest
runs-on: ubuntu-20.04
steps:
- name: Checkout repository
uses: actions/checkout@v4
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ on:

jobs:
test:
runs-on: Ubuntu 22.04
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v4
Expand Down
70 changes: 70 additions & 0 deletions internal/scripts/helm-release.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
#!/bin/bash

# Build and release helm chart if the version does not already exists in the specified AWS ECR public repository

CHART_NAME=$1
CHART_DIRECTORY=$2
RELEASE_VERSION=$3
REPOSITORY=$4

usage() {
echo "Usage: $0 <chart_name> <chart_directory> <release_version> <AWS_ECR_public_repository>"
exit 1
}

check_parameters() {
if [ -z $CHART_NAME ];
then
echo "ERROR: Chart name must be specified"
usage
fi

if [ -z $CHART_DIRECTORY ];
then
echo "ERROR: Chart directory must be specified"
usage
fi

if [ -z $RELEASE_VERSION ];
then
echo "ERROR: Release version must be specified"
usage
fi

if [ -z $REPOSITORY ];
then
echo "ERROR: Repository must be specified"
usage
fi
}

check_version_exists() {
AWS_ERROR=$(aws ecr-public describe-images --region us-east-1 --repository-name ${CHART_NAME} --image-ids imageTag=${RELEASE_VERSION} --output json 2>&1 > /dev/null)
AWS_EXIT_CODE=$?
if [ $AWS_EXIT_CODE -eq 0 ];
then
echo "Release ${RELEASE_VERSION} already exists in AWS ECR"
exit 0
elif [ ! $AWS_EXIT_CODE -eq 254 ];
then
echo "Unexpected error while checking if ${RELEASE_VERSION} version exists: exit code ${AWS_EXIT_CODE}"
echo ${AWS_ERROR}
exit 1
fi
}

build() {
helm package ${CHART_DIRECTORY} --app-version ${RELEASE_VERSION} --version ${RELEASE_VERSION}
}

publish() {
helm push ${CHART_NAME}-${RELEASE_VERSION}.tgz oci://public.ecr.aws/${REPOSITORY}
}

check_parameters
check_version_exists

set -x

build
publish

0 comments on commit 1e4744c

Please sign in to comment.