Skip to content

Commit 568fe51

Browse files
ci: replace individual github workflows with matrix-build for dockerfiles
Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
1 parent 2dfa8c5 commit 568fe51

3 files changed

Lines changed: 32 additions & 4 deletions

File tree

.github/actions/docker-build/action.yml

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ inputs:
2424
suffix:
2525
description: "The suffix for the docker tag (e.g., amd64)"
2626
required: false
27+
ghcr_user:
28+
description: "GHCR username"
29+
required: false
30+
default: ${{ github.repository_owner }}
2731

2832
runs:
2933
using: "composite"
@@ -41,14 +45,35 @@ runs:
4145
username: ${{ inputs.docker_user }}
4246
password: ${{ inputs.docker_pass }}
4347

48+
- name: Login to GitHub Container Registry
49+
if: inputs.docker_push == 'true'
50+
uses: docker/login-action@v3
51+
with:
52+
registry: ghcr.io
53+
username: ${{ github.actor }}
54+
password: ${{ inputs.github_token }}
55+
4456
- name: Run Makefile Target
4557
shell: bash
4658
env:
4759
TARGET: ${{ inputs.target }}
4860
USER_DEFAULT: ${{ inputs.docker_user }}
61+
GHCR_USER: ${{ inputs.ghcr_user }}
4962
DOCKER_PUSH: ${{ inputs.docker_push }}
5063
GITHUB_ACCESS_TOKEN: ${{ inputs.github_token }}
5164
DOCKER_BUILDER_PLATFORM: ${{ inputs.platform }}
5265
DOCKER_ARCH_SUFFIX: ${{ inputs.suffix }}
66+
EVENT_NAME: ${{ github.event_name }}
67+
EVENT_PATH: ${{ github.event_path }}
68+
GITHUB_REF_VAR: ${{ github.ref }}
5369
run: |
54-
make "$TARGET" DOCKER_PUSH="$DOCKER_PUSH" USER="$USER_DEFAULT" GITHUB_ACCESS_TOKEN="$GITHUB_ACCESS_TOKEN" DOCKER_BUILDER_PLATFORM="$DOCKER_BUILDER_PLATFORM" DOCKER_ARCH_SUFFIX="$DOCKER_ARCH_SUFFIX"
70+
VERSION="nightly"
71+
72+
if [ "$EVENT_NAME" == "pull_request" ]; then
73+
PR_NUM=$(jq -r ".number" "$EVENT_PATH")
74+
VERSION="pr-$PR_NUM"
75+
elif [[ "$GITHUB_REF_VAR" == refs/tags/* ]]; then
76+
VERSION="${GITHUB_REF_VAR#refs/tags/}"
77+
fi
78+
79+
make "$TARGET" DOCKER_PUSH="$DOCKER_PUSH" USER="$USER_DEFAULT" GHCR_USER="$GHCR_USER" VERSION="$VERSION" GITHUB_ACCESS_TOKEN="$GITHUB_ACCESS_TOKEN" DOCKER_BUILDER_PLATFORM="$DOCKER_BUILDER_PLATFORM" DOCKER_ARCH_SUFFIX="$DOCKER_ARCH_SUFFIX"

.github/workflows/docker-matrix.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ jobs:
137137
merge_dev:
138138
needs: build_dev
139139
if: github.event_name != 'pull_request'
140+
if: github.event_name != 'pull_request'
140141
runs-on: ubuntu-latest
141142
steps:
142143
- uses: actions/checkout@v4

Makefile

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ EMAIL = kpango@vdaas.org
1313

1414
DOCKER_EXTRA_OPTS ?=
1515
DOCKER_ARCH_SUFFIX ?=
16+
GHCR_USER ?= $(USER)
1617
DOCKER_PUSH ?= true
1718
DOCKER_BUILDER_NAME = "kpango-builder"
1819
DOCKER_BUILDER_DRIVER = "docker-container"
@@ -22,9 +23,6 @@ DOCKER_BUILD_CACHE_DIR:= $(HOME)/.docker/buildcache
2223
DOCKER_MEMORY_LIMIT = 32G
2324

2425
VERSION ?= latest
25-
ifneq (,$(findstring refs/tags/,$(GITHUB_REF)))
26-
VERSION := $(subst refs/tags/,,$(GITHUB_REF))
27-
endif
2826

2927
ifneq ($(DOCKER_ARCH_SUFFIX),)
3028
DOCKER_TAG_VERSION = $(VERSION)-$(DOCKER_ARCH_SUFFIX)
@@ -441,6 +439,7 @@ docker_build:
441439
--provenance=mode=max \
442440
--secret id=gat,src="$(TMP_DIR)/gat" \
443441
-t "$(USER)/$(NAME):$(DOCKER_TAG_VERSION)" \
442+
-t "ghcr.io/$(GHCR_USER)/$(NAME):$(DOCKER_TAG_VERSION)" \
444443
-f $(DOCKERFILE) .
445444
# --cache-to type=image,ref=$(DOCKER_CACHE_REPO),mode=max,inline=true \
446445
docker buildx rm --force "$(DOCKER_BUILDER_NAME)"
@@ -559,6 +558,9 @@ docker_merge:
559558
docker buildx imagetools create -t "$(USER)/$(NAME):$(VERSION)" \
560559
"$(USER)/$(NAME):$(VERSION)-amd64" \
561560
"$(USER)/$(NAME):$(VERSION)-arm64"
561+
docker buildx imagetools create -t "ghcr.io/$(GHCR_USER)/$(NAME):$(VERSION)" \
562+
"ghcr.io/$(GHCR_USER)/$(NAME):$(VERSION)-amd64" \
563+
"ghcr.io/$(GHCR_USER)/$(NAME):$(VERSION)-arm64"
562564

563565
do_merge:
564566
@make NAME="$(NAME)" docker_merge

0 commit comments

Comments
 (0)