Skip to content

Commit

Permalink
[PERFSCALE-2470]: Updates to the GHA (#106)
Browse files Browse the repository at this point in the history
This PR updates the GHA workflow for build & publishing
multi-architecture container images

Signed-off-by: Krishna Harsha Voora <[email protected]>
  • Loading branch information
krishvoor authored Sep 25, 2023
1 parent 1c79ea3 commit 5e39470
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 51 deletions.
69 changes: 26 additions & 43 deletions .github/workflows/build-container.yml
Original file line number Diff line number Diff line change
@@ -1,67 +1,50 @@
name: Release k8s-netperf container image

on:
pull_request:
push:
paths:
- 'containers/Dockerfile' # Trigger only when Dockerfile changes in a pull request
- "containers/**" # Trigger only when Dockerfile changes in a pull request

env:
CONTAINER_REGISTRY: ${{ github.repository_owner == 'cloud-bulldozer' && 'quay.io' }}
RHEL_VERSION: ubi9
CONTAINER_REGISTRY: ${{ 'quay.io' }}
GO_VER: 1.19
RHEL_VERSION: ubi9

jobs:

build-and-push-container-images:
name: Build and Push Container Images
name: Build and Publish Multi Architecture Container Images
runs-on: ubuntu-latest

permissions:
contents: read
packages: write

steps:
- name: Setup QEMU
uses: docker/setup-qemu-action@v2

- name: Setup docker-buildx
uses: docker/setup-buildx-action@v2
with:
buildkitd-flags: --debug
config-inline: |
[worker.oci]
max-parallelism = 1
- name: Checkout
- name: Setup QEMU & Install Dependecies
run: |
sudo apt-get update -y
sudo apt-get install qemu-user-static fuse-overlayfs -y
sudo apt-get install podman -y
if: runner.os == 'Linux'

- name: Clone Repository
uses: actions/checkout@v3

- name: Login to the ${{ env.CONTAINER_REGISTRY }} Container Registry
uses: docker/login-action@v2
- name: Setup Golang
uses: actions/setup-go@v3
with:
registry: ${{ env.CONTAINER_REGISTRY }}
username: ${{ env.CONTAINER_REGISTRY == 'quay.io' && secrets.QUAY_USER || github.actor }}
password: ${{ env.CONTAINER_REGISTRY == 'quay.io' && secrets.QUAY_TOKEN || secrets.GITHUB_TOKEN }
go-version: ${{ env.GO_VER }}

- name: Docker meta
id: meta
uses: docker/metadata-action@v4
- name: Login to the ${{ env.CONTAINER_REGISTRY }} Container Registry
run: podman login quay.io -u ${QUAY_USER} -p ${QUAY_TOKEN}
with:
images: ${{ env.CONTAINER_REGISTRY }}/${{ github.repository_owner }}/netperf
tags: |
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}}.{{minor}}.{{patch}}
QUAY_USER: ${{ secrets.QUAY_USER }}
QUAY_TOKEN: ${{ secrets.QUAY_TOKEN }}

- name: Build and push multi-arch Image
- name: Build and Push multi-arch Image
id: push
uses: docker/build-push-action@v3
with:
file: containers/Dockerfile
platforms: linux/amd64,linux/arm64
tags: ${{ steps.meta.outputs.tags }}
push: ${{ github.event_name != 'pull_request' }}
labels: ${{ steps.meta.outputs.labels }}
build-args: |
RHEL_VERSION=${{ env.RHEL_VERSION }}
GO_VER=${{ env.GO_VER }}
GO_TAGS=
run: |
make gha-build
make gha-push
env:
GO_VER: ${{ env.GO_VER }}
28 changes: 20 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,39 @@
#
# - all (default) - builds all targets
# - build - builds k8s-netperf binary
# - docker-build - builds the container image
# - container-build - builds the container image
# - gha-build - build multi-architecture container image
# - gha-push - Push the image & manifest
# - clean - remove everything under bin/* directory

ARCH=$(shell go env GOARCH)
BIN = k8s-netperf
BIN = k8s-netperf
BIN_DIR = bin
BIN_PATH = $(BIN_DIR)/$(ARCH)/$(BIN)
CGO = 0
RHEL_VERSION = ubi9
DOCKER_BUILD ?= podman build --force-rm
DOCKER_NS ?= perfscale
CONTAINER_BUILD ?= podman build --force-rm
CONTAINER_NS ?= quay.io/cloud-bulldozer/netperf

all: build docker-build
all: build container-build

build: $(BIN_PATH)

docker-build: build
container-build: build
@echo "Building the container image"
$(DOCKER_BUILD) -f containers/Dockerfile \
$(CONTAINER_BUILD) -f containers/Containerfile \
--build-arg RHEL_VERSION=$(RHEL_VERSION) \
-t $(DOCKER_NS)/$(BIN) ./containers
-t $(CONTAINER_NS)/$(BIN) ./containers

gha-build: build
@echo "Building the container image for GHA"
$(CONTAINER_BUILD) -f containers/Containerfile \
--build-arg RHEL_VERSION=$(RHEL_VERSION) --platform=linux/amd64,linux/arm64,linux/ppc64le,linux/s390x \
-t $(CONTAINER_NS) ./containers --manifest=$(CONTAINER_NS):latest

gha-push: gha-build
@echo "Pushing Container Images & manifest"
$(CONTAINER_BUILD) manifest push

clean: $(BIN_PATH)
rm -rf bin/$(ARCH)
Expand Down
File renamed without changes.

0 comments on commit 5e39470

Please sign in to comment.