Skip to content

Commit

Permalink
Add multiarch container builds
Browse files Browse the repository at this point in the history
  • Loading branch information
brancz committed Feb 28, 2022
1 parent 9d37ad7 commit cd53dc6
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 4 deletions.
6 changes: 6 additions & 0 deletions .github/workflows/container.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ jobs:
shell: bash
run: echo "GITHUB_BRANCH_NAME=$(echo ${GITHUB_REF#refs/heads/} | tr / -)" >> $GITHUB_ENV

# To build multi-arch images, see also: https://github.com/redhat-actions/buildah-build#multi-arch-builds
- name: Install qemu dependency
run: |
sudo apt-get update
sudo apt-get install -y qemu-user-static
- name: Build container
run: make container

Expand Down
6 changes: 6 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,14 @@ RUN apt-get -o Acquire::Check-Valid-Until="false" update -y && \
apt-get install --no-install-recommends -y clang-11 llvm-11 make gcc coreutils elfutils binutils zlib1g-dev libelf-dev ca-certificates netbase && \
ln -s /usr/bin/clang-11 /usr/bin/clang && \
ln -s /usr/bin/llc-11 /usr/bin/llc

WORKDIR /parca-agent

ARG ARCH=amd64
ENV GOOS=linux
ENV ARCH=$ARCH
ENV GOARCH=$ARCH

COPY go.mod go.sum /parca-agent/
RUN go mod download -modcacherw

Expand Down
23 changes: 19 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ all: bpf build

SHELL := /bin/bash

ALL_ARCH ?= amd64 arm64

# tools:
CMD_LLC ?= llc
CMD_CLANG ?= clang
Expand All @@ -11,7 +13,19 @@ CMD_GIT ?= git
CMD_EMBEDMD ?= embedmd
# environment:
ARCH_UNAME := $(shell uname -m)
ARCH ?= $(ARCH_UNAME:aarch64=arm64)

ifeq ($(ARCH_UNAME), x86_64)
ARCH ?= amd64
else
ARCH ?= arm64
endif

ifeq ($(ARCH), amd64)
LINUX_ARCH ?= x86_64=x86
else
LINUX_ARCH ?= aarch64=arm64
endif

KERN_RELEASE ?= $(shell uname -r)
KERN_BLD_PATH ?= $(if $(KERN_HEADERS),$(KERN_HEADERS),/lib/modules/$(KERN_RELEASE)/build)
KERN_SRC_PATH ?= $(if $(KERN_HEADERS),$(KERN_HEADERS),$(if $(wildcard /lib/modules/$(KERN_RELEASE)/source),/lib/modules/$(KERN_RELEASE)/source,$(KERN_BLD_PATH)))
Expand Down Expand Up @@ -103,15 +117,14 @@ $(BPF_BUNDLE): $(BPF_SRC) $(LIBBPF_HEADERS)/bpf $(BPF_HEADERS)
.PHONY: bpf
bpf: $(OUT_BPF)

linux_arch := $(ARCH:x86_64=x86)
ifndef DOCKER
$(OUT_BPF): $(BPF_SRC) $(LIBBPF_HEADERS) $(LIBBPF_OBJ) | $(OUT_DIR) $(bpf_compile_tools)
mkdir -p $(OUT_BPF_DIR)
@v=$$($(CMD_CLANG) --version); test $$(echo $${v#*version} | head -n1 | cut -d '.' -f1) -ge '9' || (echo 'required minimum clang version: 9' ; false)
$(CMD_CLANG) -S \
-D__BPF_TRACING__ \
-D__KERNEL__ \
-D__TARGET_ARCH_$(linux_arch) \
-D__TARGET_ARCH_$(LINUX_ARCH) \
-I $(LIBBPF_HEADERS)/bpf \
-I $(BPF_HEADERS) \
-Wno-address-of-packed-member \
Expand Down Expand Up @@ -192,7 +205,9 @@ check_%:

.PHONY: container
container:
buildah build-using-dockerfile --timestamp 0 --layers -t $(OUT_DOCKER):$(VERSION)
for arch in $(ALL_ARCH); do \
buildah build-using-dockerfile --build-arg ARCH=$$arch --arch $$arch --timestamp 0 --manifest -t $(OUT_DOCKER):$(VERSION); \
done

.PHONY: push-container
push-container:
Expand Down

0 comments on commit cd53dc6

Please sign in to comment.