From b2cfd60e871a5933e72ba60109930c2923b2e2ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Lucas?= Date: Mon, 24 Oct 2022 10:25:45 +0100 Subject: [PATCH] Hack a multi-arch image build using buildah. README updated accordingly. --- Makefile | 40 ++++++++++++++++++++++++++++++++++++++++ README.md | 18 +++++++++++++++++- 2 files changed, 57 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index f7b17a3..cf5b7cd 100644 --- a/Makefile +++ b/Makefile @@ -2,6 +2,8 @@ IMAGE ?= storageos/init:test GO_BUILD_CMD = go build -v GO_ENV = GOOS=linux CGO_ENABLED=0 +MPIMAGE ?= docker.io/soegarots/mpinit:latest + # Test node image name. NODE_IMAGE ?= storageos/node:1.4.0 # Test scripts path. @@ -27,6 +29,44 @@ docker-build: docker-push: docker push ${IMAGE} +SUDO = sudo +BUILDAH = $(SUDO) buildah +PODMAN = $(SUDO) podman + +BUILD_DEPS = + +BUILD_ARGS_COMMON = +BUILD_ARGS_ARM64 = $(BUILD_ARGS_COMMON) +BUILD_ARGS_AMD64 = $(BUILD_ARGS_COMMON) + +BUILDAH_MANIFEST = mpbuild-init +BUILDAH_URI = docker://$(MPIMAGE) + +mpbuild: mpbuild-prep mpbuild-amd64 mpbuild-arm64 + +mprelease: mpbuild-finalise + +mpbuild-prep: + $(BUILDAH) manifest rm $(BUILDAH_MANIFEST) || true + $(BUILDAH) manifest create $(BUILDAH_MANIFEST) + +mpbuild-amd64: $(BUILD_DEPS) + $(BUILDAH) build --tag $(MPIMAGE) $(BUILD_ARGS_AMD64) --manifest $(BUILDAH_MANIFEST) --arch amd64 . + +mpbuild-arm64: $(BUILD_DEPS) + $(BUILDAH) build --tag $(MPIMAGE) $(BUILD_ARGS_ARM64) --manifest $(BUILDAH_MANIFEST) --arch arm64 . + +mpbuild-finalise: + $(BUILDAH) manifest push --all $(BUILDAH_MANIFEST) $(BUILDAH_URI) + + +cache-build-amd64: $(BUILD_DEPS) + $(PODMAN) build --arch amd64 $(BUILD_ARGS_AMD64) -t deleteme:latest . + +cache-build-arm64: $(BUILD_DEPS) + $(PODMAN) build --arch arm64 $(BUILD_ARGS_ARM64) -t deleteme:latest . + + # Run tests test: generate fmt vet go test -v -race `go list -v ./...` diff --git a/README.md b/README.md index c676e56..c3cae29 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Init Container for StorageOS -[![Test and build image](https://github.com/storageos/init/workflows/Test%20and%20build%20image/badge.svg)](https://github.com/storageos/init/actions?query=workflow%3A%22Test+and+build+image%22) [![Build Status](https://travis-ci.com/storageos/init.svg?branch=master)](https://travis-ci.com/storageos/init) +[![Test and build image](https://github.com/storageos/init/workflows/Test%20and%20build%20image/badge.svg)](https://github.com/storageos/init/actions?query=workflow%3A%22Test+and+build+image%22) [![Build Status](https://travis-ci.com/storageos/init.svg?branch=master)](https://travis-ci.com/storageos/init) Init container to prepare the environment for StorageOS. @@ -37,6 +37,22 @@ The version must be set in the `Dockerfile`. To set it, run: NEW_VERSION= make release ``` +## HACK: multi-arch build and release + +This will push `docker.io/soegarots/mpinit:latest` to Docker Hub. Change the image and tag using the Makefile variable `MPIMAGE`. If you don't have write access on Docker Hub, it will build but won't push. + +```sh +$ sudo podman login --username MY-DOCKER_HUB_USERNAME +... + +$ make mpbuild +... + +$ make mprelease +... + +``` + ## Run it on host Build the init container with `make docker-build` and run it on the host with