Skip to content

Commit

Permalink
Fix release multiarch (#363)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
OlivierCazade committed Jan 23, 2023
1 parent c87220a commit a9bf99b
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 39 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/push_image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ env:
jobs:
push-image:
name: push image
runs-on: ubuntu-20.04
runs-on: ubuntu-latest
strategy:
matrix:
go: ['1.18']
Expand All @@ -26,17 +26,17 @@ jobs:
go-version: ${{ matrix.go }}
- name: checkout
uses: actions/checkout@v2
- name: build images
run: DOCKER_TAG=${{ env.TAG }} make build-ci-images
- name: podman login to quay.io
uses: redhat-actions/podman-login@v1
- name: docker login to quay.io
uses: docker/login-action@v2
with:
username: ${{ env.REGISTRY_USER }}
password: ${{ env.REGISTRY_PASSWORD }}
registry: quay.io
- name: get short sha
id: shortsha
run: echo "::set-output name=short_sha::$(git rev-parse --short HEAD)"
- name: build and push images
run: OCI_RUNTIME=docker DOCKER_TAG=${{ env.TAG }} make push-ci-images
- name: push to quay.io
id: push-to-quay
uses: redhat-actions/push-to-registry@v2
Expand Down
17 changes: 5 additions & 12 deletions .github/workflows/push_image_pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
push-pr-image:
if: ${{ github.event.label.name == 'ok-to-test' }}
name: push PR image
runs-on: ubuntu-20.04
runs-on: ubuntu-latest
strategy:
matrix:
go: ['1.18']
Expand All @@ -27,24 +27,17 @@ jobs:
uses: actions/checkout@v2
with:
ref: "refs/pull/${{ github.event.number }}/merge"
- name: build images
run: DOCKER_TAG=temp make build-ci-images
- name: podman login to quay.io
uses: redhat-actions/podman-login@v1
- name: docker login to quay.io
uses: docker/login-action@v2
with:
username: ${{ env.REGISTRY_USER }}
password: ${{ secrets.QUAY_SECRET }}
registry: quay.io
- name: get short sha
id: shortsha
run: echo "::set-output name=short_sha::$(git rev-parse --short HEAD)"
- name: push to quay.io
id: push-to-quay
uses: redhat-actions/push-to-registry@v2
with:
image: ${{ env.IMAGE }}
tags: ${{ steps.shortsha.outputs.short_sha }}
registry: ${{ env.REGISTRY }}
- name: build and push images
run: OCI_RUNTIME=docker DOCKER_TAG=temp make push-ci-images
- uses: actions/github-script@v5
with:
github-token: ${{secrets.GITHUB_TOKEN}}
Expand Down
15 changes: 4 additions & 11 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,20 +37,13 @@ jobs:
uses: actions/setup-go@v2
with:
go-version: ${{ matrix.go }}
- name: build images
run: DOCKER_TAG=${{ steps.validate_tag.outputs.tag }} make build-image-multiarch
- name: podman login to quay.io
uses: redhat-actions/podman-login@v1
- name: docker login to quay.io
uses: docker/login-action@v2
with:
username: ${{ env.REGISTRY_USER }}
password: ${{ env.REGISTRY_PASSWORD }}
registry: quay.io
- name: push to quay.io
id: push-to-quay
uses: redhat-actions/push-to-registry@v2
with:
image: ${{ env.IMAGE }}
tags: ${{ steps.validate_tag.outputs.tag }}
registry: ${{ env.REGISTRY }}
- name: build and push images
run: OCI_RUNTIME=docker DOCKER_TAG=${{ steps.validate_tag.outputs.tag }} make push-multiarch-manifest
- name: print image url
run: echo "Image pushed to ${{ steps.push-to-quay.outputs.registry-paths }}"
35 changes: 24 additions & 11 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ GOARCH ?= amd64
SHELL := /usr/bin/env bash
DOCKER_TAG ?= latest
DOCKER_IMG ?= quay.io/netobserv/flowlogs-pipeline
OCI_RUNTIME ?= $(shell which podman || which docker)
OCI_RUNTIME_PATH = $(shell which podman || which docker)
OCI_RUNTIME ?= $(shell v='$(OCI_RUNTIME_PATH)'; echo "$${v##*/}")
MIN_GO_VERSION := 1.18.0
FLP_BIN_FILE=flowlogs-pipeline
CG_BIN_FILE=confgenerator
Expand Down Expand Up @@ -130,23 +131,26 @@ run: build ## Run
build-image:
DOCKER_BUILDKIT=1 $(OCI_RUNTIME) build -t $(DOCKER_IMG):$(DOCKER_TAG) -f contrib/docker/Dockerfile .

build-image-multiarch-linux/%:
# It would have been better to have
build-single-multiarch-linux/%:
#The --load option is ignored by podman but required for docker
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 .

# note: to build and push custom image tag use: DOCKER_TAG=test make push-image
.PHONY: build-image-multiarch
build-image-multiarch: build-image-multiarch-linux/amd64 build-image-multiarch-linux/arm64 build-image-multiarch-linux/ppc64le
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

push-image-multiarch-linux/%:
# It would have been better to have
push-single-multiarch-linux/%: build-single-multiarch-linux/%
#The --load option is ignored by podman but required for docker
DOCKER_BUILDKIT=1 $(OCI_RUNTIME) push $(DOCKER_IMG):$(DOCKER_TAG)-$*

# note: to build and push custom image tag use: DOCKER_TAG=test make push-image
.PHONY: build-multiarch-manifest
build-multiarch-manifest: push-single-multiarch-linux/amd64 push-single-multiarch-linux/arm64 push-single-multiarch-linux/ppc64le
#if using Docker, image needs to be pushed before beeing added to the manifest
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

.PHONY: push-image-multiarch
push-image-multiarch: build-image-multiarch push-image-multiarch-linux/amd64 push-image-multiarch-linux/arm64 push-image-multiarch-linux/ppc64le
.PHONY: push-multiarch-manifest
push-multiarch-manifest: build-multiarch-manifest
@echo 'publish manifest $(DOCKER_TAG) to $(DOCKER_IMG)'
ifeq ($(shell basename $(OCI_RUNTIME)), docker)
ifeq (${OCI_RUNTIME} , docker)
DOCKER_BUILDKIT=1 $(OCI_RUNTIME) manifest push $(DOCKER_IMG):$(DOCKER_TAG)
else
DOCKER_BUILDKIT=1 $(OCI_RUNTIME) manifest push $(DOCKER_IMG):$(DOCKER_TAG) docker://$(DOCKER_IMG):$(DOCKER_TAG)
Expand All @@ -163,6 +167,15 @@ else
endif
DOCKER_BUILDKIT=1 $(OCI_RUNTIME) build --build-arg BASE_IMAGE=$(DOCKER_IMG):$(DOCKER_TAG) -t $(DOCKER_IMG):$(COMMIT) -f contrib/docker/shortlived.Dockerfile .

.PHONY: push-ci-images
push-ci-images:
DOCKER_BUILDKIT=1 $(OCI_RUNTIME) push $(DOCKER_IMG):$(COMMIT)
ifeq ($(DOCKER_TAG), main)
# Also tag "latest" only for branch "main"
DOCKER_BUILDKIT=1 $(OCI_RUNTIME) push $(DOCKER_IMG):$(DOCKER_TAG)
DOCKER_BUILDKIT=1 $(OCI_RUNTIME) push $(DOCKER_IMG):latest
endif

.PHONY: push-image
push-image: build-image ## Push latest image
@echo 'publish image $(DOCKER_TAG) to $(DOCKER_IMG)'
Expand Down

0 comments on commit a9bf99b

Please sign in to comment.