Skip to content

Commit f47b691

Browse files
Improve Image Versioning (#7)
- Build and publish images based on git tags - Simplify python tag name - Publish a mutable main image
1 parent 2946c66 commit f47b691

File tree

3 files changed

+52
-8
lines changed

3 files changed

+52
-8
lines changed

.github/workflows/build.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ on:
88

99
env:
1010
REGISTRY: ghcr.io
11+
PUSH: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }}
1112

1213
jobs:
1314
bake:
@@ -26,4 +27,6 @@ jobs:
2627
- name: Build and Push
2728
uses: docker/bake-action@37816e747588cb137173af99ab33873600c46ea8 # v6
2829
with:
29-
push: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }}
30+
push: ${{ env.PUSH == 'true' }}
31+
env:
32+
BUILD_VERSION: ${{ env.PUSH == 'true' && 'main' || 'pr' }}

.github/workflows/publish.yml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
name: Publish Images
2+
3+
on:
4+
push:
5+
tags:
6+
- '*'
7+
8+
env:
9+
REGISTRY: ghcr.io
10+
11+
jobs:
12+
bake:
13+
runs-on: ubuntu-latest
14+
steps:
15+
- name: Checkout
16+
uses: actions/checkout@v4
17+
18+
- name: Set up Docker Buildx
19+
uses: docker/setup-buildx-action@v3
20+
21+
- name: Login to GitHub Container Registry
22+
uses: docker/login-action@v3
23+
with:
24+
registry: ${{ env.REGISTRY }}
25+
username: ${{ github.actor }}
26+
password: ${{ secrets.GITHUB_TOKEN }}
27+
28+
- name: Build and Push
29+
uses: docker/bake-action@v4
30+
with:
31+
push: true
32+
env:
33+
BUILD_VERSION: ${{ github.ref_name }}

docker-bake.hcl

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,29 @@
1-
group "default" {
2-
targets = ["python"]
1+
variable "BUILD_VERSION" {
2+
default = "dev"
3+
}
4+
5+
variable "PYTHON_VERSION" {
6+
default = "3.13.5"
37
}
48

5-
variable "PYTHON_TAG" {
6-
default = "3.13.5-slim-bookworm"
9+
variable "PYTHON_BASE_VARIANT" {
10+
default = "slim-bookworm"
711
}
812

9-
variable "PYTHON_SHA" {
13+
variable "PYTHON_BASE_SHA" {
1014
default = "f2fdaec50160418e0c2867ba3e254755edd067171725886d5d303fd7057bbf81"
1115
}
1216

17+
group "default" {
18+
targets = ["python"]
19+
}
20+
1321
target "python" {
1422
context = "docker/python"
1523
args = {
16-
PYTHON_TAG_SHA = "${PYTHON_TAG}@sha256:${PYTHON_SHA}"
24+
PYTHON_TAG_SHA = "${PYTHON_VERSION}-${PYTHON_BASE_VARIANT}@sha256:${PYTHON_BASE_SHA}"
1725
}
1826
tags = [
19-
"ghcr.io/powerhome/cdk8s-cmp-python:${PYTHON_TAG}"
27+
"ghcr.io/powerhome/cdk8s-cmp-python:${BUILD_VERSION}-${PYTHON_VERSION}"
2028
]
2129
}

0 commit comments

Comments
 (0)