Improve `makecontainerpkg`

* Add my GPG key to the pacman keyring (not nice to hard-code it in the
  Dockerfile but good enough for now)
* Install ccache into the base image to support makepkg's ccache option
* Split syncing packages and execution of `makepkg` so syncing can be
  avoided when only building source package
* Don't quote `CRE`, it is unlikely spaces are needed here and using
  chained commands (e.g. `sudo …`) might be useful
* Add documentation
This commit is contained in:
Martchus 2022-06-12 20:33:06 +02:00
parent 97dc991438
commit 513103840d
6 changed files with 59 additions and 13 deletions

View File

@ -51,9 +51,40 @@ Requests regarding binary packages can be tracked on the issue tracker of this
GitHub project as well, e.g. within the [general discussion
issue](https://github.com/Martchus/PKGBUILDs/issues/94).
## Docker image
Checkout the repository
[docker-mingw-qt5](https://github.com/mdimura/docker-mingw-qt5).
## Container image, building packages within a container
The directory `devel/container` contains a script to build a container image
suitable to run Arch Linux's `makepkg` script so you can build from PKGBUILDs on
any environment where Docker, Podman or any other suitable container runtime is
available.
It also contains a script called `makecontainerpkg` which behaves like
`makechrootpkg` from Arch Linux's devtools but uses the previously mentioned
container image. Therefore it does *not* require devtools, a chroot setup and
systemd-nsapwn. Instead, any container runtime should be sufficient (tested with
Docker).
The usage of `makecontainerpkg` is very similar to `makechrootpkg`. Simply run
the script in a directory containing a `PKGBUILD` file. If the directory
contains a file called `pacman.conf` and/or `makepkg.conf` those files are
configured to be used during the build. The call syntax is the following:
```
makecontainerpkg [cre args] --- [makepkg args]
```
Example where the host pacman cache and ccache directories are mounted into the
container and a package rebuild is forced via `makepkg`'s flag `-f`:
```
makecontainerpkg -v /var/cache/pacman/pkg/ -v /run/media/devel/ccache:/ccache -- -f CCACHE_DIR=/ccache
```
Set the environment variable `CRE` to the container runtime executable (by
default `docker`) and set `CRE_IMAGE` to use a different container image.
---
There's also the 3rdparty repository
[docker-mingw-qt5](https://github.com/mdimura/docker-mingw-qt5) which contains
an image with many mingw-w64 package pre-installed.
## Structure
Each package is in its own subdirectoy:

View File

@ -4,7 +4,11 @@ MAINTAINER Martchus <martchus@gmx.net>
RUN mkdir -p /startdir /build && \
useradd -m -d /build -u 1000 -U -s /bin/bash builduser && \
chown -R builduser:builduser /build && \
pacman -Syu --noconfirm --needed base-devel pacman-contrib && \
pacman-key --init && \
pacman-key --recv-keys B9E36A7275FC61B464B67907E06FE8F53CDC6A4C && \
pacman-key --finger B9E36A7275FC61B464B67907E06FE8F53CDC6A4C && \
pacman-key --lsign-key B9E36A7275FC61B464B67907E06FE8F53CDC6A4C && \
pacman -Syu --noconfirm --needed base-devel pacman-contrib ccache && \
pacman -Scc --noconfirm && \
paccache -r -k0 && \
rm -rf /usr/share/man/* /tmp/* /var/tmp/*

View File

@ -1,7 +1,5 @@
#!/bin/bash
set -e
source PKGBUILD
pacman -Syu --noconfirm --needed "${depends[@]}" "${makedepends[@]}" "${checkdepends[@]}"
export LOGDEST=$PWD SRCPKGDEST=$PWD SRCDEST=$PWD PKGDEST=$PWD BUILDDIR=/build
export BUILDTOOL=makecontainerbuild BUILDTOOLVER="0.0.1"
chown builduser:builduser "$PWD"

View File

@ -0,0 +1,7 @@
#!/bin/bash
set -e
for config_file in {makepkg,pacman}.conf; do
[[ -f $config_file ]] && cp --target-directory=/etc "$config_file"
done
source PKGBUILD
pacman -Syu --noconfirm --needed "${depends[@]}" "${makedepends[@]}" "${checkdepends[@]}"

View File

@ -1,4 +1,4 @@
#!/bin/bash
set -e
bindir=$(dirname "$0")
"${CRE:-docker}" image build --tag "${CRE_IMAGE:-archlinux-base-devel}" "$bindir/base-devel"
${CRE:-docker} image build --tag "${CRE_IMAGE:-archlinux-base-devel}" "$bindir/base-devel"

View File

@ -1,15 +1,14 @@
#!/bin/bash
set -e
# load "containerbuild" script
bindir=$(dirname "$0")
script=$(cat "$bindir/containerbuild")
# parse arguments
cre_args=(--workdir "/startdir" -v "$PWD":/startdir --rm)
script_args= read_script_args=
script_args= read_script_args= no_sync=
for arg in "$@"; do
if [[ $read_script_args ]]; then
if [[ $arg == '--nodeps' ]] || [[ $arg == '-d' ]]; then
no_sync=1
fi
script_args+=" '$arg'"
else
if [[ $arg == '--' ]]; then
@ -20,9 +19,16 @@ for arg in "$@"; do
fi
done
# load "containerbuild" and "containersync" script
bindir=$(dirname "$0")
script=$(cat "$bindir/containerbuild")
if ! [[ $no_sync ]]; then
script_sync=$(cat "$bindir/containersync")
fi
# allow one to prevent the container from stopping via DEBUG variable
if [[ $DEBUG ]]; then
script_args+=' ; sleep infinity'
fi
"${CRE:-docker}" run "${cre_args[@]}" "${CRE_IMAGE:-archlinux-base-devel}" bash -c "$script $script_args"
${CRE:-docker} run "${cre_args[@]}" "${CRE_IMAGE:-archlinux-base-devel}" bash -c "$script_sync $script $script_args"