Tidbits – Terraform and Multiarch

Here is a compendium of tidbits from the week:

FYI: Terraform v1.5.0 is released. It’s probably worth updating. link to ppc64le build

❯ brew upgrade terraform

There are new features:

check blocks for validating infrastructure: Module and configuration authors can now write independent check blocks within their configuration to validate assertions about their infrastructure. Adds a new strcontains function that checks whether a given string contains a given substring. (#33069)

https://github.com/hashicorp/terraform/releases/tag/v1.5.0

Blog: Build multi-architecture container images on GitHub Actions using native nodes

My colleague, Yussuf, has posted a blog on using GitHub actions with Native Nodes. It’s to the point, and super helpful. link

There are already a few good blogs[1][2][3] available in this group that demonstrates how to build multi-arch container images on GitHub Actions using Buildx. However, they are using QEMU which is a free and open-source emulator for running cross-builds. Using QEMU presents its own problems where the main point is the slowness which cannot match when we run the builds natively. Even there is no guarantee that the build will always succeed when we use low-level code in the project. These pain points forced us to use native nodes as part of the same Buildx workflow inside a GitHub Action. If you as well want to use native nodes to build your projects on multiple architectures including ppc64le then this article is for you.

https://community.ibm.com/community/user/powerdeveloper/blogs/yussuf-shaikh/2023/06/14/workflow-using-buildx-remote-builders

Tip: Custom Build of QEMU on Centos 9

I had to do a cross-build of ARM64, so I used QEMU. It’s not necessarily straight-forward on CENTOS9, here are the steps I took:

  1. Connect to my machine.
❯ ssh cloud-user@<machine IP>
  1. Switch to Root
❯ sudo -s 
  1. Enable the Code Ready Builders repo
❯ dnf config-manager --set-enabled crb
  1. install a bunch of dependencies
❯ dnf install -y git make pip vim ninja-build gcc glib2-devel.x86_64 pixman.x86_64 libjpeg-devel giflib-devel pixman-devel cairo-devel pango-devel qemu-kvm edk2-aarch64
  1. Install Python dependencies
❯ pip install Sphinx sphinx-rtd-theme
  1. Pull the Qemu Code
❯ git clone https://git.qemu.org/git/qemu.git
  1. Change to QEMU
❯ cd qemu
  1. Apply the patch
From 14920d35f053c8effd17a232b5144ef43465a85e Mon Sep 17 00:00:00 2001
From: root <root@cross-build-pbastide.novalocal>
Date: Tue, 20 Jun 2023 10:02:39 -0400
Subject: [PATCH] test

---
 configure | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/configure b/configure
index 01a53576a7..02cabb556b 100755
--- a/configure
+++ b/configure
@@ -371,6 +371,7 @@ else
   # be the result of a missing compiler.
   targetos=bogus
 fi
+targetos=linux
 
 # OS specific
 
@@ -508,7 +509,7 @@ case "$cpu" in
   sparc64)
     CPU_CFLAGS="-m64 -mcpu=ultrasparc" ;;
 esac
-
+CPU_CFLAGS="-m64 -mcx16"
 check_py_version() {
     # We require python >= 3.7.
     # NB: a True python conditional creates a non-zero return code (Failure)
-- 

The above patch is generated from git format-patch -1 HEAD.

  1. Create the build directory
❯ mkdir -p build
  1. Configure the qemu build
❯ ./configure --target-list=aarch64-softmmu --enable-virtfs --enable-slirp
  1. Build with all your processors.
❯ make -j`nproc`
  1. The file should exist and be in your native architecture.
❯ file ./build/qemu-system-aarch64
./build/qemu-system-aarch64: ELF 64-bit LSB pie executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, BuildID[sha1]=1871423864de4428c4721b8e805304f0142bed6a, for GNU/Linux 3.2.0, with debug_info, not stripped
  1. Download Centos qcow2 from link
❯ curl -O https://cloud.centos.org/centos/9-stream/aarch64/images/CentOS-Stream-GenericCloud-9-20220621.1.aarch64.qcow2
  1. Update the .ssh/authorized_keys
modprobe nbd
qemu-nbd -c /dev/nbd0 CentOS-Stream-GenericCloud-9-20220621.1.aarch64.qcow2
mount /dev/nbd0p1 /mnt
mkdir -p /mnt/root/.ssh/
  1. Edit the keys to add your public key.
vim /mnt/root/.ssh/authorized_keys
  1. Unmount the qcow2 mount
umount /mnt
qemu-nbd -d /dev/nbd0
  1. Start the QEMU vm.
build/qemu-system-aarch64 -m 4G -M virt -cpu cortex-a57 \
  -bios /usr/share/edk2/aarch64/QEMU_EFI.fd \
  -drive if=none,file=CentOS-Stream-GenericCloud-9-20220621.1.aarch64.qcow2,id=hd0 \
  -device virtio-blk-device,drive=hd0 \
  -device e1000,netdev=net0 -netdev user,id=net0,hostfwd=tcp:127.0.0.1:5555-:22 \
  -nographic

Finally, you’ll see:

CentOS Stream 9
Kernel 5.14.0-115.el9.aarch64 on an aarch64

Activate the web console with: systemctl enable --now cockpit.socket

cross-build-pbastide login: 

It’s ready-to-go.

References
  1. http://cdn.kernel.org/pub/linux/kernel/people/will/docs/qemu/qemu-arm64-howto.html
  2. https://fedoraproject.org/wiki/Architectures/AArch64/Install_with_QEMU
  3. https://wiki-archive.linaro.org/LEG/UEFIforQEMU
  4. https://packages.debian.org/experimental/qemu-efi-aarch64
  5. https://www.redhat.com/sysadmin/install-epel-linux
  6. https://wiki.qemu.org/Hosts/Linux
  7. https://github.com/Automattic/node-canvas/issues/1065#issuecomment-1278496824
  8. https://wiki.debian.org/Arm64Qemu

Posted

in

by

Tags:

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.