Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

workflows: build within emulated container #276

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions .github/workflows/build-within-container.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: Build within container
on:
push:
branches: [master]
pull_request:
branches: [master]
jobs:
build-within-container:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Enable emulation
run: |
sudo apt-get update
sudo apt-get install -y qemu qemu-user-static
sudo update-binfmts --display
- name: Require build utilities
run: |
command -v podman
command -v qemu-x86_64-static
command -v qemu-aarch64-static
- name: Build within AMD64 container
run: hack/build-within-container.sh amd64
- name: Build within ARM64 container
run: hack/build-within-container.sh arm64
8 changes: 8 additions & 0 deletions hack/Dockerfile.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
FROM centos:stream9
WORKDIR /workspace
RUN dnf install -y epel-release epel-next-release
RUN dnf install -y gcc tar golang wget make yamllint
COPY samba-operator.tar.gz .
RUN tar xvfz samba-operator.tar.gz
RUN go version
RUN make
37 changes: 37 additions & 0 deletions hack/build-within-container.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/usr/bin/env bash
export LC_ALL=C
unset CDPATH
ARCH=${1:-amd64}

# Currently, aupport amd64 (x86_64) and arm64 (aarch64) architectures
case "${ARCH}" in "amd64") ;; "arm64") ;; \
*) echo "illegal ${ARCH}" && exit 1 ;; esac

# Prerequisites checks
_require_command() {
command -v "$1" > /dev/null || (echo "missing: $1" && exit 1)
}

_require_command realpath
_require_command git
_require_command podman
_require_command qemu-x86_64-static
_require_command qemu-aarch64-static

# Fail on error
set -o errexit
set -o nounset
set -o pipefail

# Create tar-ball using git
BASEDIR=$(realpath "$(dirname "${BASH_SOURCE[0]}")/../")
cd "${BASEDIR}"
git archive --format tar.gz HEAD > hack/samba-operator.tar.gz
function cleanup_on_exit() { rm -f hack/samba-operator.tar.gz; }
trap cleanup_on_exit EXIT

# Build within container using podman
podman build \
--arch=${ARCH} \
--tag localhost/samba-operator-build:${ARCH} \
--file hack/Dockerfile.build