Promote Image #410
This file contains hidden or 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 Image | |
on: | |
workflow_run: | |
workflows: ["Test"] | |
types: [completed] | |
jobs: | |
# Check-test-status: Uses the hook called test-status on the test.yml job in order to | |
# see if any test failed or was skipped; promotion should only run when all tests suceeded! | |
check-test-status: | |
runs-on: ubuntu-latest | |
outputs: | |
test-status: ${{ steps.set-status.outputs.status }} | |
steps: | |
- name: Ensure test-status job completed | |
id: set-status | |
env: | |
REPO: ${{ github.repository }} | |
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
RUN_ID: ${{ github.event.workflow_run.id }} | |
run: | | |
jobs=$(gh api --paginate /repos/$REPO/actions/runs/$RUN_ID/jobs --jq '.jobs[] | select(.name == "Final Test Status")') | |
if [[ -z "$jobs" ]]; then | |
echo "test-status job not found" | |
exit 1 | |
fi | |
conclusion=$(echo "$jobs" | jq -r '.conclusion') | |
echo "status=$conclusion" >> "$GITHUB_OUTPUT" | |
# Promote image: this will be responbile for taking a tested image from an unofficial registry like | |
# ghcr.io and promote it by adding it to an official registry (docker.io and quay.io) | |
promote-image: | |
runs-on: ubuntu-latest | |
environment: release | |
needs: check-test-status | |
if: | | |
needs.check-test-status.outputs.test-status == 'success' | |
env: | |
GHCR_REPO: ghcr.io/mongodb/mongodb-atlas-kubernetes-operator-prerelease | |
DOCKER_REPO: docker.io/mongodb/mongodb-atlas-kubernetes-operator-prerelease | |
QUAY_REPO: quay.io/mongodb/mongodb-atlas-kubernetes-operator-prerelease | |
steps: | |
- name: Checkout PR commit | |
uses: actions/checkout@v4 | |
# Login in all the needed registries | |
- name: Log in to the GitHub Container Registry | |
uses: docker/login-action@v3 | |
with: | |
registry: ghcr.io | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Login to Docker registry | |
uses: docker/login-action@v3 | |
with: | |
registry: docker.io | |
username: ${{ secrets.DOCKER_USERNAME }} | |
password: ${{ secrets.DOCKER_PASSWORD }} | |
- name: Log in to Quay registry | |
uses: docker/login-action@v3 | |
with: | |
registry: quay.io | |
username: ${{ secrets.QUAY_USERNAME }} | |
password: ${{ secrets.QUAY_PASSWORD }} | |
# Prepare tags | |
- name: Prepare image tag | |
id: set_tag | |
uses: ./.github/actions/set-tag | |
with: | |
branch_name: ${{ github.event.workflow_run.head_branch }} | |
commit_sha: ${{ github.event.workflow_run.head_sha }} | |
- name: Prepare tag for promoted image | |
id: promoted_tag | |
run: | | |
RAW_TAG="${{ steps.set_tag.outputs.tag }}" | |
COMMIT_SHA="${RAW_TAG##*-}" | |
echo "tag=promoted-${COMMIT_SHA}" >> $GITHUB_OUTPUT | |
# Promote image to official prerelease registries | |
- name: Move image to Docker Hub | |
run: ./scripts/move-image.sh | |
env: | |
IMAGE_SRC_REPO: ${{ env.GHCR_REPO }} | |
IMAGE_DEST_REPO: ${{ env.DOCKER_REPO }} | |
IMAGE_SRC_TAG: ${{ steps.set_tag.outputs.tag }} | |
IMAGE_DEST_TAG: ${{ steps.promoted_tag.outputs.tag }} | |
ALIAS_ENABLED: ${{ github.event.workflow_run.head_branch == 'main' }} | |
ALIAS_TAG: promoted-latest | |
- name: Move image to Quay | |
run: ./scripts/move-image.sh | |
env: | |
IMAGE_SRC_REPO: ${{ env.GHCR_REPO }} | |
IMAGE_DEST_REPO: ${{ env.QUAY_REPO }} | |
IMAGE_SRC_TAG: ${{ steps.set_tag.outputs.tag }} | |
IMAGE_DEST_TAG: ${{ steps.promoted_tag.outputs.tag }} | |
ALIAS_ENABLED: ${{ github.event.workflow_run.head_branch == 'main' }} | |
ALIAS_TAG: promoted-latest |