Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
101 changes: 80 additions & 21 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,30 +1,89 @@
# syntax=docker/dockerfile:1

### Build stage
# Use the latest Ubuntu base image
FROM ubuntu:latest AS builder

# Set the working directory inside the container
WORKDIR /workspaces/cups

# Update package list and upgrade existing packages
RUN apt-get update -y && apt-get upgrade --fix-missing -y
WORKDIR /root/cups

# Install required dependencies for CUPS
RUN apt-get install -y autoconf build-essential \
avahi-daemon libavahi-client-dev \
libssl-dev libkrb5-dev libnss-mdns libpam-dev \
libsystemd-dev libusb-1.0-0-dev zlib1g-dev \
openssl sudo
RUN apt-get update -y && apt-get upgrade --fix-missing -y \
&& apt-get install -y --no-install-recommends \
autoconf \
build-essential \
libavahi-client-dev \
libgnutls28-dev \
libkrb5-dev \
libnss-mdns \
libpam-dev \
libssl-dev \
libsystemd-dev \
libusb-1.0-0-dev \
zlib1g-dev \
&& rm -rf /var/lib/apt/lists/*

# Copy the current directory contents into the container's working directory
COPY . /root/cups
WORKDIR /root/cups
RUN ./configure --prefix=/usr --sysconfdir=/etc --localstatedir=/var && make clean && make && make install

### Runtime stage
FROM ubuntu:latest
COPY --from=builder /root/cups /root/cups
WORKDIR /root/cups
# Expose port 631 for CUPS web interface
# DESTDIR=/buildroot — sab kuch /buildroot mein install hoga
RUN ./configure \
--prefix=/usr \
--libdir=/usr/lib \
--sysconfdir=/etc \
--localstatedir=/var \
&& make clean \
&& make \
&& make install DESTDIR=/buildroot

FROM ubuntu:latest AS runtime

RUN apt-get update -y \
&& apt-get install -y --no-install-recommends \
avahi-daemon \
libavahi-client3 \
libgnutls30t64 \
libkrb5-3 \
libnss-mdns \
libpam0g \
libssl3t64 \
libsystemd0 \
libusb-1.0-0 \
openssl \
sudo \
zlib1g \
&& rm -rf /var/lib/apt/lists/*

# Poora buildroot copy — ubuntu files overwrite se bachne ke liye
# sirf CUPS ki apni files copy ho rahi hain /buildroot se
COPY --from=builder /buildroot/usr /usr
COPY --from=builder /buildroot/etc/cups /etc/cups

# ldconfig — koi hardcoded path nahi, system khud library dhundega
RUN ldconfig

RUN useradd -m --create-home \
--password "$(echo 'admin' | openssl passwd -1 -stdin)" \
-f 0 admin \
&& groupadd -f lpadmin \
&& usermod -aG lpadmin admin \
&& echo 'admin ALL=(ALL:ALL) ALL' >> /etc/sudoers

RUN /usr/sbin/cupsd \
&& sleep 3 \
&& cupsctl --remote-admin --remote-any --share-printers \
&& killall cupsd || true

RUN sed -i \
-e 's/SystemGroup sys root/SystemGroup lpadmin/' \
/etc/cups/cups-files.conf \
&& sed -i \
-e 's/Port 631/Port 631\nServerAlias */' \
-e 's/DefaultAuthType Basic/DefaultAuthType Basic\nDefaultEncryption IfRequested/' \
/etc/cups/cupsd.conf \
&& echo "Browsing No" >> /etc/cups/cupsd.conf \
&& echo "BrowseLocalProtocols none" >> /etc/cups/cupsd.conf

RUN cp -rp /etc/cups /etc/cups-bak

VOLUME ["/etc/cups"]
VOLUME ["/var/log/cups"]

EXPOSE 631

CMD ["/usr/sbin/cupsd", "-f"]
32 changes: 2 additions & 30 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,38 +4,10 @@ services:
context: .
dockerfile: Dockerfile
container_name: cups
# Command to be executed when the container starts
command:
- /bin/bash
- -c
- |
# Add a new user 'admin' with password 'admin'
useradd -m --create-home --password $(echo 'admin' | openssl passwd -1 -stdin) -f 0 admin

# Create a new group 'lpadmin'
groupadd lpadmin

# Add the user 'admin' to the 'lpadmin' group
usermod -aG lpadmin admin

# Grant sudo privileges to the user 'admin'
echo 'admin ALL=(ALL:ALL) ALL' >> /etc/sudoers

# Start the CUPS daemon for remote access
/usr/sbin/cupsd \
&& while [ ! -f /var/run/cups/cupsd.pid ]; do sleep 1; done \
&& cupsctl --remote-admin --remote-any --share-printers \
&& kill $(cat /var/run/cups/cupsd.pid) \
&& echo "ServerAlias *" >> /etc/cups/cupsd.conf \
&& service cups start \
&& /usr/sbin/cupsd -f

# Expose port 631 for CUPS web interface
restart: unless-stopped
command: ["/usr/sbin/cupsd", "-f"]
ports:
- "631:631"

# Bind mount for cups config files and logs
volumes:
- .:/workspaces/cups
- ./container-config:/etc/cups
- ./container-config/logs:/var/log/cups
Loading