Skip to content

Commit

Permalink
Improvements on the multi-arch container build pipeline
Browse files Browse the repository at this point in the history
Signed-off-by: Raul Sevilla <rsevilla@redhat.com>
  • Loading branch information
rsevilla87 committed Nov 21, 2022
1 parent 7d38bdb commit decbcd8
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 74 deletions.
46 changes: 1 addition & 45 deletions .github/workflows/containers.yml
Expand Up @@ -11,55 +11,11 @@ jobs:
containers:
name: Build container images
runs-on: ubuntu-latest
strategy:
matrix:
arch:
- arm64
- amd64
- ppc64le
- s390x

steps:

- name: Install dependencies required for multi-arch builds
run: sudo apt-get update && sudo apt-get install qemu-user-static podman fuse-overlayfs

- name: Check out code into the Go module directory
uses: actions/checkout@v3

- name: Set up Go 1.18
uses: actions/setup-go@v3
with:
go-version: 1.18
id: go

- name: Login in quay
run: podman login quay.io -u ${QUAY_USER} -p ${QUAY_TOKEN}
env:
QUAY_USER: ${{ secrets.QUAY_USER }}
QUAY_TOKEN: ${{ secrets.QUAY_TOKEN }}

- name: Build kube-burner binary
run: make build
env:
ARCH: ${{ matrix.arch }}

- name: Build container image
run: make images
env:
ARCH: ${{ matrix.arch }}

- name: Push container image
run: make push
env:
ARCH: ${{ matrix.arch }}

manifest:
name: Build container manifest
runs-on: ubuntu-latest
needs: containers
steps:

- name: Check out code into the Go module directory
uses: actions/checkout@v3

Expand All @@ -69,5 +25,5 @@ jobs:
QUAY_USER: ${{ secrets.QUAY_USER }}
QUAY_TOKEN: ${{ secrets.QUAY_TOKEN }}

- name: Create and push manifest
- name: Build & push container images
run: make manifest
2 changes: 1 addition & 1 deletion .github/workflows/kube-burner.yml
Expand Up @@ -33,7 +33,7 @@ jobs:
run: make build

- name: Build container images
run: make images
run: make image
env:
VERSION: snapshot

Expand Down
8 changes: 6 additions & 2 deletions Containerfile
@@ -1,6 +1,10 @@
FROM registry.fedoraproject.org/fedora-minimal:latest as builder
COPY . /kube-burner
RUN microdnf install -y golang make
RUN make -C kube-burner build

FROM registry.fedoraproject.org/fedora-minimal:latest
RUN microdnf install rsync -y && rm -Rf /var/cache/yum
COPY kube-burner /bin/kube-burner
COPY --from=builder kube-burner/bin/kube-burner /bin/kube-burner
LABEL io.k8s.display-name="kube-burner" \
maintainer="Raul Sevilla <rsevilla@redhat.com"
ENTRYPOINT ["/bin/kube-burner"]
44 changes: 18 additions & 26 deletions Makefile
@@ -1,11 +1,11 @@

.PHONY: build clean test help images push manifest manifest-build
.PHONY: build clean test help image container push manifest


ARCH ?= amd64
PLATFORMS ?= linux/amd64,linux/arm64,linux/ppc64le,linux/s390x
BIN_NAME = kube-burner
BIN_DIR = bin
BIN_PATH = $(BIN_DIR)/$(ARCH)/$(BIN_NAME)
BIN_PATH = $(BIN_DIR)/$(BIN_NAME)
CGO = 0

GIT_COMMIT = $(shell git rev-parse HEAD)
Expand All @@ -19,20 +19,19 @@ ENGINE ?= podman
REGISTRY = quay.io
ORG ?= cloud-bulldozer
CONTAINER_NAME = $(REGISTRY)/$(ORG)/kube-burner:$(VERSION)
CONTAINER_NAME_ARCH = $(REGISTRY)/$(ORG)/kube-burner:$(VERSION)-$(ARCH)
MANIFEST_ARCHS ?= amd64 arm64 ppc64le s390x

all: lint build images push
all: lint build
image: container push

help:
@echo "Commands for $(BIN_PATH):"
@echo
@echo 'Usage:'
@echo ' make clean Clean the compiled binaries'
@echo ' [ARCH=arch] make build Compile the project for arch, default amd64'
@echo ' [ARCH=arch] make install Installs kube-burner binary in the system, default amd64'
@echo ' [ARCH=arch] make images Build images for arch, default amd64'
@echo ' [ARCH=arch] make push Push images for arch, default amd64'
@echo ' make build Compile the project for arch, default amd64'
@echo ' make install Installs kube-burner binary in the system, default amd64'
@echo ' make images Build images for arch, default amd64'
@echo ' make push Push images for arch, default amd64'
@echo ' make manifest Create and push manifest for the different architectures supported'
@echo ' make help Show this message'

Expand All @@ -41,7 +40,7 @@ build: $(BIN_PATH)
$(BIN_PATH): $(SOURCES)
@echo -e "\033[2mBuilding $(BIN_PATH)\033[0m"
@echo "GOPATH=$(GOPATH)"
GOARCH=$(ARCH) CGO_ENABLED=$(CGO) go build -v -mod vendor -ldflags "-X $(KUBE_BURNER_VERSION).GitCommit=$(GIT_COMMIT) -X $(KUBE_BURNER_VERSION).BuildDate=$(BUILD_DATE) -X $(KUBE_BURNER_VERSION).Version=$(VERSION)" -o $(BIN_PATH) ./cmd/kube-burner
CGO_ENABLED=$(CGO) go build -v -mod vendor -ldflags "-X $(KUBE_BURNER_VERSION).GitCommit=$(GIT_COMMIT) -X $(KUBE_BURNER_VERSION).BuildDate=$(BUILD_DATE) -X $(KUBE_BURNER_VERSION).Version=$(VERSION)" -o $(BIN_PATH) ./cmd/kube-burner

lint:
golangci-lint run
Expand All @@ -59,22 +58,15 @@ deps-update:
install:
cp $(BIN_PATH) /usr/bin/$(BIN_NAME)

images:
@echo -e "\n\033[2mBuilding container $(CONTAINER_NAME_ARCH)\033[0m"
$(ENGINE) build --arch=$(ARCH) -f Containerfile $(BIN_DIR)/$(ARCH)/ -t $(CONTAINER_NAME_ARCH)
container:
@echo -e "\n\033[2mBuilding container $(CONTAINER_NAME)\033[0m"
$(ENGINE) build -f Containerfile . -t=$(CONTAINER_NAME)

push:
@echo -e "\033[2mPushing container $(CONTAINER_NAME_ARCH)\033[0m"
$(ENGINE) push $(CONTAINER_NAME_ARCH)
@echo -e "\033[2mPushing container $(CONTAINER_NAME)\033[0m"
$(ENGINE) push $(CONTAINER_NAME)

manifest: manifest-build
@echo -e "\033[2mPushing container manifest $(CONTAINER_NAME)\033[0m"
$(ENGINE) manifest push $(CONTAINER_NAME) $(CONTAINER_NAME)

manifest-build:
manifest:
@echo -e "\033[2mCreating container manifest $(CONTAINER_NAME)\033[0m"
$(ENGINE) manifest create $(CONTAINER_NAME)
for arch in $(MANIFEST_ARCHS); do \
$(ENGINE) manifest add $(CONTAINER_NAME) $(CONTAINER_NAME)-$${arch}; \
done

$(ENGINE) build --platform=$(PLATFORMS) -f Containerfile --manifest=$(CONTAINER_NAME)
$(ENGINE) manifest push $(CONTAINER_NAME) $(CONTAINER_NAME)

0 comments on commit decbcd8

Please sign in to comment.