Skip to content

Commit

Permalink
Build ARM packages without QEMU emulation (#682)
Browse files Browse the repository at this point in the history
This splits the package building and testing logic into x86_64 and arm64
targets, and allows triggering either both, or just one of them.

It also changes the GitHub actions for package testing and release to
no longer use QEMU emulation (which recently started failing with
segfaults), and instead uses separate runners for each architecture.

Further we add an explicit check for cgroups v2. Testing the Amazon Linux 2
package is only supported on a cgroups v1 host, since the container itself
has a too old systemd version to support cgroups v2. Because the ARM
runner is only available on Ubuntu 22.04 or newer (which requires cgroups v2)
we do not test the ARM packages on Amazon Linux 2.

In passing remove stale "DOCKER_BUILDKIT=1" settings from package release
action, which should no longer be needed since GH actions updated their
Docker version, and allow overriding the docker command used with
"DOCKER_CMD", like we already supported for the release step.
  • Loading branch information
lfittl authored Feb 20, 2025
1 parent d3d7a57 commit 5f539e9
Show file tree
Hide file tree
Showing 5 changed files with 236 additions and 87 deletions.
41 changes: 33 additions & 8 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ jobs:
name: pganalyze-collector-linux-arm64
path: pganalyze-collector-linux-arm64

build_packages:
build_packages_x86_64:
# Use older Ubuntu release to ensure availability of CGroupsv1 (which are necessary
# currently to support older systemd on some of the test containers)
runs-on: ubuntu-20.04
Expand All @@ -97,25 +97,50 @@ jobs:
with:
submodules: true

- name: Set up QEMU
uses: docker/setup-qemu-action@v3

- name: Build packages
run: |
DOCKER_BUILDKIT=1 make -C packages build
make -C packages build_x86_64
- name: Test packages
run: |
DOCKER_BUILDKIT=1 make -C packages test
make -C packages test_x86_64
- name: Upload packages as artifacts
uses: actions/upload-artifact@v4
with:
name: packages
path: |
packages/tmp/pganalyze-collector-*.aarch64.rpm
packages/tmp/pganalyze-collector-*.x86_64.rpm
packages/tmp/pganalyze-collector_*_amd64.deb
if-no-files-found: error

build_packages_arm64:
runs-on: ubuntu-22.04-arm
permissions: {}
# ensure we don't release on create events for branches (only tags)
if: ${{ startsWith( github.ref, 'refs/tags' ) }}

steps:

- name: Check out code
uses: actions/checkout@v4
with:
submodules: true

- name: Build packages
run: |
make -C packages build_arm64
- name: Test packages
run: |
make -C packages test_arm64
- name: Upload packages as artifacts
uses: actions/upload-artifact@v4
with:
name: packages
path: |
packages/tmp/pganalyze-collector-*.aarch64.rpm
packages/tmp/pganalyze-collector_*_arm64.deb
if-no-files-found: error

Expand Down Expand Up @@ -145,7 +170,7 @@ jobs:
if-no-files-found: error

release:
needs: [build, build_arm, build_packages, build_charts]
needs: [build, build_arm, build_packages_x86_64, build_packages_arm64, build_charts]
runs-on: ubuntu-latest
# ensure we don't release on create events for branches (only tags)
if: ${{ startsWith( github.ref, 'refs/tags' ) }}
Expand Down
26 changes: 20 additions & 6 deletions .github/workflows/test-packages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ on:
workflow_dispatch:

jobs:
build:
build_x86_64:
# Use older Ubuntu release to ensure availability of CGroupsv1 (which are necessary
# currently to support older systemd on some of the test containers)
runs-on: ubuntu-20.04-4-cores
Expand All @@ -20,15 +20,29 @@ jobs:
with:
submodules: true

- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Build packages
run: |
GIT_VERSION=HEAD VERSION=0.0.0 make -C packages build_x86_64
- name: Test packages
run: |
GIT_VERSION=HEAD VERSION=0.0.0 make -C packages test_x86_64
build_arm64:
runs-on: ubuntu-22.04-arm
permissions: {}

steps:

- name: Check out code
uses: actions/checkout@v4
with:
platforms: arm64
submodules: true

- name: Build packages
run: |
GIT_VERSION=HEAD VERSION=0.0.0 make -C packages build
GIT_VERSION=HEAD VERSION=0.0.0 make -C packages build_arm64
- name: Test packages
run: |
GIT_VERSION=HEAD VERSION=0.0.0 make -C packages test
GIT_VERSION=HEAD VERSION=0.0.0 make -C packages test_arm64
20 changes: 15 additions & 5 deletions packages/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,28 @@ export DEB_PACKAGE_ARM64=$(NAME)_$(VERSION)_arm64.deb

export TMP_DIR=$(shell pwd)/tmp

.PHONY: default setup build test clean repo
.PHONY: default setup build_x86_64 build_arm64 build test_x86_64 test_arm64 test clean repo

default: test repo

setup:
mkdir -p $(TMP_DIR)

build: setup
make -C src
build_x86_64: setup
make -C src x86_64

test: setup build
make -C test
build_arm64: setup
make -C src arm64

build: build_x86_64 build_arm64

test_x86_64: setup build_x86_64
make -C test x86_64

test_arm64: setup build_arm64
make -C test arm64

test: test_x86_64 test_arm64

# Assume the package build and test were run automatically, and use the artifacts from the GitHub release instead of rebuilding
repo: setup
Expand Down
34 changes: 19 additions & 15 deletions packages/src/Makefile
Original file line number Diff line number Diff line change
@@ -1,28 +1,32 @@
# Note: This requires variables that are set in the top-level packages Makefile

BUILD_ARGS=--no-cache --build-arg VERSION=$(VERSION) --build-arg GIT_VERSION=$(GIT_VERSION)
DOCKER_CMD=docker

.PHONY: all
.PHONY: all x86_64 arm64

all: $(TMP_DIR)/$(RPM_PACKAGE_X86_64) $(TMP_DIR)/$(RPM_PACKAGE_ARM64) \
$(TMP_DIR)/$(DEB_PACKAGE_X86_64) $(TMP_DIR)/$(DEB_PACKAGE_ARM64)
all: x86_64 arm64

x86_64: $(TMP_DIR)/$(RPM_PACKAGE_X86_64) $(TMP_DIR)/$(DEB_PACKAGE_X86_64)

arm64: $(TMP_DIR)/$(RPM_PACKAGE_ARM64) $(TMP_DIR)/$(DEB_PACKAGE_ARM64)

$(TMP_DIR)/$(RPM_PACKAGE_X86_64): Dockerfile.build.rpm-systemd
docker build --platform linux/amd64 $(BUILD_ARGS) -f Dockerfile.build.rpm-systemd -t pga-collector-build ../../
docker run --platform linux/amd64 --rm -v $(TMP_DIR):/out pga-collector-build sh -c "cp /root/$(RPM_PACKAGE_X86_64) /out"
docker rmi pga-collector-build
$(DOCKER_CMD) build --platform linux/amd64 $(BUILD_ARGS) -f Dockerfile.build.rpm-systemd -t pga-collector-build ../../
$(DOCKER_CMD) run --platform linux/amd64 --rm -v $(TMP_DIR):/out pga-collector-build sh -c "cp /root/$(RPM_PACKAGE_X86_64) /out"
$(DOCKER_CMD) rmi pga-collector-build

$(TMP_DIR)/$(RPM_PACKAGE_ARM64): Dockerfile.build.rpm-systemd
docker build --platform linux/arm64 $(BUILD_ARGS) -f Dockerfile.build.rpm-systemd -t pga-collector-build ../../
docker run --platform linux/arm64 --rm -v $(TMP_DIR):/out pga-collector-build sh -c "cp /root/$(RPM_PACKAGE_ARM64) /out"
docker rmi pga-collector-build
$(DOCKER_CMD) build --platform linux/arm64 $(BUILD_ARGS) -f Dockerfile.build.rpm-systemd -t pga-collector-build ../../
$(DOCKER_CMD) run --platform linux/arm64 --rm -v $(TMP_DIR):/out pga-collector-build sh -c "cp /root/$(RPM_PACKAGE_ARM64) /out"
$(DOCKER_CMD) rmi pga-collector-build

$(TMP_DIR)/$(DEB_PACKAGE_X86_64): Dockerfile.build.deb-systemd
docker build --platform linux/amd64 $(BUILD_ARGS) -f Dockerfile.build.deb-systemd -t pga-collector-build ../../
docker run --platform linux/amd64 --rm -v $(TMP_DIR):/out pga-collector-build sh -c "cp /root/$(DEB_PACKAGE_X86_64) /out"
docker rmi pga-collector-build
$(DOCKER_CMD) build --platform linux/amd64 $(BUILD_ARGS) -f Dockerfile.build.deb-systemd -t pga-collector-build ../../
$(DOCKER_CMD) run --platform linux/amd64 --rm -v $(TMP_DIR):/out pga-collector-build sh -c "cp /root/$(DEB_PACKAGE_X86_64) /out"
$(DOCKER_CMD) rmi pga-collector-build

$(TMP_DIR)/$(DEB_PACKAGE_ARM64): Dockerfile.build.deb-systemd
docker build --platform linux/arm64 $(BUILD_ARGS) -f Dockerfile.build.deb-systemd -t pga-collector-build ../../
docker run --platform linux/arm64 --rm -v $(TMP_DIR):/out pga-collector-build sh -c "cp /root/$(DEB_PACKAGE_ARM64) /out"
docker rmi pga-collector-build
$(DOCKER_CMD) build --platform linux/arm64 $(BUILD_ARGS) -f Dockerfile.build.deb-systemd -t pga-collector-build ../../
$(DOCKER_CMD) run --platform linux/arm64 --rm -v $(TMP_DIR):/out pga-collector-build sh -c "cp /root/$(DEB_PACKAGE_ARM64) /out"
$(DOCKER_CMD) rmi pga-collector-build
Loading

0 comments on commit 5f539e9

Please sign in to comment.