Skip to content

Commit

Permalink
Merge pull request #358 from OlivierCazade/stage-multiarch
Browse files Browse the repository at this point in the history
Updated Dockefile for crosscompilation compatibility
  • Loading branch information
OlivierCazade authored Jan 10, 2023
2 parents 6a8b986 + f407424 commit 30d42fd
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 15 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/pull_request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
strategy:
matrix:
go: ['1.18']

steps:
- name: install make
run: sudo apt-get install make
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ jobs:
with:
go-version: ${{ matrix.go }}
- name: build images
run: DOCKER_TAG=${{ steps.validate_tag.outputs.tag }} make build-image
run: DOCKER_TAG=${{ steps.validate_tag.outputs.tag }} make build-image-multiarch
- name: podman login to quay.io
uses: redhat-actions/podman-login@v1
with:
Expand Down
32 changes: 28 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ export GOFLAGS=-mod=vendor
export GO111MODULE=on
export CGO_ENABLED=0
export GOOS=linux
export GOARCH=amd64

SHELL := /bin/bash
GOARCH ?= amd64

SHELL := /usr/bin/env bash
DOCKER_TAG ?= latest
DOCKER_IMG ?= quay.io/netobserv/flowlogs-pipeline
OCI_RUNTIME ?= $(shell which podman || which docker)
Expand Down Expand Up @@ -69,8 +70,8 @@ lint: $(GOLANGCI_LINT) ## Lint the code

.PHONY: build_code
build_code:
go build -ldflags "-X 'main.BuildVersion=$(BUILD_VERSION)' -X 'main.BuildDate=$(BUILD_DATE)'" "${CMD_DIR}${FLP_BIN_FILE}"
go build -ldflags "-X 'main.BuildVersion=$(BUILD_VERSION)' -X 'main.BuildDate=$(BUILD_DATE)'" "${CMD_DIR}${CG_BIN_FILE}"
GOARCH=${GOARCH} go build -ldflags "-X 'main.BuildVersion=$(BUILD_VERSION)' -X 'main.BuildDate=$(BUILD_DATE)'" "${CMD_DIR}${FLP_BIN_FILE}"
GOARCH=${GOARCH} go build -ldflags "-X 'main.BuildVersion=$(BUILD_VERSION)' -X 'main.BuildDate=$(BUILD_DATE)'" "${CMD_DIR}${CG_BIN_FILE}"

.PHONY: build
build: validate_go lint build_code docs ## Build flowlogs-pipeline executable and update the docs
Expand Down Expand Up @@ -129,6 +130,29 @@ run: build ## Run
build-image:
DOCKER_BUILDKIT=1 $(OCI_RUNTIME) build -t $(DOCKER_IMG):$(DOCKER_TAG) -f contrib/docker/Dockerfile .

build-image-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/%:
DOCKER_BUILDKIT=1 $(OCI_RUNTIME) push $(DOCKER_IMG):$(DOCKER_TAG)-$*


.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
@echo 'publish manifest $(DOCKER_TAG) to $(DOCKER_IMG)'
ifeq ($(shell basename $(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)
endif


.PHONY: build-ci-images
build-ci-images:
ifeq ($(DOCKER_TAG), main)
Expand Down
16 changes: 8 additions & 8 deletions contrib/docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
FROM docker.io/library/golang:1.18 as builder
# We do not use --platform feature to auto fill this ARG because of incompatibility between podman and docker
ARG TARGETPLATFORM=linux/amd64
ARG BUILDPLATFORM=linux/amd64
FROM --platform=$BUILDPLATFORM docker.io/library/golang:1.18 as builder

ARG TARGETPLATFORM
ARG TARGETARCH=amd64
WORKDIR /app

# Copy source code
Expand All @@ -13,15 +18,10 @@ COPY cmd/ cmd/
COPY pkg/ pkg/

RUN git status --porcelain
RUN make build_code
RUN GOARCH=$TARGETARCH make build_code

# final stage
FROM registry.access.redhat.com/ubi8/ubi-minimal:8.7
RUN microdnf install -y \
iputils \
curl \
net-tools \
&& microdnf -y clean all && rm -rf /var/cache
FROM --platform=$TARGETPLATFORM registry.access.redhat.com/ubi8/ubi-minimal:8.7

COPY --from=builder /app/flowlogs-pipeline /app/
COPY --from=builder /app/confgenerator /app/
Expand Down
2 changes: 1 addition & 1 deletion hack/update-docs.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash
#!/usr/bin/env bash

set -eou pipefail

Expand Down

0 comments on commit 30d42fd

Please sign in to comment.