Skip to content

Commit a9bf99b

Browse files
Fix release multiarch (#363)
* Removed basename usage which is not in github runners * Added temporary build in pull request action for testing * Testing setup github action * Changing Makefile dependecy order for multiarch because docker needs image to be pushed before creating the manifest * Removed testing target * Moved release oci runtime to docker because of old podman version on github action runners * Removed testing step * Switched ci build to docker for consistency * Fix PHONY in Makefile * Fix Makefile syntax * Update runner version * Small rollback
1 parent c87220a commit a9bf99b

File tree

4 files changed

+38
-39
lines changed

4 files changed

+38
-39
lines changed

.github/workflows/push_image.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ env:
1313
jobs:
1414
push-image:
1515
name: push image
16-
runs-on: ubuntu-20.04
16+
runs-on: ubuntu-latest
1717
strategy:
1818
matrix:
1919
go: ['1.18']
@@ -26,17 +26,17 @@ jobs:
2626
go-version: ${{ matrix.go }}
2727
- name: checkout
2828
uses: actions/checkout@v2
29-
- name: build images
30-
run: DOCKER_TAG=${{ env.TAG }} make build-ci-images
31-
- name: podman login to quay.io
32-
uses: redhat-actions/podman-login@v1
29+
- name: docker login to quay.io
30+
uses: docker/login-action@v2
3331
with:
3432
username: ${{ env.REGISTRY_USER }}
3533
password: ${{ env.REGISTRY_PASSWORD }}
3634
registry: quay.io
3735
- name: get short sha
3836
id: shortsha
3937
run: echo "::set-output name=short_sha::$(git rev-parse --short HEAD)"
38+
- name: build and push images
39+
run: OCI_RUNTIME=docker DOCKER_TAG=${{ env.TAG }} make push-ci-images
4040
- name: push to quay.io
4141
id: push-to-quay
4242
uses: redhat-actions/push-to-registry@v2

.github/workflows/push_image_pr.yml

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ jobs:
1212
push-pr-image:
1313
if: ${{ github.event.label.name == 'ok-to-test' }}
1414
name: push PR image
15-
runs-on: ubuntu-20.04
15+
runs-on: ubuntu-latest
1616
strategy:
1717
matrix:
1818
go: ['1.18']
@@ -27,24 +27,17 @@ jobs:
2727
uses: actions/checkout@v2
2828
with:
2929
ref: "refs/pull/${{ github.event.number }}/merge"
30-
- name: build images
31-
run: DOCKER_TAG=temp make build-ci-images
32-
- name: podman login to quay.io
33-
uses: redhat-actions/podman-login@v1
30+
- name: docker login to quay.io
31+
uses: docker/login-action@v2
3432
with:
3533
username: ${{ env.REGISTRY_USER }}
3634
password: ${{ secrets.QUAY_SECRET }}
3735
registry: quay.io
3836
- name: get short sha
3937
id: shortsha
4038
run: echo "::set-output name=short_sha::$(git rev-parse --short HEAD)"
41-
- name: push to quay.io
42-
id: push-to-quay
43-
uses: redhat-actions/push-to-registry@v2
44-
with:
45-
image: ${{ env.IMAGE }}
46-
tags: ${{ steps.shortsha.outputs.short_sha }}
47-
registry: ${{ env.REGISTRY }}
39+
- name: build and push images
40+
run: OCI_RUNTIME=docker DOCKER_TAG=temp make push-ci-images
4841
- uses: actions/github-script@v5
4942
with:
5043
github-token: ${{secrets.GITHUB_TOKEN}}

.github/workflows/release.yml

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -37,20 +37,13 @@ jobs:
3737
uses: actions/setup-go@v2
3838
with:
3939
go-version: ${{ matrix.go }}
40-
- name: build images
41-
run: DOCKER_TAG=${{ steps.validate_tag.outputs.tag }} make build-image-multiarch
42-
- name: podman login to quay.io
43-
uses: redhat-actions/podman-login@v1
40+
- name: docker login to quay.io
41+
uses: docker/login-action@v2
4442
with:
4543
username: ${{ env.REGISTRY_USER }}
4644
password: ${{ env.REGISTRY_PASSWORD }}
4745
registry: quay.io
48-
- name: push to quay.io
49-
id: push-to-quay
50-
uses: redhat-actions/push-to-registry@v2
51-
with:
52-
image: ${{ env.IMAGE }}
53-
tags: ${{ steps.validate_tag.outputs.tag }}
54-
registry: ${{ env.REGISTRY }}
46+
- name: build and push images
47+
run: OCI_RUNTIME=docker DOCKER_TAG=${{ steps.validate_tag.outputs.tag }} make push-multiarch-manifest
5548
- name: print image url
5649
run: echo "Image pushed to ${{ steps.push-to-quay.outputs.registry-paths }}"

Makefile

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ GOARCH ?= amd64
1414
SHELL := /usr/bin/env bash
1515
DOCKER_TAG ?= latest
1616
DOCKER_IMG ?= quay.io/netobserv/flowlogs-pipeline
17-
OCI_RUNTIME ?= $(shell which podman || which docker)
17+
OCI_RUNTIME_PATH = $(shell which podman || which docker)
18+
OCI_RUNTIME ?= $(shell v='$(OCI_RUNTIME_PATH)'; echo "$${v##*/}")
1819
MIN_GO_VERSION := 1.18.0
1920
FLP_BIN_FILE=flowlogs-pipeline
2021
CG_BIN_FILE=confgenerator
@@ -130,23 +131,26 @@ run: build ## Run
130131
build-image:
131132
DOCKER_BUILDKIT=1 $(OCI_RUNTIME) build -t $(DOCKER_IMG):$(DOCKER_TAG) -f contrib/docker/Dockerfile .
132133

133-
build-image-multiarch-linux/%:
134+
# It would have been better to have
135+
build-single-multiarch-linux/%:
134136
#The --load option is ignored by podman but required for docker
135137
DOCKER_BUILDKIT=1 $(OCI_RUNTIME) buildx build --load --build-arg TARGETPLATFORM=linux/$* --build-arg TARGETARCH=$* --build-arg BUILDPLATFORM=linux/amd64 -t $(DOCKER_IMG):$(DOCKER_TAG)-$* -f contrib/docker/Dockerfile .
136138

137-
# note: to build and push custom image tag use: DOCKER_TAG=test make push-image
138-
.PHONY: build-image-multiarch
139-
build-image-multiarch: build-image-multiarch-linux/amd64 build-image-multiarch-linux/arm64 build-image-multiarch-linux/ppc64le
140-
DOCKER_BUILDKIT=1 $(OCI_RUNTIME) manifest create $(DOCKER_IMG):$(DOCKER_TAG) --amend $(DOCKER_IMG):$(DOCKER_TAG)-amd64 --amend $(DOCKER_IMG):$(DOCKER_TAG)-arm64 --amend $(DOCKER_IMG):$(DOCKER_TAG)-ppc64le
141-
142-
push-image-multiarch-linux/%:
139+
# It would have been better to have
140+
push-single-multiarch-linux/%: build-single-multiarch-linux/%
141+
#The --load option is ignored by podman but required for docker
143142
DOCKER_BUILDKIT=1 $(OCI_RUNTIME) push $(DOCKER_IMG):$(DOCKER_TAG)-$*
144143

144+
# note: to build and push custom image tag use: DOCKER_TAG=test make push-image
145+
.PHONY: build-multiarch-manifest
146+
build-multiarch-manifest: push-single-multiarch-linux/amd64 push-single-multiarch-linux/arm64 push-single-multiarch-linux/ppc64le
147+
#if using Docker, image needs to be pushed before beeing added to the manifest
148+
DOCKER_BUILDKIT=1 $(OCI_RUNTIME) manifest create $(DOCKER_IMG):$(DOCKER_TAG) --amend $(DOCKER_IMG):$(DOCKER_TAG)-amd64 --amend $(DOCKER_IMG):$(DOCKER_TAG)-arm64 --amend $(DOCKER_IMG):$(DOCKER_TAG)-ppc64le
145149

146-
.PHONY: push-image-multiarch
147-
push-image-multiarch: build-image-multiarch push-image-multiarch-linux/amd64 push-image-multiarch-linux/arm64 push-image-multiarch-linux/ppc64le
150+
.PHONY: push-multiarch-manifest
151+
push-multiarch-manifest: build-multiarch-manifest
148152
@echo 'publish manifest $(DOCKER_TAG) to $(DOCKER_IMG)'
149-
ifeq ($(shell basename $(OCI_RUNTIME)), docker)
153+
ifeq (${OCI_RUNTIME} , docker)
150154
DOCKER_BUILDKIT=1 $(OCI_RUNTIME) manifest push $(DOCKER_IMG):$(DOCKER_TAG)
151155
else
152156
DOCKER_BUILDKIT=1 $(OCI_RUNTIME) manifest push $(DOCKER_IMG):$(DOCKER_TAG) docker://$(DOCKER_IMG):$(DOCKER_TAG)
@@ -163,6 +167,15 @@ else
163167
endif
164168
DOCKER_BUILDKIT=1 $(OCI_RUNTIME) build --build-arg BASE_IMAGE=$(DOCKER_IMG):$(DOCKER_TAG) -t $(DOCKER_IMG):$(COMMIT) -f contrib/docker/shortlived.Dockerfile .
165169

170+
.PHONY: push-ci-images
171+
push-ci-images:
172+
DOCKER_BUILDKIT=1 $(OCI_RUNTIME) push $(DOCKER_IMG):$(COMMIT)
173+
ifeq ($(DOCKER_TAG), main)
174+
# Also tag "latest" only for branch "main"
175+
DOCKER_BUILDKIT=1 $(OCI_RUNTIME) push $(DOCKER_IMG):$(DOCKER_TAG)
176+
DOCKER_BUILDKIT=1 $(OCI_RUNTIME) push $(DOCKER_IMG):latest
177+
endif
178+
166179
.PHONY: push-image
167180
push-image: build-image ## Push latest image
168181
@echo 'publish image $(DOCKER_TAG) to $(DOCKER_IMG)'

0 commit comments

Comments
 (0)