Skip to content

Commit bfe7cd1

Browse files
committed
workflows: build within emulated container
Use QEMU to build samba-operator within containerized environment; either AMD64 or ARM64 architectures (regardless of local host architecture). Using this method we can ensures that all build tools are properly configured on architectures other than default x86_64, without relaying on specific hardware. Signed-off-by: Shachar Sharon <[email protected]>
1 parent 70df8a1 commit bfe7cd1

File tree

3 files changed

+71
-0
lines changed

3 files changed

+71
-0
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
name: Build within container
2+
on:
3+
push:
4+
branches: [master]
5+
pull_request:
6+
branches: [master]
7+
jobs:
8+
build-within-container:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- name: Checkout
12+
uses: actions/checkout@v3
13+
- name: Enable emulation
14+
run: |
15+
sudo apt-get update
16+
sudo apt-get install -y qemu qemu-user-static
17+
sudo update-binfmts --display
18+
- name: Require build utilities
19+
run: |
20+
command -v podman
21+
command -v qemu-x86_64-static
22+
command -v qemu-aarch64-static
23+
- name: Build within AMD64 container
24+
run: hack/build-within-container.sh amd64
25+
- name: Build within ARM64 container
26+
run: hack/build-within-container.sh arm64

hack/Dockerfile.build

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
FROM centos:stream9
2+
WORKDIR /workspace
3+
RUN dnf install -y epel-release epel-next-release
4+
RUN dnf install -y gcc tar golang wget make yamllint
5+
COPY samba-operator.tar.gz .
6+
RUN tar xvfz samba-operator.tar.gz
7+
RUN go version
8+
RUN make

hack/build-within-container.sh

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#!/usr/bin/env bash
2+
export LC_ALL=C
3+
unset CDPATH
4+
ARCH=${1:-amd64}
5+
6+
# Currently, aupport amd64 (x86_64) and arm64 (aarch64) architectures
7+
case "${ARCH}" in "amd64") ;; "arm64") ;; \
8+
*) echo "illegal ${ARCH}" && exit 1 ;; esac
9+
10+
# Prerequisites checks
11+
_require_command() {
12+
command -v "$1" > /dev/null || (echo "missing: $1" && exit 1)
13+
}
14+
15+
_require_command realpath
16+
_require_command git
17+
_require_command podman
18+
_require_command qemu-x86_64-static
19+
_require_command qemu-aarch64-static
20+
21+
# Fail on error
22+
set -o errexit
23+
set -o nounset
24+
set -o pipefail
25+
26+
# Create tar-ball using git
27+
BASEDIR=$(realpath "$(dirname "${BASH_SOURCE[0]}")/../")
28+
cd "${BASEDIR}"
29+
git archive --format tar.gz HEAD > hack/samba-operator.tar.gz
30+
function cleanup_on_exit() { rm -f hack/samba-operator.tar.gz; }
31+
trap cleanup_on_exit EXIT
32+
33+
# Build within container using podman
34+
podman build \
35+
--arch=${ARCH} \
36+
--tag localhost/samba-operator-build:${ARCH} \
37+
--file hack/Dockerfile.build

0 commit comments

Comments
 (0)