Skip to content

Commit

Permalink
Add support for docker with README install instructions (#88)
Browse files Browse the repository at this point in the history
* Add Dockerfile + workflow to build

* Modify README to add docker install instructions

* Mod README and add docker README

* Make Dockerfile better

* Update Dockerfile

---------

Co-authored-by: Alex Butler <[email protected]>
  • Loading branch information
Ew4n1011 and alexheretic authored Aug 7, 2023
1 parent 6749a49 commit 40d718f
Show file tree
Hide file tree
Showing 4 changed files with 144 additions and 0 deletions.
41 changes: 41 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: Create and Publish a Docker image

on:
push:
branches: [ master ]

env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}

jobs:
build-and-push-image:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write

steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Log in to the Container registry
uses: docker/[email protected]
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/[email protected]
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}

- name: Build and push Docker image
uses: docker/[email protected]
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
68 changes: 68 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
FROM archlinux:base-devel AS build

# Setup sudo user & install dependencies
RUN pacman -Syu --noconfirm git pacutils perl-json-xs devtools pacman-contrib ninja cargo && \
echo '%wheel ALL=(ALL:ALL) NOPASSWD: ALL' >> /etc/sudoers && \
useradd --uid 1000 --shell /bin/bash --groups wheel --create-home build

USER build

WORKDIR /home/build

# Build aurutils & aurto
RUN curl -L https://aur.archlinux.org/cgit/aur.git/snapshot/aurutils.tar.gz | tar xz && \
cd aurutils && \
gpg --recv-keys DBE7D3DD8C81D58D0A13D0E76BC26A17B9B7018A && \
makepkg -i --noconfirm && \
cd .. && \
curl -L https://aur.archlinux.org/cgit/aur.git/snapshot/aurto.tar.gz | tar xz && \
cd aurto && \
makepkg -i --noconfirm

FROM archlinux:latest

ENV USER_ID="1002" \
USER=aurto

WORKDIR /

# Remove unnecessary units
RUN rm -f /lib/systemd/system/multi-user.target.wants/* \
/etc/systemd/system/*.wants/* \
/lib/systemd/system/local-fs.target.wants/* \
/lib/systemd/system/sockets.target.wants/*udev* \
/lib/systemd/system/sockets.target.wants/*initctl* \
/lib/systemd/system/sysinit.target.wants/systemd-tmpfiles-setup* \
/lib/systemd/system/systemd-update-utmp*

# Install dependencies and setup sudo user
RUN pacman -Syu --needed --noconfirm base-devel sudo pacman-contrib && \
echo '%wheel ALL=(ALL:ALL) NOPASSWD: ALL' >> /etc/sudoers && \
useradd --uid ${USER_ID} --shell /bin/bash --groups wheel --create-home aurto

WORKDIR /tmp

# Copy aurutils & aurto from build stage
COPY --from=build /home/build/aurutils/aurutils-*.pkg.tar.zst /tmp/
COPY --from=build /home/build/aurto/aurto-*.pkg.tar.zst /tmp/

# Install aurto & aurutils
RUN pacman -U --noconfirm /tmp/aurutils-*.pkg.tar.zst && \
pacman -U --noconfirm /tmp/aurto-*.pkg.tar.zst && \

# Disable chroot for aurto
touch /usr/lib/aurto/conf-disable-chroot && \

# Cleanup
rm -r /tmp/* && \
paccache -rk0 && \

# Setup pacman hook
mkdir -p /etc/pacman.d/hooks/ && \
echo -e "[Trigger]\nType = Package\nOperation = Remove\nOperation = Install\nOperation = Upgrade\nTarget = *\n\n[Action]\nDescription = Removing unnecessary cached files (keeping the latest one)...\nWhen = PostTransaction\nExec = /usr/bin/paccache -rk0" > /etc/pacman.d/hooks/pacman-cache-cleanup.hook

WORKDIR /home/aurto

VOLUME ["/tmp", "/run", "/run/lock", "/etc/aurto", "/var/cache/pacman/aurto"]

CMD [ "/lib/systemd/systemd", "log-level=info", "unit=sysinit.target" ]
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,11 @@ Remove `/etc/aurto/trusted-users` to trust everyone.
**aurto** builds packages in a chroot using `/etc/aurto/makepkg-chroot.conf` & `/etc/aurto/pacman-chroot.conf`.
These can be customized in the same way as the main _makepkg.conf, pacman.conf_, for example to change compression.

# Running on docker
**aurto** can also be ran on docker to allow for installation on non Arch distros for hosting a aur repo, etc.

You can find the documentation on how to install it [here](./dockerREADME.md).

# Limitations & Security
**aurto** automatically builds and regularly re-builds updated remote code from the aur.
Code is _built_ in a clean chroot, but presumably will eventually be installed to your system.
Expand Down
30 changes: 30 additions & 0 deletions dockerREADME.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# aurto with docker

After installing docker on your machine, run this command to create the container:
```sh
docker run -d --name aurto-docker \
--privileged --cap-add SYS_ADMIN --security-opt seccomp=unconfined \
--cgroup-parent=docker.slice --cgroupns private \
--tmpfs /tmp --tmpfs /run --tmpfs /run/lock \
-v aurto_db:/var/cache/pacman/aurto \
-v aurto_config:/etc/aurto \
ghcr.io/alexheretic/aurto:master
```

> Make sure to replace **aurto_db** and **aurto_config** with an actual path if you don't want it to store the pacman repo and config files in a docker volume
Then running the commands like a normal installation, first initialise the 'aurto' repo & systemd timers.
```sh
docker exec -it --user aurto aurto-docker aurto init
```

Recommended: Add **aurto** to the 'aurto' repo to provide self updates.
```sh
docker exec -it --user aurto aurto-docker aurto add aurto
```

Also recommended: Add an alias to .bashrc so you only have to write aurto instead of the full docker command.

```sh
alias aurto="docker exec -it --user aurto aurto-docker aurto"
```

0 comments on commit 40d718f

Please sign in to comment.