-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
83245cf
commit 496f0a9
Showing
3 changed files
with
142 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
--- | ||
name: build | ||
run-name: building and publishing new release | ||
on: # yamllint disable-line rule:truthy | ||
push: | ||
# run only against tags | ||
tags: | ||
- "*" | ||
permissions: | ||
contents: write # allows the action to create a Github release | ||
id-token: write # This is required for requesting the AWS JWT | ||
|
||
jobs: | ||
build-publish: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v4 | ||
with: | ||
fetch-depth: 0 | ||
|
||
- name: Configure AWS credentials | ||
uses: aws-actions/configure-aws-credentials@v4 | ||
with: | ||
aws-region: us-east-1 # ECR Public can only be logged into from the us-east-1 region | ||
role-to-assume: arn:aws:iam::202662887508:role/ecr-postgresql-partition-manager | ||
role-session-name: githubActions | ||
|
||
- name: Login to Amazon ECR | ||
id: login-ecr-public | ||
uses: aws-actions/amazon-ecr-login@v2 | ||
with: | ||
registry-type: public | ||
|
||
- run: git fetch --force --tags | ||
|
||
- uses: actions/setup-go@v5 | ||
with: | ||
go-version: stable | ||
|
||
- name: Set up QEMU for ARM64 build | ||
uses: docker/setup-qemu-action@v3 | ||
|
||
- uses: goreleaser/goreleaser-action@v5 | ||
with: | ||
distribution: goreleaser | ||
version: latest | ||
args: release --clean | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
- name: Configure AWS credentials for helm chart | ||
uses: aws-actions/configure-aws-credentials@v4 | ||
with: | ||
aws-region: us-east-1 # ECR Public can only be logged into from the us-east-1 region | ||
role-to-assume: arn:aws:iam::202662887508:role/ecr-postgresql-partition-manager-chart | ||
role-session-name: githubActions | ||
|
||
- name: Login to Amazon ECR for helm chart | ||
uses: aws-actions/amazon-ecr-login@v2 | ||
with: | ||
registry-type: public | ||
|
||
- name: Helm release | ||
run: make helm-release |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |