create repo to makpkg _cleanly_ inside container

This commit is contained in:
Alexander Mahr 2024-06-17 07:00:34 +02:00
commit dee78d745c
7 changed files with 140 additions and 0 deletions

1
.gitingore Normal file
View file

@ -0,0 +1 @@
packages.build/*

18
Containerfile Normal file
View file

@ -0,0 +1,18 @@
FROM archlinux:latest
RUN type makepkg
RUN id
RUN pacman -Syu --noconfirm
RUN pacman -Sy --noconfirm git vim jq base-devel
RUN pacman -Sy --noconfirm sudo
RUN echo 'build ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers
RUN find / -name 'libreadline.*' -print | xargs chmod -v a+rx || true
RUN useradd -m build
RUN mkdir /packages.build/; chown build /packages.build
VOLUME /packages.build/
COPY --chmod=0555 ./entrypoint.sh /entrypoint.sh
ENTRYPOINT ["/entrypoint.sh"]
CMD ["sh"]
USER build
WORKDIR /packages.build/

1
LICENSE Normal file
View file

@ -0,0 +1 @@
(C) Alexander Mahr 2024 + This work is licensed under AGPL-3.0-only

93
README.md Normal file
View file

@ -0,0 +1,93 @@
# cleaner archlinux makepkg
**tl;dr** makepkg ofte requires to install dependencies ("polluting the system with eversomore packages") this is a way to do this in a container to keep the system "cleaner".
In archlinux packages can be made via [`PKGBUILD`](https://wiki.archlinux.org/title/PKGBUILD) using the [`makepkg`](https://wiki.archlinux.org/title/Makepkg)
command. This is a great to build modified packages existing in the arch linux package repos (i.e. via ABS arch build system) and also AUR (arch user repos)
However a often the this leads to a situation where for building the package further dependencies are required
```
[alex@thinkbox tmp]$ mkdir abs
[alex@thinkbox tmp]$ cd abs
[alex@thinkbox abs]$ git clone https://gitlab.archlinux.org/archlinux/packaging/packages/squid
Cloning into 'squid'...
warning: redirecting to https://gitlab.archlinux.org/archlinux/packaging/packages/squid.git/
remote: Enumerating objects: 593, done.
remote: Counting objects: 100% (79/79), done.
remote: Compressing objects: 100% (69/69), done.
remote: Total 593 (delta 48), reused 9 (delta 9), pack-reused 514 (from 1)
Receiving objects: 100% (593/593), 89.66 KiB | 2.24 MiB/s, done.
Resolving deltas: 100% (292/292), done.
[alex@thinkbox abs]$ cd squid/
[alex@thinkbox squid]$ makepkg
==> ERROR: Cannot find the debugedit binary required for including source files in debug packages.
[alex@thinkbox squid]$
```
It becomes necessary to install the required dependencies (something that can be done via the `--syncdeps` flag to `makepkg`
```
-s, --syncdeps
Install missing dependencies using pacman. When build-time or run-time dependencies are not found, pacman will try to resolve them. If successful, the missing packages will be downloaded and installed.
```
which however requires the user to be
1. allowed to install packages
2. accepting/willing to have those new packages installed and potentially bloating the system.
while 2. can be mitigated by removing the instlled packages after the build if desired, i.e. by cleaning up, it
yet would be nice to not even have to (even temporarily) installed packages for the only purpose being to be
able to build a package. This is paritcular true for [`makedepends`](https://wiki.archlinux.org/title/PKGBUILD#makedepends) packages
which are required only for the build of the package anyway.
## What does this repo provide then?
It provides a container setup, a docker/podman compose setup to `makepkg` build archlinux without polluting your system
## How to use
1. if needed install `docker-compose` (ideally in a [rootless way](https://docs.docker.com/engine/security/rootless/))
2. run `docker compose run makepkg https://gitlab.archlinux.org/archlinux/packaging/packages/<packagename>`
3. select if you desire to step in to modify some of the code/build before the build
4. build is run
5. build is done and resulting package can be found in `./packages.build/<packagename>.git/...`
example the package `unzip`
1. compose already setup
```
[alex@thinkbox docker-makepkg]$ pacman -Q | grep compose
docker-compose 2.27.1-1
podman-compose 1.1.0-2
[alex@thinkbox docker-makepkg]$ type docker-compose
docker-compose is /usr/bin/docker-compose
```
2. using this repo to build using a container
```
[alex@thinkbox docker-makepkg]$ docker compose run makepkg https://gitlab.archlinux.org/archlinux/packaging/packages/unzip.git
args are https://gitlab.archlinux.org/archlinux/packaging/packages/unzip.git
/packages.build
Cloning into 'unzip.git'...
remote: Enumerating objects: 132, done.
remote: Counting objects: 100% (54/54), done.
remote: Compressing objects: 100% (34/34), done.
remote: Total 132 (delta 39), reused 20 (delta 20), pack-reused 78 (from 1)
Receiving objects: 100% (132/132), 44.88 KiB | 1.18 MiB/s, done.
Resolving deltas: 100% (39/39), done.
modify stuff prior to build?[y/N]==>
```
3. determine if that you do not need to do anything (default after 3 seconds)
4. build is run with all required depdencies installed (within the container)
5. as a result we end up with the packages for `unzip`
```
[alex@thinkbox docker-makepkg]$ ls -l packages.build/unzip.git/*pkg*tar*
-rw-r--r-- 1 alex alex 145806 Jun 17 06:45 packages.build/unzip.git/unzip-6.0-21-x86_64.pkg.tar.zst
-rw-r--r-- 1 alex alex 481896 Jun 17 06:45 packages.build/unzip.git/unzip-debug-6.0-21-x86_64.pkg.tar.zst
```
Voila we could now install this very package via `sudo pacman -U packages.build/unzip.git/unzip-6.0-21-x86_64.pkg.tar.zst`

8
compose.yml Normal file
View file

@ -0,0 +1,8 @@
services:
makepkg:
build:
context: '.'
dockerfile: "Containerfile"
volumes:
- ./packages.build:/packages.build

19
entrypoint.sh Executable file
View file

@ -0,0 +1,19 @@
#!/bin/bash
echo args are "$@"
pwd
test "$1" = "sh" && exec sh
test "$2" = '--clean' && rm -rf "${A##*/}" || true
test -d "${1##*/}" && echo "CLONED ALREADY set --clean as second arg to remove" || git clone "$1" "${1##*/}"
cd "${1##*/}"
read -t 3 -p "modify stuff prior to build?[y/N]" -N1 YES
test "$YES" = "y" && {
bash
read -t 3 -p "continue build?[Y/n]" -N1 NO
test "$NO" = "n" && exit 0
}
makepkg --syncdeps --noconfirm

0
packages.build/.gitkeep Normal file
View file