diff --git a/.github/workflows/oci-container.yml b/.github/workflows/oci-container.yml new file mode 100644 index 00000000..f098f292 --- /dev/null +++ b/.github/workflows/oci-container.yml @@ -0,0 +1,41 @@ +name: OCI Container Build and Smoke Test + +on: + push: + branches: + - feature/cloud-native-oci + - master + pull_request: + branches: + - master + workflow_dispatch: + +jobs: + build-and-test: + name: Build OCI Image & Smoke Test + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Build OCI Container Image + uses: docker/build-push-action@v5 + with: + context: . + file: ./Containerfile + tags: ghostscript-printer-app:test + load: true + cache-from: type=gha + cache-to: type=gha,mode=max + + - name: Smoke Test OCI Container + run: | + docker run -d --name gs-test -p 8000:8000 ghostscript-printer-app:test + sleep 5 + docker logs gs-test + curl -f -s -I http://localhost:8000/ || exit 1 + docker stop gs-test diff --git a/Containerfile b/Containerfile new file mode 100644 index 00000000..ee15e9b9 --- /dev/null +++ b/Containerfile @@ -0,0 +1,121 @@ +FROM fedora:41 AS builder + +RUN echo "fastestmirror=True" >> /etc/dnf/dnf.conf \ + && echo "max_parallel_downloads=10" >> /etc/dnf/dnf.conf \ + && echo "defaultyes=True" >> /etc/dnf/dnf.conf \ + && dnf install -y 'dnf-command(builddep)' \ + && dnf --enablerepo=\*source* builddep -y libcupsfilters libppd \ + && dnf install -y \ + gcc \ + gcc-c++ \ + make \ + which \ + autoconf \ + automake \ + libtool \ + gettext-devel \ + pkgconf-pkg-config \ + git \ + cups-devel \ + libjpeg-turbo-devel \ + libpng-devel \ + libtiff-devel \ + libjxl-devel \ + libexif-devel \ + libusb1-devel \ + avahi-devel \ + gnutls-devel \ + pam-devel \ + qpdf-devel \ + poppler-devel \ + zlib-devel \ + ghostscript-devel \ + ghostscript \ + && dnf clean all + +WORKDIR /build + +RUN git clone --depth 1 --recurse-submodules https://github.com/OpenPrinting/libcups.git \ + && cd libcups \ + && ./configure --prefix=/usr --libdir=/usr/lib64 \ + && make -j$(nproc) \ + && make install + +RUN git clone --depth 1 -b v1.4.x https://github.com/michaelrsweet/pappl.git \ + && cd pappl \ + && ./configure --prefix=/usr --libdir=/usr/lib64 --enable-libusb --with-dnssd=avahi \ + && make -j$(nproc) \ + && make install + +RUN git clone --depth 1 --recurse-submodules https://github.com/michaelrsweet/pdfio.git \ + && cd pdfio \ + && ./configure --prefix=/usr --libdir=/usr/lib64 \ + && make -j$(nproc) \ + && make install + +RUN git clone --depth 1 https://github.com/OpenPrinting/libcupsfilters.git \ + && cd libcupsfilters \ + && ./autogen.sh \ + && ./configure --prefix=/usr --libdir=/usr/lib64 --disable-mutool \ + && make -j$(nproc) \ + && make install + +RUN git clone --depth 1 https://github.com/OpenPrinting/libppd.git \ + && cd libppd \ + && ./autogen.sh \ + && ./configure --prefix=/usr --libdir=/usr/lib64 --disable-mutool \ + && make -j$(nproc) \ + && make install + +RUN git clone --depth 1 https://github.com/OpenPrinting/pappl-retrofit.git \ + && cd pappl-retrofit \ + && ./autogen.sh \ + && ./configure --prefix=/usr --libdir=/usr/lib64 \ + && make -j$(nproc) \ + && make install + +COPY . /build/ghostscript-printer-app +WORKDIR /build/ghostscript-printer-app +RUN make -j$(nproc) && make install DESTDIR=/build/rootfs + +FROM quay.io/fedora/fedora-minimal:41 + +RUN microdnf install -y \ + cups-libs \ + libusb1 \ + libpng \ + libjpeg-turbo \ + libtiff \ + libjxl \ + libexif \ + avahi-libs \ + gnutls \ + qpdf-libs \ + poppler \ + ghostscript \ + foomatic-db \ + foomatic-db-ppds \ + shadow-utils \ + && microdnf clean all + +COPY --from=builder /usr/lib64/libcups3* /usr/lib64/ +COPY --from=builder /usr/lib64/libpappl* /usr/lib64/ +COPY --from=builder /usr/lib64/libpdfio* /usr/lib64/ +COPY --from=builder /usr/lib64/libcupsfilters* /usr/lib64/ +COPY --from=builder /usr/lib64/libppd* /usr/lib64/ +COPY --from=builder /usr/lib64/libpappl-retrofit* /usr/lib64/ +COPY --from=builder /build/rootfs/ / + +RUN ldconfig + +RUN useradd -r -u 1001 -g lp -d /var/run/ghostscript-printer-app -s /sbin/nologin printer-app \ + && mkdir -p /var/run/ghostscript-printer-app /var/spool/ghostscript-printer-app /var/lib/ghostscript-printer-app \ + && chown -R 1001:lp /var/run/ghostscript-printer-app /var/spool/ghostscript-printer-app /var/lib/ghostscript-printer-app + +USER 1001:lp +WORKDIR /var/run/ghostscript-printer-app + +EXPOSE 8000 + +ENTRYPOINT ["/usr/bin/ghostscript-printer-app"] +CMD ["-o", "server-port=8000", "server"] diff --git a/README.md b/README.md index e8b81501..d2f56e80 100644 --- a/README.md +++ b/README.md @@ -340,6 +340,144 @@ If you mess up any configuration file under `/var/snap/ghostscript-printer-app/common/`, simply delete it (or move it away) and restart the Snap to get it restored. +## CLOUD-NATIVE OCI CONTAINER & SYSTEMD QUADLET (RECOMMENDED) + +The modern, recommended way to deploy the Ghostscript Printer Application on immutable Linux distributions (such as Universal Blue / Bluefin, Bazzite, Fedora Silverblue) as well as classic distributions is using standard OCI containers and systemd Quadlets. + +### Key Architectural Highlights + +- **Universal & Rootless**: Built on a minimal Fedora base (`quay.io/fedora/fedora-minimal:41`), running rootless as an unprivileged user (`1001:lp`). +- **Host D-Bus Socket Sharing**: Rather than running redundant internal `dbus-daemon` and `avahi-daemon` instances inside the container, the container mounts `/run/dbus/system_bus_socket`. The application communicates directly with the host's Avahi daemon for mDNS/DNS-SD registration without network or daemon collisions. +- **Declarative Systemd Management**: Integrates natively with Podman Quadlets (`.container` files), allowing systemd to manage container lifecycle, restarts, dependencies, and autostart on boot. +- **Bleeding-Edge Dependency Stack**: Compiles against upstream `libcups` (3.x), `pappl` (v1.4.x stable branch), `pdfio`, `libcupsfilters`, `libppd`, and `pappl-retrofit`, bundling Ghostscript for legacy printer rasterization. + +--- + +### Deploying with Systemd Quadlet (Universal Blue / Bluefin / Fedora Silverblue) + +Systemd Quadlet is the declarative, systemd-native way to run Podman containers on modern Linux desktops. + +#### 1. Install the Quadlet File + +Copy the provided Quadlet configuration to your user systemd directory: + +```sh +mkdir -p ~/.config/containers/systemd/ +cp packaging/quadlet/ghostscript-printer-app.container ~/.config/containers/systemd/ +``` + +*(For a system-wide service across all users, copy to `/etc/containers/systemd/` instead).* + +> [!NOTE] +> **Image reference:** The Quadlet file defaults to `Image=ghcr.io/openprinting/ghostscript-printer-app:latest`. If you built the container image locally with the tag `ghostscript-printer-app:latest`, update the `Image=` line in `~/.config/containers/systemd/ghostscript-printer-app.container` to `Image=localhost/ghostscript-printer-app:latest` (or `ghostscript-printer-app:latest`). + +#### 2. Reload and Start the Service + +Tell systemd to generate the service and start it: + +```sh +# Reload systemd generator to create the service +systemctl --user daemon-reload + +# Start the Printer Application +systemctl --user start ghostscript-printer-app + +# Check status +systemctl --user status ghostscript-printer-app +``` + +#### 3. Enable Autostart on Boot + +To start the container automatically on system login: + +```sh +systemctl --user enable ghostscript-printer-app +``` + +--- + +### Running Directly with Podman or Docker CLI + +If you are not using Quadlets, you can build and run the container directly with Podman or Docker: + +#### 1. Build the Container Image + +```sh +# Using Podman +podman build -f Containerfile -t ghostscript-printer-app:latest . + +# Using Docker +docker build -f Containerfile -t ghostscript-printer-app:latest . +``` + +#### 2. Run the Container + +Create named volumes for persistence: + +```sh +podman volume create ghostscript-printer-app-data +podman volume create ghostscript-printer-app-spool +``` + +Start the container with host network and device access: + +```sh +podman run -d \ + --name ghostscript-printer-app \ + --network host \ + --cap-drop=ALL \ + --device /dev/bus/usb:/dev/bus/usb:rwm \ + -v /run/dbus/system_bus_socket:/run/dbus/system_bus_socket:ro \ + -v ghostscript-printer-app-data:/var/lib/ghostscript-printer-app \ + -v ghostscript-printer-app-spool:/var/spool/ghostscript-printer-app \ + ghostscript-printer-app:latest +``` + +*(Replace `podman` with `docker` if using Docker).* + +#### Explanation of Flags: +- `--network host`: Required for discovering network printers via DNS-SD/mDNS and SNMP broadcasts. +- `--cap-drop=ALL`: Drops all unnecessary Linux capabilities, ensuring the container runs strictly with least privilege as unprivileged user `1001:lp`. +- `--device /dev/bus/usb`: Passes USB printer devices into the container with read/write permissions. +- `-v /run/dbus/system_bus_socket:...`: Shares the host system D-Bus socket so PAPPL/libcups can register IPP services with host Avahi. +- `-v ghostscript-printer-app-data:/var/lib/ghostscript-printer-app`: Persists configured printer settings and user-uploaded PPD files across container restarts. +- `-v ghostscript-printer-app-spool:/var/spool/ghostscript-printer-app`: Persists print queue spool files across container restarts. + +> [!TIP] +> **Host D-Bus and AppArmor (Ubuntu / Debian / Linux Mint with Docker):** +> On distributions using AppArmor (such as Ubuntu, Debian, or Linux Mint), Docker's default AppArmor profile (`docker-default`) restricts container access to the host D-Bus socket (`/run/dbus/system_bus_socket`), and the host D-Bus daemon will reject unmapped container UIDs (`1001`). +> If testing on Ubuntu or Linux Mint with rootful Docker, pass `--security-opt apparmor=unconfined --user $(id -u):$(id -g)` so the container authenticates as your host user, or use **Podman** (which handles user namespaces rootlessly out-of-the-box on immutable systems like Universal Blue / Bluefin and Fedora Silverblue). + +--- + +### Setting Up Printers & Web Interface + +Once running, access the web administration interface at: + +```text +http://localhost:8000/ +``` + +1. **Auto-Discovered Printers**: Network printers (via DNS-SD) and connected USB printers will be discovered automatically. Click **Add Printer** to set up a queue. +2. **Adding Custom PPD Files**: + - In the web interface, go to the **Add PPD files** section to upload manufacturer PPDs directly through your browser. + - Uploaded PPDs are stored in `/var/lib/ghostscript-printer-app/ppd/` inside the container and persisted across restarts via the `ghostscript-printer-app-data` volume. +3. **Mounting Existing Host PPD Directories**: + You can also mount an existing collection of PPD files into the container by adding a bind mount: + ```sh + -v /path/to/my/ppds:/usr/share/ppd/custom:ro + ``` + +--- + +### Notes for Developers & Maintainers + +- **PAPPL Version Compatibility**: The container builds against `https://github.com/michaelrsweet/pappl.git` tracking branch `v1.4.x`. `pappl-retrofit` officially targets the stable PAPPL 1.4.x ABI. When PAPPL 2.0.x reaches its first stable release and `pappl-retrofit` callback signatures are aligned upstream, the container will switch to tracking PAPPL 2.x. +- **Dual CUPS Compatibility**: `ghostscript-printer-app.c` maintains dual compatibility across CUPS versions using preprocessor macros (`#if CUPS_VERSION_MAJOR >= 3`). This ensures that the application compiles cleanly against both `libcups3` (used in this OCI container) and `libcups2` (used in existing Snapcraft builds). +- **Smoke Testing in CI**: The `.github/workflows/oci-container.yml` workflow builds the multi-stage image using Docker Buildx and executes an automated smoke test verifying HTTP `200 OK` on port 8000. + +--- + ## THE ROCK (OCI CONTAINER IMAGE) ### Install from Docker Hub diff --git a/packaging/quadlet/ghostscript-printer-app.container b/packaging/quadlet/ghostscript-printer-app.container new file mode 100644 index 00000000..943909bc --- /dev/null +++ b/packaging/quadlet/ghostscript-printer-app.container @@ -0,0 +1,23 @@ +[Unit] +Description=Ghostscript Printer Application +Documentation=https://github.com/OpenPrinting/ghostscript-printer-app +After=network-online.target +Wants=network-online.target + +[Container] +Image=ghcr.io/openprinting/ghostscript-printer-app:latest +ContainerName=ghostscript-printer-app +Network=host +AddDevice=/dev/bus/usb:/dev/bus/usb:rwm +Volume=/run/dbus/system_bus_socket:/run/dbus/system_bus_socket:ro +Volume=ghostscript-printer-app-data:/var/lib/ghostscript-printer-app +Volume=ghostscript-printer-app-spool:/var/spool/ghostscript-printer-app +DropCapability=ALL + +[Service] +Restart=on-failure +RestartSec=5s +TimeoutStartSec=60s + +[Install] +WantedBy=default.target