From 7619e28917d0e09f371d787f9d532c22f5a2f80a Mon Sep 17 00:00:00 2001 From: Knut Ahlers Date: Sat, 10 Nov 2018 14:25:53 +0100 Subject: [PATCH] Initial version Signed-off-by: Knut Ahlers --- Dockerfile | 22 ++++++++++++++++++++++ README.md | 32 ++++++++++++++++++++++++++++++++ run.sh | 36 ++++++++++++++++++++++++++++++++++++ 3 files changed, 90 insertions(+) create mode 100644 Dockerfile create mode 100644 README.md create mode 100755 run.sh diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..a6ec0cd --- /dev/null +++ b/Dockerfile @@ -0,0 +1,22 @@ +FROM archlinux/base:latest + +RUN set -ex \ + && pacman -Sy \ + && pacman -S --noconfirm --needed \ + base-devel \ + curl \ + git \ + && useradd -m -u 1000 builder \ + && echo "builder ALL=(ALL) NOPASSWD: ALL" >/etc/sudoers.d/builder \ + && curl -sSfLo /usr/local/bin/dumb-init "https://github.com/Yelp/dumb-init/releases/download/v1.2.1/dumb-init_1.2.1_amd64" \ + && curl -sSfLo /usr/local/bin/gosu "https://github.com/tianon/gosu/releases/download/1.11/gosu-amd64" \ + && chmod 0755 \ + /usr/local/bin/dumb-init \ + /usr/local/bin/gosu + +VOLUME ["/src", "/repo"] +WORKDIR /src + +COPY run.sh /usr/local/bin/ + +ENTRYPOINT ["/usr/local/bin/run.sh"] diff --git a/README.md b/README.md new file mode 100644 index 0000000..3221626 --- /dev/null +++ b/README.md @@ -0,0 +1,32 @@ +# luzifer-docker / arch-repo-builder + +This repo contains a docker image to build and automatically add Archlinux packages to a local repository (which then can be served through an HTTP server). + +## Usage + +### Local `PKGBUILD` +First possibility to use this image is to build a local `PKGBUILD` file: + +```bash +docker run --rm -ti \ + -v "$(pwd):/src" \ + -v "/path/to/repo:/repo" \ + luzifer/arch-repo-builder +``` + +This will build an image from this Gist, take the local `PKGBUILD` in `/src`, build the package, move the result into `/repo` and add it to the `*.db.tar.*` file found in the repo. (Which means you need to initialize the repo first: `repo-add /path/to/repo/reponame.db.tar.xz`) + +### Remote git repository +The second possibility is to build any git repo containing a `PKGBUILD` file: + +```bash +docker run --rm -ti \ + -v "/path/to/repo:/repo" \ + luzifer/arch-repo-builder \ + https://aur.archlinux.org/nerd-fonts-dejavu-complete.git +``` + +This will clone the given repository and then execute the same process as above. + +### Build without repo +If no db-file was found in `/repo` the package will not be added to the repo but only reside in the mounted `/src`. diff --git a/run.sh b/run.sh new file mode 100755 index 0000000..9d39dbd --- /dev/null +++ b/run.sh @@ -0,0 +1,36 @@ +#!/usr/local/bin/dumb-init /bin/bash +set -euxo pipefail + +SRC=${1:-} + +# Override WORKDIR +cd /src + +if [ ! -e PKGBUILD ]; then + if [ -z "${SRC}" ]; then + echo "No /src/PKGBUILD was found and no repo to clone was given as parameter" + exit 1 + fi + + # Ensure permissions on src + chown -R builder /src + + gosu builder git clone "${SRC}" /src/git + cd /src/git +fi + +# Execute the build itself +gosu builder makepkg -cCs --noconfirm --needed + +PACKAGE=$(ls *.pkg.*) # This should be only one file + +REPODB=$(find /repo -name '*.db.*' ! -name '*.old') +if [ -z "${REPODB}" ]; then + echo "No database found in /repo, not adding package." + echo "The built package is available in ${PACKAGE}" +fi + +gosu builder mv "${PACKAGE}" /repo + +cd /repo +gosu builder repo-add ${REPODB} "${PACKAGE}"