Add kselftest-builder container for x86 and ARM64

Kernel's sefltest depends on a number of userland libraries
COS does not provide. For this reason Ubuntu is used as a base
image and should be used as a run-time test userland.

kselftest also does not fully support cross-compilation so
the builder needs ARM64 version that can be used with linuxkit/binfmt
on x86 worker VM.

Change-Id: I00dccad76ec83d12ffb601850e2e48f801ab7bc5
Reviewed-by: Oleksandr Tymoshenko <>
Reviewed-by: Arnav Kansal <>
Tested-by: Oleksandr Tymoshenko <>
Cloud-Build: GCB Service account <>
diff --git a/src/cmd/kselftest_builder/Dockerfile b/src/cmd/kselftest_builder/Dockerfile
new file mode 100644
index 0000000..2f9983b
--- /dev/null
+++ b/src/cmd/kselftest_builder/Dockerfile
@@ -0,0 +1,11 @@
+FROM ubuntu:22.04
+RUN set -x; apt-get -y update && \
+	apt-get -y install apt-transport-https ca-certificates && \
+	DEBIAN_FRONTEND=noninteractive TZ=Etc/UTC apt-get install -y tzdata && \
+	apt-get install -y make python3 git libssl-dev bc bison flex cpio kmod \
+	    dwarves xz-utils libelf-dev rsync clang llvm g++ libmnl-dev \
+	    libmount-dev libcap-ng-dev libcap-dev libelf-dev \
+	    libfuse-dev libpopt-dev libnuma-dev docutils-common && \
+	if [ "$(uname -m)" = "x86_64" ]; then apt-get -y install gcc-multilib libc6-i386 libc6-dev-i386; fi && \
+	apt-get clean
diff --git a/src/cmd/kselftest_builder/cloudbuild.yaml b/src/cmd/kselftest_builder/cloudbuild.yaml
new file mode 100644
index 0000000..88eb3b6
--- /dev/null
+++ b/src/cmd/kselftest_builder/cloudbuild.yaml
@@ -0,0 +1,25 @@
+  env:
+# Build toolbox image
+# This step is needed to add a new entry to /proc/sys/fs/binfmt_misc. Docker
+# uses QEMU user emulation to run arm64 programs on x86 hosts. A QEMU
+# interpreter needs to be added to /proc/sys/fs/binfmt_misc to run arm64
+# programs.
+- name: ''
+  args: ['run', '--privileged', 'linuxkit/binfmt:a17941b47f5cb262638cfb49ffc59ac5ac2bf334-amd64']
+# The default builder (which appears to be the Docker daemon that implements
+# the old, familiar `docker build` behavior) doesn't support the --platform
+# flag, so we need to create a new builder.
+- name: ''
+  args: ['buildx', 'create', '--name', 'builder']
+- name: ''
+  args: ['buildx', 'use', 'builder']
+# Images produced in this way do not appear in the Docker image registry shown
+# by `docker images`, at least by default. We use the --push flag to push the
+# image after building it, because a subsequent `docker push` won't find the
+# image locally.
+- name: ''
+  args: ['buildx', 'build', '--platform', 'linux/amd64,linux/arm64', '-f', 'src/cmd/kselftest_builder/Dockerfile', '-t', '${_OUTPUT_PROJECT}/kselftest-builder:latest', '-t', '${_OUTPUT_PROJECT}/kselftest-builder:${TAG_NAME}', '--push', 'src/cmd/kselftest_builder']
+timeout: 1800s