Skip to content

Commit 6ef6074

Browse files
committed
feat(docker): update workflow to push images on branch pushes and refine tag handling
1 parent bc637a7 commit 6ef6074

1 file changed

Lines changed: 38 additions & 31 deletions

File tree

Lines changed: 38 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,44 @@
1-
# This workflow pushes new Bitsong docker images on every new tag.
1+
# This workflow pushes new Bitsong docker images on every new tag or branch push.
22
#
33
# On every new `vX.Y.Z` tag the following images are pushed:
44
#
55
# bitsongofficial/go-bitsong:vX.Y.Z # is pushed
66
# bitsongofficial/go-bitsong:X.Y.Z # is pushed
77
# bitsongofficial/go-bitsong:X.Y # is updated to X.Y.Z
88
# bitsongofficial/go-bitsong:X # is updated to X.Y.Z
9-
# bitsongofficial/go-bitsong:latest # is updated to X.Y.Z
109
#
11-
# bitsongofficial/go-bitsong-e2e:vX.Y.Z # is pushed
12-
# bitsongofficial/go-bitsong-e2e:X.Y.Z # is pushed
13-
# bitsongofficial/go-bitsong-e2e:X.Y # is updated to X.Y.Z
14-
# bitsongofficial/go-bitsong-e2e:X # is updated to X.Y.Z
15-
# bitsongofficial/go-bitsong-e2e:latest # is updated to X.Y.Z
10+
# On branch pushes (e.g. feat-hyperlane) the following images are pushed:
11+
#
12+
# bitsongofficial/go-bitsong:feat-hyperlane # latest for that branch
13+
# bitsongofficial/go-bitsong:feat-hyperlane-abc1234 # pinned to commit
1614
#
1715
# All the images above have support for linux/amd64 and linux/arm64.
1816

1917
name: Push Docker Images
2018

2119
env:
2220
DOCKER_REPOSITORY: bitsongofficial/go-bitsong
23-
RUNNER_BASE_IMAGE_DISTROLESS: gcr.io/distroless/static-debian12
24-
RUNNER_BASE_IMAGE_NONROOT: gcr.io/distroless/static-debian12:nonroot
25-
RUNNER_BASE_IMAGE_ALPINE: alpine:3.21
2621

2722
on:
2823
release:
2924
types: [published, created, edited]
3025
push:
3126
tags:
32-
- 'v[0-9]+.[0-9]+.[0-9]+' # ignore rc
27+
- 'v[0-9]+.[0-9]+.[0-9]+' # ignore rc
28+
branches:
29+
- 'feat-hyperlane'
3330

3431
jobs:
3532
bitsong-images:
3633
runs-on: ubuntu-latest
3734
steps:
38-
-
35+
-
3936
name: Check out the repo
4037
uses: actions/checkout@v4
41-
-
38+
-
4239
name: Set up QEMU
4340
uses: docker/setup-qemu-action@v3
44-
-
41+
-
4542
name: Set up Docker Buildx
4643
uses: docker/setup-buildx-action@v3
4744
- name: Login to GitHub Container Registry
@@ -51,28 +48,38 @@ jobs:
5148
username: ${{ github.repository_owner }}
5249
password: ${{ secrets.GITHUB_TOKEN }}
5350
-
54-
name: Parse tag
55-
id: tag
51+
name: Determine image tags
52+
id: tags
5653
run: |
57-
VERSION=$(echo ${{ github.ref_name }} | sed "s/v//")
58-
MAJOR_VERSION=$(echo $VERSION | cut -d '.' -f 1)
59-
MINOR_VERSION=$(echo $VERSION | cut -d '.' -f 2)
60-
PATCH_VERSION=$(echo $VERSION | cut -d '.' -f 3)
61-
echo "VERSION=$VERSION" >> $GITHUB_ENV
62-
echo "MAJOR_VERSION=$MAJOR_VERSION" >> $GITHUB_ENV
63-
echo "MINOR_VERSION=$MINOR_VERSION" >> $GITHUB_ENV
64-
echo "PATCH_VERSION=$PATCH_VERSION" >> $GITHUB_ENV
65-
-
66-
name: Build and push
54+
SHORT_SHA=$(echo "${{ github.sha }}" | cut -c1-7)
55+
56+
if [[ "${{ github.ref_type }}" == "tag" ]]; then
57+
# Tag push: produce semver tags (e.g. v0.21.0 -> 0, 0.21, 0.21.0, v0.21.0)
58+
VERSION=$(echo "${{ github.ref_name }}" | sed "s/v//")
59+
MAJOR_VERSION=$(echo "$VERSION" | cut -d '.' -f 1)
60+
MINOR_VERSION=$(echo "$VERSION" | cut -d '.' -f 2)
61+
PATCH_VERSION=$(echo "$VERSION" | cut -d '.' -f 3)
62+
IMAGE_TAGS="ghcr.io/${{ env.DOCKER_REPOSITORY }}:${MAJOR_VERSION}
63+
ghcr.io/${{ env.DOCKER_REPOSITORY }}:${MAJOR_VERSION}.${MINOR_VERSION}
64+
ghcr.io/${{ env.DOCKER_REPOSITORY }}:${MAJOR_VERSION}.${MINOR_VERSION}.${PATCH_VERSION}
65+
ghcr.io/${{ env.DOCKER_REPOSITORY }}:v${MAJOR_VERSION}.${MINOR_VERSION}.${PATCH_VERSION}"
66+
else
67+
# Branch push: produce branch + commit-pinned tags
68+
BRANCH=$(echo "${{ github.ref_name }}" | sed 's/\//-/g')
69+
IMAGE_TAGS="ghcr.io/${{ env.DOCKER_REPOSITORY }}:${BRANCH}
70+
ghcr.io/${{ env.DOCKER_REPOSITORY }}:${BRANCH}-${SHORT_SHA}"
71+
fi
72+
73+
echo "IMAGE_TAGS<<EOF" >> $GITHUB_OUTPUT
74+
echo "$IMAGE_TAGS" >> $GITHUB_OUTPUT
75+
echo "EOF" >> $GITHUB_OUTPUT
76+
-
77+
name: Build and push
6778
id: build_push_image
6879
uses: docker/build-push-action@v5
6980
with:
7081
file: Dockerfile
7182
context: .
7283
push: true
7384
platforms: linux/amd64,linux/arm64
74-
tags: |
75-
ghcr.io/bitsongofficial/go-bitsong:${{ env.MAJOR_VERSION }}
76-
ghcr.io/bitsongofficial/go-bitsong:${{ env.MAJOR_VERSION }}.${{ env.MINOR_VERSION }}
77-
ghcr.io/bitsongofficial/go-bitsong:${{ env.MAJOR_VERSION }}.${{ env.MINOR_VERSION }}.${{ env.PATCH_VERSION }}
78-
ghcr.io/bitsongofficial/go-bitsong:v${{ env.MAJOR_VERSION }}.${{ env.MINOR_VERSION }}.${{ env.PATCH_VERSION }}
85+
tags: ${{ steps.tags.outputs.IMAGE_TAGS }}

0 commit comments

Comments
 (0)