Skip to content

Commit 986cfc2

Browse files
authored
Introduces immutability to IPP-USB OCI image (#106)
* Introduce immutability to IPP-USB OCI image * Update README to include runtime flags for data persistence * Update documentation for configuration and logging setup * Include nano in Rock image and improve docs with persistent storage for ipp-usb * Enhance persistence: Separate volumes for state, config, and logs in ipp-usb.
1 parent 2b0fb8d commit 986cfc2

5 files changed

Lines changed: 380 additions & 116 deletions

File tree

README.md

Lines changed: 175 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -235,76 +235,123 @@ start ipp-usb when needed.
235235
sudo snap install docker
236236
```
237237

238-
#### Step-by-Step Guide
238+
#### **Running the `ipp-usb` Container with Persistent Storage**
239239

240-
You can pull the `ipp-usb` Docker image from the GitHub Container Registry.
240+
To run the `ipp-usb` container while ensuring that its state persists across restarts, follow these steps.
241241

242-
**From GitHub Container Registry** <br>
243-
To pull the image from the GitHub Container Registry, run the following command:
242+
#### **1. Pull the `ipp-usb` Docker Image**
243+
The latest image is available on the GitHub Container Registry. Pull it using:
244244
```sh
245-
sudo docker pull ghcr.io/openprinting/ipp-usb:latest
245+
sudo docker pull ghcr.io/openprinting/ipp-usb:latest
246246
```
247247

248-
To run the container after pulling the image, use:
248+
#### **2. Create Persistent Storage Volumes**
249+
To ensure that configuration settings and printer state persist across container restarts, create two Docker volumes:
250+
249251
```sh
250-
sudo docker run -d --network host \
251-
-v /dev/bus/usb:/dev/bus/usb:ro \
252-
--device-cgroup-rule='c 189:* rmw' \
253-
--name ipp-usb \
254-
ghcr.io/openprinting/ipp-usb:latest
255-
```
252+
sudo docker volume create ipp-usb-state
253+
sudo docker volume create ipp-usb-conf
254+
```
255+
256+
These volumes store:
256257

257-
- `--network host`: Uses the host network, ensuring IPP-over-USB and Avahi service discovery work correctly.
258-
- `-v /dev/bus/usb:/dev/bus/usb:ro`: Grants the container read-only access to USB devices.
259-
- `--device-cgroup-rule='c 189:* rmw'`: Grants the container permission to manage USB devices (189:* covers USB device nodes).
258+
- **`ipp-usb-state` (`/var/ipp-usb/`)**
259+
- Device state files (`/var/ipp-usb/dev/`) – Ensures stable TCP port allocation and DNS-SD name resolution.
260+
- Lock files (`/var/ipp-usb/lock/`) – Prevents multiple instances from running simultaneously.
261+
- Log files (`/var/log/ipp-usb/`) – Can be optionally mounted if needed for debugging.
262+
263+
- **`ipp-usb-conf` (`/etc/ipp-usb/`)**
264+
- Configuration file (`/etc/ipp-usb/ipp-usb.conf`) – Stores user-defined settings.
265+
- Quirks files (`/etc/ipp-usb/quirks/`) – Contains printer-specific workarounds.
266+
267+
#### **3. Run the Container with Required Mounts**
268+
Start the container with appropriate options:
260269

261-
To check the logs of `ipp-usb`, run:
262270
```sh
263-
sudo docker logs -f ipp-usb
271+
sudo docker run -d --network host \
272+
-v /dev/bus/usb:/dev/bus/usb:ro \
273+
-v ipp-usb-state:/var/ipp-usb \
274+
-v ipp-usb-conf:/etc/ipp-usb \
275+
--device-cgroup-rule='c 189:* rmw' \
276+
--name ipp-usb \
277+
ghcr.io/openprinting/ipp-usb:latest
264278
```
265279

280+
- **`--network host`** → Uses the host’s network to enable proper IPP-over-USB and Avahi service discovery.
281+
- **`-v /dev/bus/usb:/dev/bus/usb:ro`** → Grants read-only access to USB devices for printer detection.
282+
- **`-v ipp-usb-state:/var/ipp-usb`** → Mounts the persistent storage volume for printer state, lock files, and logs.
283+
- **`-v ipp-usb-conf:/etc/ipp-usb`** → Ensures configuration and quirks files persist across reboots.
284+
- **`--device-cgroup-rule='c 189:* rmw'`** → Grants read, write, and management permissions for USB printers inside the container.
285+
286+
266287
### Building and Running `ipp-usb` Locally
267288

268289
#### Prerequisites
269290

270-
**Docker Installed**: Ensure Docker is installed on your system. You can download it from the [official Docker website](https://www.docker.com/get-started) or from the Snap Store:
291+
1. **Docker Installed**: Ensure Docker is installed on your system. You can download it from the [official Docker website](https://www.docker.com/get-started) or from the Snap Store:
271292
```sh
272293
sudo snap install docker
273294
```
274295

275-
**Rockcraft**: Rockcraft should be installed. You can install Rockcraft using the following command:
296+
2. **Rockcraft**: Rockcraft should be installed. You can install Rockcraft using the following command:
276297
```sh
277298
sudo snap install rockcraft --classic
278299
```
279300

280-
#### Step-by-Step Guide
281-
282-
**Build the `ipp-usb` Rock Image**
301+
**To Build and Run the `ipp-usb` Rock Image Locally, follow these steps**
283302

284-
The first step is to build the Rock from the `rockcraft.yaml`. This image will contain all the configurations and dependencies required to run `ipp-usb`.
303+
#### **1. Build the `ipp-usb` Rock Image**
304+
The first step is to build the Rock image from the `rockcraft.yaml` configuration file. This image will include all required dependencies and configurations for `ipp-usb`.
285305

286-
Navigate to the directory containing `rockcraft.yaml`, then run:
306+
Navigate to the directory containing `rockcraft.yaml` and run:
287307
```sh
288308
rockcraft pack -v
289-
```
309+
```
290310

291-
**Compile to Docker Image**
311+
#### **2. Convert the Rock Image to a Docker Image**
312+
Once the `.rock` file is built, convert it into a Docker image using:
313+
```sh
314+
sudo rockcraft.skopeo --insecure-policy copy oci-archive:<rock_image> docker-daemon:ipp-usb:latest
315+
```
316+
317+
#### **3. Create Persistent Storage Volumes**
318+
To ensure that configuration settings and printer state persist across container restarts, create two Docker volumes:
292319

293-
Once the `.rock` file is built, compile a Docker image from it using:
294320
```sh
295-
sudo rockcraft.skopeo --insecure-policy copy oci-archive:<rock_image_name> docker-daemon:ipp-usb:latest
296-
```
321+
sudo docker volume create ipp-usb-state
322+
sudo docker volume create ipp-usb-conf
323+
```
297324

298-
**Run the `ipp-usb` Docker Container**
325+
These volumes store:
326+
327+
- **`ipp-usb-state` (`/var/ipp-usb/`)**
328+
- Device state files (`/var/ipp-usb/dev/`) – Ensures stable TCP port allocation and DNS-SD name resolution.
329+
- Lock files (`/var/ipp-usb/lock/`) – Prevents multiple instances from running simultaneously.
330+
- Log files (`/var/log/ipp-usb/`) – Can be optionally mounted if needed for debugging.
331+
332+
- **`ipp-usb-conf` (`/etc/ipp-usb/`)**
333+
- Configuration file (`/etc/ipp-usb/ipp-usb.conf`) – Stores user-defined settings.
334+
- Quirks files (`/etc/ipp-usb/quirks/`) – Contains printer-specific workarounds.
335+
336+
#### **4. Run the Container with Required Mounts**
337+
Start the container with appropriate options:
299338

300339
```sh
301-
sudo docker run -d --network host \
302-
-v /dev/bus/usb:/dev/bus/usb:ro \
303-
--device-cgroup-rule='c 189:* rmw' \
304-
--name ipp-usb \
305-
ipp-usb:latest
340+
sudo docker run -d --network host \
341+
-v /dev/bus/usb:/dev/bus/usb:ro \
342+
-v ipp-usb-state:/var/ipp-usb \
343+
-v ipp-usb-conf:/etc/ipp-usb \
344+
--device-cgroup-rule='c 189:* rmw' \
345+
--name ipp-usb \
346+
ipp-usb:latest
306347
```
307348

349+
- **`--network host`** → Uses the host’s network to enable proper IPP-over-USB and Avahi service discovery.
350+
- **`-v /dev/bus/usb:/dev/bus/usb:ro`** → Grants read-only access to USB devices for printer detection.
351+
- **`-v ipp-usb-state:/var/ipp-usb`** → Mounts the persistent storage volume for printer state, lock files, and logs.
352+
- **`-v ipp-usb-conf:/etc/ipp-usb`** → Ensures configuration and quirks files persist across reboots.
353+
- **`--device-cgroup-rule='c 189:* rmw'`** → Grants read, write, and management permissions for USB printers inside the container.
354+
308355
### Accessing the Container Shell
309356

310357
To enter the running `ipp-usb` container and access a shell inside it, use:
@@ -313,22 +360,105 @@ To enter the running `ipp-usb` container and access a shell inside it, use:
313360
```
314361
This allows you to inspect logs, debug issues, or manually run commands inside the container.
315362

316-
### Configuration
363+
### Configuration
317364

318-
The `ipp-usb` container uses a configuration file located at:
365+
The `ipp-usb` container uses a configuration file located at:
366+
```sh
367+
/etc/ipp-usb/ipp-usb.conf
319368
```
320-
/etc/ipp-usb.conf
369+
By default, the container uses the built-in configuration, which can be modified from inside the container.
370+
371+
**Modifying the Configuration File Inside the Container**
372+
373+
#### **1. Enter the Running Container**
374+
Use the following command to access the container’s shell:
375+
```sh
376+
sudo docker exec -it ipp-usb bash
321377
```
322-
To customize the configuration, mount a modified config file:
378+
379+
#### **2. Open the Configuration File in Nano**
380+
Once inside the container, open the configuration file using `nano`:
323381
```sh
324-
sudo docker run -d --network host \
325-
-v /dev/bus/usb:/dev/bus/usb:ro \
326-
--device-cgroup-rule='c 189:* rmw' \
327-
-v /path/to/custom/ipp-usb.conf:/etc/ipp-usb.conf:ro \
328-
--name ipp-usb \
329-
ghcr.io/openprinting/ipp-usb:latest
382+
nano /etc/ipp-usb/ipp-usb.conf
330383
```
331384

385+
#### **3. Edit and Save the File**
386+
- Make the necessary changes to the file.
387+
- Press `CTRL + X`, then `Y`, and hit `Enter` to save the changes.
388+
389+
#### **4. Restart the Container to Apply Changes**
390+
Exit the container and restart it to apply the updated configuration:
391+
```sh
392+
sudo docker restart ipp-usb
393+
```
394+
395+
### **Viewing Logs in the `ipp-usb` Container**
396+
397+
The `ipp-usb` container logs important events and errors to `/var/log/ipp-usb/`. Logs are categorized into:
398+
399+
- **Main log file:** `/var/log/ipp-usb/main.log` → Captures overall service activity, including errors and general events.
400+
- **Per-device logs:** `/var/log/ipp-usb/<DEVICE>.log` → Individual log files for each detected printer, helpful for troubleshooting device-specific issues.
401+
402+
#### **1. Using Docker Logs**
403+
404+
To view real-time logs from the running container, use:
405+
```sh
406+
sudo docker logs -f ipp-usb
407+
```
408+
- The `-f` flag follows the logs in real-time.
409+
- Replace `ipp-usb` with your actual container name if different.
410+
411+
#### **2. Viewing Logs Inside the Container**
412+
413+
If you need to inspect logs manually, first enter the container shell:
414+
```sh
415+
sudo docker exec -it ipp-usb bash
416+
```
417+
418+
Once inside the container, you can use the following commands:
419+
420+
#### **2.1 Monitor Logs in Real-Time**
421+
422+
- **Main log file:**
423+
```sh
424+
tail -f /var/log/ipp-usb/main.log
425+
```
426+
This continuously displays new log entries for the entire service.
427+
428+
- **Per-device log file (Replace `<DEVICE>` with your printer's identifier):**
429+
```sh
430+
tail -f /var/log/ipp-usb/<DEVICE>.log
431+
```
432+
433+
#### **2.2 Display Full Log Files**
434+
435+
- **Show full contents of the main log file:**
436+
```sh
437+
cat /var/log/ipp-usb/main.log
438+
```
439+
440+
- **Show logs for a specific device:**
441+
```sh
442+
cat /var/log/ipp-usb/<DEVICE>.log
443+
```
444+
445+
#### **2.3 List Available Device Logs**
446+
447+
To see all available per-device log files, run:
448+
```sh
449+
ls /var/log/ipp-usb/
450+
```
451+
452+
#### **3. Persisting Logs Across Container Restarts**
453+
454+
If you want logs to persist across container restarts, you should mount the log directory using a Docker volume or a host directory.
455+
456+
**Required Docker Flags for Log Persistence:**
457+
- `-v <volume-name>:/var/log/ipp-usb` → Mounts a Docker volume for log persistence.
458+
- **or**
459+
- `-v <host-directory>:/var/log/ipp-usb` → Mounts a host directory to retain logs outside the container.
460+
461+
These options ensure that logs remain available even after the container stops or is recreated, allowing for easier troubleshooting and auditing.
332462

333463
## Installation from source
334464

0 commit comments

Comments
 (0)