Skip to content

Promote RC to Release #13

Promote RC to Release

Promote RC to Release #13

name: Promote RC to Release
concurrency:
group: ${{ github.workflow }}-${{ github.ref_name }}
cancel-in-progress: true
on:
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: false
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 }}-${{ github.event.inputs.mage_rc_version }}
docker_repo_rc: memgraph/memgraph-mage
docker_repo_release: memgraph/memgraph-mage${{ github.event.inputs.test == 'true' && '-release-test' || '' }}
jobs:
PromoteDocker:
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"
runs-on: ${{ matrix.build_target == 'dev' && 'ubuntu-large' || 'ubuntu-latest' }}
steps:
- name: Setup environment variables
run: |
mage_version=${{ github.event.inputs.mage_version }}
memgraph_version=${{ github.event.inputs.memgraph_version }}
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
echo "Downloading and loading ${rc_image} for arm ..."
aws s3 cp s3://${rc_bucket}/${rc_dir}/${docker_tar_arm} - | docker load
echo "Tagging ${rc_image} as ${release_image_arm} ..."
docker tag ${rc_image} ${release_image_arm}
echo "Pushing ${release_image_arm} to DockerHub!"
docker push ${release_image_arm}
# amd64
echo "Downloading and loading ${rc_image} for amd ..."
aws s3 cp s3://${rc_bucket}/${rc_dir}/${docker_tar_amd} - | docker load
echo "Tagging ${rc_image} as ${release_image_amd} ..."
docker tag ${rc_image} ${release_image_amd}
echo "Pushing ${release_image_amd} to DockerHub!"
docker push ${release_image_amd}
# Setup manifest list for release image
docker manifest create ${release_image} \
--amend ${release_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 ${release_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/