Initial commit

This commit is contained in:
exu 2023-07-28 17:04:56 +02:00
commit ad4d73c503
5 changed files with 104 additions and 0 deletions

4
README.md Normal file
View File

@ -0,0 +1,4 @@
Example for single build
`buildah build -f builder-x86.dockerfile -t builderx86:latest`
Build all containers and push by executing `create-containers.sh`

18
builder-arm.dockerfile Normal file
View File

@ -0,0 +1,18 @@
FROM docker.io/menci/archlinuxarm:base-devel
# install dependencies
RUN pacman -Syu --noconfirm \
sudo \
git
# allow sudo for all users
RUN echo '%wheel ALL=(ALL) NOPASSWD: ALL' > /etc/sudoers.d/wheel
# add builder user
RUN useradd builder -s /bin/bash -G wheel
# copy builder script
COPY --chmod=755 builder.sh /
# execute builder script
ENTRYPOINT [ "/builder.sh" ]

18
builder-x86.dockerfile Normal file
View File

@ -0,0 +1,18 @@
FROM docker.io/archlinux:base-devel
# install dependencies
RUN pacman -Syu --noconfirm \
sudo \
git
# allow sudo for all users
RUN echo '%wheel ALL=(ALL) NOPASSWD: ALL' > /etc/sudoers.d/wheel
# add builder user
RUN useradd builder -s /bin/bash -G wheel
# copy builder script
COPY --chmod=755 builder.sh /
# execute builder script
ENTRYPOINT [ "/builder.sh" ]

30
builder.sh Executable file
View File

@ -0,0 +1,30 @@
#!/usr/bin/env sh
set -euo pipefail
# check if one argument is present
if [ "$#" -ne 1 ]; then
echo "Pass the AUR package name you want to build"
exit 1
fi
# relaunch script as builder user
if [ "$(whoami)" != "builder" ]; then
sudo -u builder bash "$0" "$@"
exit
fi
echo "MAKEFLAGS=\"-j$(nproc)\"" | sudo tee -a /etc/makepkg.conf
export TMPDIR=$(mktemp -d)
cd "$TMPDIR"
git clone https://aur.archlinux.org/"$1".git
cd "$TMPDIR/$1"
makepkg -As --noconfirm
sudo mkdir -p /out
sudo cp ./*".pkg.tar.zst" /out

34
create-containers.sh Executable file
View File

@ -0,0 +1,34 @@
#!/usr/bin/env sh
# read variables from file
eval "$(cat variables)"
# Create a multi-architecture manifest
buildah manifest create ${MANIFEST_NAME}
# Build your amd64 architecture container
buildah bud \
--tag "${REGISTRY}/${USER}/${IMAGE_NAME}:${IMAGE_TAG}" \
--tag "${REGISTRY}/${USER}/${IMAGE_NAME}:latest" \
--manifest ${MANIFEST_NAME} \
--file ${AMD64_FILE} \
--arch amd64
# Build your arm64 architecture container
buildah bud \
--tag "${REGISTRY}/${USER}/${IMAGE_NAME}:${IMAGE_TAG}" \
--tag "${REGISTRY}/${USER}/${IMAGE_NAME}:latest" \
--manifest ${MANIFEST_NAME} \
--file ${ARM64_FILE} \
--arch arm64
# Push the full manifest, with both CPU Architectures
buildah manifest push --all \
${MANIFEST_NAME} \
"docker://${REGISTRY}/${USER}/${IMAGE_NAME}:${IMAGE_TAG}"
buildah manifest push --all \
${MANIFEST_NAME} \
"docker://${REGISTRY}/${USER}/${IMAGE_NAME}:latest"
# remove manifest
buildah manifest rm ${MANIFEST_NAME}