Skip to content

Commit 4207259

Browse files
committed
chore(ci): Add releaser
1 parent 3ae719b commit 4207259

File tree

3 files changed

+142
-0
lines changed

3 files changed

+142
-0
lines changed

.github/workflows/release.yaml

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
---
2+
name: build
3+
run-name: building and publishing new release
4+
on: # yamllint disable-line rule:truthy
5+
push:
6+
# run only against tags
7+
tags:
8+
- "*"
9+
permissions:
10+
contents: write # allows the action to create a Github release
11+
id-token: write # This is required for requesting the AWS JWT
12+
13+
jobs:
14+
build-publish:
15+
runs-on: ubuntu-latest
16+
steps:
17+
- name: Checkout repository
18+
uses: actions/checkout@v4
19+
with:
20+
fetch-depth: 0
21+
22+
- name: Configure AWS credentials
23+
uses: aws-actions/configure-aws-credentials@v4
24+
with:
25+
aws-region: us-east-1 # ECR Public can only be logged into from the us-east-1 region
26+
role-to-assume: arn:aws:iam::202662887508:role/ecr-postgresql-partition-manager
27+
role-session-name: githubActions
28+
29+
- name: Login to Amazon ECR
30+
id: login-ecr-public
31+
uses: aws-actions/amazon-ecr-login@v2
32+
with:
33+
registry-type: public
34+
35+
- run: git fetch --force --tags
36+
37+
- uses: actions/setup-go@v5
38+
with:
39+
go-version: stable
40+
41+
- name: Set up QEMU for ARM64 build
42+
uses: docker/setup-qemu-action@v3
43+
44+
- uses: goreleaser/goreleaser-action@v5
45+
with:
46+
distribution: goreleaser
47+
version: latest
48+
args: release --clean
49+
env:
50+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
51+
52+
- name: Configure AWS credentials for helm chart
53+
uses: aws-actions/configure-aws-credentials@v4
54+
with:
55+
aws-region: us-east-1 # ECR Public can only be logged into from the us-east-1 region
56+
role-to-assume: arn:aws:iam::202662887508:role/ecr-postgresql-partition-manager-chart
57+
role-session-name: githubActions
58+
59+
- name: Login to Amazon ECR for helm chart
60+
uses: aws-actions/amazon-ecr-login@v2
61+
with:
62+
registry-type: public
63+
64+
- name: Helm release
65+
run: make helm-release

Makefile

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ BUILD_DATE=$(shell date -u +'%Y-%m-%dT%H:%M:%SZ')
44
GIT_COMMIT_SHA=$(shell git rev-parse HEAD)
55
BINARY=postgresql-partition-manager
66
ARCHITECTURE=$(shell uname -m)
7+
HELM_CHART_NAME=postgresql-partition-manager-chart
8+
RELEASE_VERSION=$(shell jq .tag dist/metadata.json)
9+
AWS_ECR_PUBLIC_ORGANIZATION=qonto
710

811
all: build
912

@@ -31,6 +34,10 @@ bats-test:
3134
helm-test:
3235
helm unittest configs/helm
3336

37+
.PHONY: helm-release
38+
helm-release:
39+
./scripts/helm-release.sh $(HELM_CHART_NAME) configs/helm $(RELEASE_VERSION) $(AWS_ECR_PUBLIC_ORGANIZATION)
40+
3441
.PHONY: kubeconform-test
3542
kubeconform-test:
3643
./scripts/kubeconform-test.sh configs/helm

scripts/helm-release.sh

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
#!/bin/bash
2+
3+
# Build and release helm chart if the version does not already exists in the specified AWS ECR public repository
4+
5+
CHART_NAME=$1
6+
CHART_DIRECTORY=$2
7+
RELEASE_VERSION=$3
8+
REPOSITORY=$4
9+
10+
usage() {
11+
echo "Usage: $0 <chart_name> <chart_directory> <release_version> <AWS_ECR_public_repository>"
12+
exit 1
13+
}
14+
15+
check_parameters() {
16+
if [ -z $CHART_NAME ];
17+
then
18+
echo "ERROR: Chart name must be specified"
19+
usage
20+
fi
21+
22+
if [ -z $CHART_DIRECTORY ];
23+
then
24+
echo "ERROR: Chart directory must be specified"
25+
usage
26+
fi
27+
28+
if [ -z $RELEASE_VERSION ];
29+
then
30+
echo "ERROR: Release version must be specified"
31+
usage
32+
fi
33+
34+
if [ -z $REPOSITORY ];
35+
then
36+
echo "ERROR: Repository must be specified"
37+
usage
38+
fi
39+
}
40+
41+
check_version_exists() {
42+
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)
43+
AWS_EXIT_CODE=$?
44+
if [ $AWS_EXIT_CODE -eq 0 ];
45+
then
46+
echo "Release ${RELEASE_VERSION} already exists in AWS ECR"
47+
exit 0
48+
elif [ ! $AWS_EXIT_CODE -eq 254 ];
49+
then
50+
echo "Unexpected error while checking if ${RELEASE_VERSION} version exists: exit code ${AWS_EXIT_CODE}"
51+
echo ${AWS_ERROR}
52+
exit 1
53+
fi
54+
}
55+
56+
build() {
57+
helm package ${CHART_DIRECTORY} --app-version ${RELEASE_VERSION} --version ${RELEASE_VERSION}
58+
}
59+
60+
publish() {
61+
helm push ${CHART_NAME}-${RELEASE_VERSION}.tgz oci://public.ecr.aws/${REPOSITORY}
62+
}
63+
64+
check_parameters
65+
check_version_exists
66+
67+
set -x
68+
69+
build
70+
publish

0 commit comments

Comments
 (0)