Skip to content

Commit a75d3e5

Browse files
committed
feat: create release pipeline
1 parent 645a0dc commit a75d3e5

File tree

9 files changed

+381
-39
lines changed

9 files changed

+381
-39
lines changed

.github/actions/build-push-image/action.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,3 +99,5 @@ runs:
9999
sbom: true
100100
push: true
101101
tags: ${{ inputs.tags }}
102+
labels: |
103+
org.opencontainers.image.revision=${{ github.sha }}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
name: image2commit
2+
description: Resolve full commit SHA from a promoted image tag.
3+
4+
inputs:
5+
register:
6+
description: "Registry (e.g., docker.io, quay.io)"
7+
required: true
8+
repo:
9+
description: "Repository path (e.g., andrpac/my-repo)"
10+
required: true
11+
image_sha:
12+
description: "Short SHA or 'latest'"
13+
required: true
14+
15+
outputs:
16+
commit_sha:
17+
description: "Resolved full commit SHA"
18+
value: ${{ steps.resolve.outputs.commit_sha }}
19+
runs:
20+
using: "composite"
21+
steps:
22+
- name: Install skopeo and jq
23+
shell: bash
24+
run: |
25+
sudo apt-get update
26+
sudo apt-get install -y skopeo jq
27+
28+
- name: Resolve commit SHA
29+
id: resolve
30+
shell: bash
31+
run: |
32+
chmod +x ${{ github.action_path }}/entrypoint.sh
33+
full_sha=$(${{
34+
github.action_path
35+
}}/entrypoint.sh \
36+
"${{ inputs.register }}" \
37+
"${{ inputs.repo }}" \
38+
"${{ inputs.image_sha }}"
39+
)
40+
41+
echo "Raw full_sha: $full_sha"
42+
echo "commit_sha=$full_sha" >> $GITHUB_OUTPUT
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#!/bin/bash
2+
# Copyright 2025 MongoDB Inc
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
16+
# This script retrives the git commit sha given an image sha
17+
18+
set -euo pipefail
19+
20+
registry="$1"
21+
repo="$2"
22+
image_sha="$3"
23+
24+
if [[ "$image_sha" == "latest" ]]; then
25+
tag="promoted-latest"
26+
else
27+
tag="promoted-${image_sha}"
28+
fi
29+
30+
full_image="${registry}/${repo}:${tag}"
31+
32+
sha=$(skopeo inspect "docker://${full_image}" | jq -r '.Labels["org.opencontainers.image.revision"]')
33+
34+
if [[ -z "$sha" || "$sha" == "null" ]]; then
35+
echo "Error: Could not extract commit SHA from $full_image" >&2
36+
exit 1
37+
fi
38+
39+
echo "$sha"

.github/workflows/promote-image.yml

Lines changed: 15 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,14 @@ on:
44
workflow_run:
55
workflows: ["Test"]
66
types: [completed]
7+
push:
8+
branches:
9+
- '**'
710

811
jobs:
912
promote-image:
1013
runs-on: ubuntu-latest
1114
environment: release
12-
if: |
13-
github.event.workflow_run.head_branch == 'main' &&
14-
github.event.workflow_run.conclusion == 'success' &&
15-
github.event.workflow_run.event == 'schedule'
1615
env:
1716
GHCR_REPO: ghcr.io/mongodb/mongodb-atlas-kubernetes-operator-prerelease
1817
DOCKER_REPO: docker.io/mongodb/mongodb-atlas-kubernetes-operator-prerelease
@@ -21,43 +20,33 @@ jobs:
2120
- name: Checkout PR commit
2221
uses: actions/checkout@v4
2322

24-
# Note, we have to be careful how we retrive the image. The event that pushed
25-
# the image to the ghcr.io repo was mainly a push/schedule that passed all the
26-
# tests. This event has access to github.ref_name. However, the workflow_run
27-
# event does not have access github.ref_name set up.
28-
#
29-
# Therefore, we need to manually specify the branch as main
30-
- name: Prepare image tag
31-
id: set_tag
32-
uses: ./.github/actions/set-tag
33-
with:
34-
branch_name: ${{ github.event.workflow_run.head_branch }}
35-
commit_sha: ${{ github.event.workflow_run.head_sha }}
36-
3723
- name: Log in to the GitHub Container Registry
3824
uses: docker/login-action@v3
3925
with:
4026
registry: ghcr.io
4127
username: ${{ github.actor }}
4228
password: ${{ secrets.GITHUB_TOKEN }}
4329

44-
- name: Pull unofficial image from GitHub Container Registry
45-
run: |
46-
docker pull ${{ env.GHCR_REPO }}:${{ steps.set_tag.outputs.tag }}
47-
4830
- name: Login to Docker registry
4931
uses: docker/login-action@v3
5032
with:
5133
registry: docker.io
5234
username: ${{ secrets.DOCKER_USERNAME }}
5335
password: ${{ secrets.DOCKER_PASSWORD }}
54-
36+
5537
- name: Log in to Quay registry
5638
uses: docker/login-action@v3
5739
with:
5840
registry: quay.io
5941
username: ${{ secrets.QUAY_USERNAME }}
6042
password: ${{ secrets.QUAY_PASSWORD }}
43+
44+
- name: Prepare image tag
45+
id: set_tag
46+
uses: ./.github/actions/set-tag
47+
with:
48+
branch_name: ${{ github.event.workflow_run.head_branch }}
49+
commit_sha: ${{ github.event.workflow_run.head_sha }}
6150

6251
- name: Prepare tag for promoted image
6352
id: promoted_tag
@@ -73,6 +62,8 @@ jobs:
7362
IMAGE_DEST_REPO: ${{ env.DOCKER_REPO }}
7463
IMAGE_SRC_TAG: ${{ steps.set_tag.outputs.tag }}
7564
IMAGE_DEST_TAG: ${{ steps.promoted_tag.outputs.tag }}
65+
ALIAS_ENABLED: true
66+
ALIAS_TAG: promoted-latest
7667

7768
- name: Move image to Quay
7869
run: ./scripts/move-image.sh
@@ -81,3 +72,5 @@ jobs:
8172
IMAGE_DEST_REPO: ${{ env.QUAY_REPO }}
8273
IMAGE_SRC_TAG: ${{ steps.set_tag.outputs.tag }}
8374
IMAGE_DEST_TAG: ${{ steps.promoted_tag.outputs.tag }}
75+
ALIAS_ENABLED: true
76+
ALIAS_TAG: promoted-latest

.github/workflows/release-branch.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
# Create Release Branch
1+
# DEPRECATED: Create Release Branch
22
# TODO after GitHub add permission for action-bot to commit to the protected branches - please merge release-* workflow into one
33

4-
name: Create Release Branch
4+
name: "[Deprecated] Create Release Branch"
55

66
on:
77
workflow_dispatch:

0 commit comments

Comments
 (0)