Add workflow to promote RC to release #3
Workflow file for this run
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
name: Promote RC to Release | |
concurrency: | |
group: ${{ github.workflow }}-${{ github.ref_name }} | |
cancel-in-progress: true | |
on: | |
pull_request: | |
workflow_dispatch: | |
inputs: | |
mage_version: | |
description: "Mage version (format: X.Y.Z)" | |
required: true | |
type: string | |
mage_rc_version: | |
description: "Mage RC version to promote (format: rcX)" | |
required: true | |
type: string | |
memgraph_version: | |
description: "Memgraph version (format: X.Y.Z)" | |
required: true | |
type: string | |
force_promote: | |
type: boolean | |
description: "Override existing release" | |
default: false | |
test: | |
description: "Run in test mode" | |
required: false | |
type: boolean | |
env: | |
s3_region: eu-west-1 | |
rc_bucket: deps.memgraph.io | |
rc_dir: mage/v${{ github.event.inputs.mage_version || '1.18.0' }}-${{ github.event.inputs.mage_rc_version || 'test' }} | |
docker_repo_rc: memgraph/memgraph-mage | |
docker_repo_release: memgraph/memgraph-mage-release-test | |
jobs: | |
PromoteDocker: | |
runs-on: ubuntu-latest | |
strategy: | |
fail-fast: false | |
matrix: | |
include: | |
- build_target: "prod" | |
build_scope: "with ML" | |
build_type: "Release" | |
- build_target: "prod" | |
build_scope: "with ML" | |
build_type: "RelWithDebInfo" | |
image_ext: "-relwithdebinfo" | |
- build_target: "prod" | |
build_scope: "without ML" | |
build_type: "Release" | |
image_ext: "-no-ml" | |
- build_target: "prod" | |
build_scope: "without ML" | |
build_type: "RelWithDebInfo" | |
image_ext: "-no-ml-relwithdebinfo" | |
- build_target: "dev" | |
build_scope: "with ML" | |
build_type: "RelwithDebInfo" | |
image_ext: "-dev" | |
steps: | |
- name: Setup environment variables | |
run: | | |
mage_version=${{ github.event.inputs.mage_version || '1.18.0' }} | |
memgraph_version=${{ github.event.inputs.memgraph_version || '2.18.0' }} | |
echo "docker_tar_amd=mage-${mage_version%.0}-memgraph-${memgraph_version%.0}${{ matrix.image_ext }}.tar.gz" >> $GITHUB_ENV | |
echo "docker_tar_arm=mage-${mage_version%.0}-memgraph-${memgraph_version%.0}-arm${{ matrix.image_ext }}.tar.gz" >> $GITHUB_ENV | |
echo "rc_image=${docker_repo_rc}:${mage_version%.0}-memgraph-${memgraph_version%.0}${{ matrix.image_ext }}" >> $GITHUB_ENV | |
echo "release_image=${docker_repo_release}:${mage_version%.0}-memgraph-${memgraph_version%.0}${{ matrix.image_ext }}" >> $GITHUB_ENV | |
- name: Setup AWS credentials | |
uses: aws-actions/configure-aws-credentials@v4 | |
with: | |
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} | |
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | |
aws-region: ${{ env.s3_region }} | |
- name: Check if rc image for this build exists | |
run: | | |
if ! aws s3 ls s3://${rc_bucket}/${rc_dir}/${docker_tar_amd} &> /dev/null; then | |
echo "RC package does not exist at s3://${rc_bucket}/${rc_dir}/${docker_tar_amd}" | |
exit 1 | |
elif ! aws s3 ls s3://${rc_bucket}/${rc_dir}/${docker_tar_arm} &> /dev/null; then | |
echo "RC package does not exist at s3://${rc_bucket}/${rc_dir}/${docker_tar_arm}" | |
exit 1 | |
fi | |
- name: Check if release image for this build aldready exists | |
run: | | |
if docker manifest inspect ${release_image} &> /dev/null; then | |
echo "Release image ${release_image} already exists on DockerHub" | |
if [[ "${{ github.event.inputs.force_promote }}" != "true" ]]; then | |
echo "Set force_promote to true to override existing release!" | |
exit 1 | |
fi | |
echo "Forcing promotion of existing release ..." | |
fi | |
- name: Log in to Docker Hub | |
uses: docker/login-action@v3 | |
with: | |
username: ${{ secrets.DOCKERHUB_USERNAME }} | |
password: ${{ secrets.DOCKERHUB_TOKEN }} | |
- name: Get dockerhub token | |
run: | | |
dockerhub_token=$(curl -s -H "Content-Type: application/json" -X POST -d '{"username": "${{ secrets.DOCKERHUB_USERNAME }}", "password": "${{ secrets.DOCKERHUB_TOKEN }}"}' https://hub.docker.com/v2/users/login/ | jq -r .token) | |
echo "dockerhub_token=${dockerhub_token}" >> $GITHUB_ENV | |
- name: Promote RC to Release | |
run: | | |
release_image_amd=${release_image}-amd64 | |
release_image_arm=${release_image}-arm64 | |
release_image_latest=${docker_repo_release}:latest | |
# Download and load, retag if necessary, push temporary image | |
# arm64 | |
aws s3 cp s3://${rc_bucket}/${rc_dir}/${docker_tar_arm} - | docker load | |
echo "Downloaded and loaded ${rc_image} for arm ..." | |
docker tag ${rc_image} ${relase_image_arm} | |
docker push ${release_image_arm} | |
echo "Pushed ${release_image_arm} to DockerHub!" | |
# amd64 | |
aws s3 cp s3://${rc_bucket}/${rc_dir}/${docker_tar_amd} - | docker load | |
echo "Downloaded and loaded ${rc_image} for amd ..." | |
docker tag ${rc_image} ${relase_image_amd} | |
docker push ${release_image_amd} | |
echo "Pushed ${release_image_amd} to DockerHub!" | |
# Setup manifest list for release image | |
docker manifest create ${release_image} \ | |
--amend ${relase_image_amd} \ | |
--amend ${release_image_arm} | |
docker manifest push${release_image} | |
echo "Successfully published ${release_image} to DockerHub!" | |
# Setup manifest list for latest image if production image | |
if [[ -z "${{ matrix.image_ext }}" ]]; then | |
docker manifest create ${release_image_latest} \ | |
--amend ${relase_image_amd} \ | |
--amend ${release_image_arm} | |
docker manifest push ${release_image_latest} | |
echo "Successfully published ${release_image_latest} to DockerHub!" | |
fi | |
- name: Clean up temporary images | |
run: | | |
echo "Deleting temporary image ${release_image_amd} ..." | |
curl -i -n -X DELETE -H "Authorization: JWT ${dockerhub_token}" https://hub.docker.com/v2/repositories/${docker_repo_release}/tags/${release_image#*:}-amd64/ | |
echo "Deleting temporary image ${release_image_arm} ..." | |
curl -i -n -X DELETE -H "Authorization: JWT ${dockerhub_token}" https://hub.docker.com/v2/repositories/${docker_repo_release}/tags/${release_image#*:}-arm64/ |