diff --git a/.github/workflows/build-container.yml b/.github/workflows/build-container.yml index 0b7f8d8a..5261a1e2 100644 --- a/.github/workflows/build-container.yml +++ b/.github/workflows/build-container.yml @@ -1,19 +1,18 @@ 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: @@ -21,47 +20,31 @@ jobs: 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= \ No newline at end of file + run: | + make gha-build + make gha-push + env: + GO_VER: ${{ env.GO_VER }} \ No newline at end of file diff --git a/Makefile b/Makefile index a7536e14..0964b6fe 100644 --- a/Makefile +++ b/Makefile @@ -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) diff --git a/containers/Dockerfile b/containers/Containerfile similarity index 100% rename from containers/Dockerfile rename to containers/Containerfile