Skip to content

Commit f13b641

Browse files
authored
Build and Deploy OCI Image of hplip-printer-app Using Rockcraft (#21)
- Added rockcraft.yaml, parts taken from snap/snapcraft.yaml - Added scripts to start Avahi and D-Bus support in the container and to start the Printer Application itself, optionally on a user-selected port - Moved patches from snap/ subdirectory to separate patches/ subdirectory for use by both Snap and Rock - Added and updated the GitHub workflows, for updating and versioning automation of the Rock, CI testing, and registering OCI image in Docker and GitHub - Added documentation for the Rock/OCI image to README.md
1 parent fac2368 commit f13b641

12 files changed

+1173
-8
lines changed

.github/workflows/auto-update.yml

+23-4
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,39 @@ name: Push new tag update to stable branch
22

33
on:
44
schedule:
5-
# Daily for now
65
- cron: '9 7 * * *'
76
workflow_dispatch:
7+
inputs:
8+
workflow_choice:
9+
description: "Choose YAML to update"
10+
required: true
11+
default: "both"
12+
type: choice
13+
options:
14+
- snapcraft
15+
- rockcraft
16+
- both
817

918
jobs:
10-
update-snapcraft-yaml:
19+
update-yamls:
1120
runs-on: ubuntu-latest
1221
steps:
1322
- name: Checkout this repo
1423
uses: actions/checkout@v3
15-
- name: Run desktop-snaps action
24+
25+
- name: Run desktop-snaps action (Snapcraft)
26+
if: ${{ github.event_name == 'schedule' || github.event.inputs.workflow_choice == 'snapcraft' || github.event.inputs.workflow_choice == 'both' }}
1627
uses: ubuntu/desktop-snaps@stable
1728
with:
1829
token: ${{ secrets.GITHUB_TOKEN }}
1930
repo: ${{ github.repository }}
2031
version-schema: '^debian/(\d+\.\d+\.\d+)'
21-
32+
33+
- name: Run desktop-snaps action (Rockcraft)
34+
if: ${{ github.event_name == 'schedule' || github.event.inputs.workflow_choice == 'rockcraft' || github.event.inputs.workflow_choice == 'both' }}
35+
uses: ubuntu/desktop-snaps@stable
36+
with:
37+
token: ${{ secrets.GITHUB_TOKEN }}
38+
repo: ${{ github.repository }}
39+
rock-version-schema: '^debian/(\d+\.\d+\.\d+)'
40+
yaml-path: 'rockcraft.yaml'

.github/workflows/ci.yml

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
name: CI Pipeline for hplip-printer-app
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
- master
8+
pull_request:
9+
branches:
10+
- main
11+
- master
12+
workflow_dispatch:
13+
14+
jobs:
15+
build-rock:
16+
runs-on: ubuntu-latest
17+
steps:
18+
- name: Checkout repository
19+
uses: actions/checkout@v4
20+
21+
- name: Pack with Rockcraft
22+
uses: canonical/craft-actions/rockcraft-pack@main
23+
id: rockcraft
24+
25+
build-snap:
26+
runs-on: ubuntu-latest
27+
steps:
28+
- name: Checkout repository
29+
uses: actions/checkout@v4
30+
31+
- name: Build Snap Package
32+
uses: snapcore/action-build@v1
33+
id: snapcraft
+113
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
name: Pack and Publish OCI Image to Docker Registry and GitHub Packages
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
- master
8+
workflow_dispatch:
9+
inputs:
10+
workflow_choice:
11+
description: "Choose Release Channel"
12+
required: true
13+
default: "edge"
14+
type: choice
15+
options:
16+
- edge
17+
- stable
18+
- both
19+
workflow_run:
20+
workflows: ["Push new tag update to stable branch"]
21+
types:
22+
- completed
23+
24+
jobs:
25+
build-rock:
26+
runs-on: ubuntu-latest
27+
steps:
28+
- name: Checkout repository
29+
uses: actions/checkout@v4
30+
31+
- name: Pack with Rockcraft
32+
uses: canonical/craft-actions/rockcraft-pack@main
33+
id: rockcraft
34+
35+
- name: Upload Rock Artifact
36+
uses: actions/upload-artifact@v4
37+
with:
38+
name: cups-rock
39+
path: ${{ steps.rockcraft.outputs.rock }}
40+
41+
publish-rock:
42+
needs: build-rock
43+
if: github.ref_name == 'main' || github.ref_name == 'master'
44+
runs-on: ubuntu-latest
45+
steps:
46+
- name: Checkout repository
47+
uses: actions/checkout@v4
48+
49+
- name: Download Rock Artifact
50+
uses: actions/download-artifact@v4
51+
with:
52+
name: cups-rock
53+
54+
- name: Install Dependencies
55+
run: |
56+
sudo snap install rockcraft --classic
57+
sudo snap install docker
58+
sudo snap install yq
59+
60+
- name: Ensure Docker Daemon is Running
61+
run: |
62+
sudo systemctl start docker
63+
sudo systemctl enable docker
64+
sudo systemctl is-active --quiet docker || sudo systemctl start docker
65+
66+
# - name: Log in to Docker Hub
67+
# uses: docker/login-action@v3.2.0
68+
# with:
69+
# username: ${{ secrets.DOCKER_USERNAME }}
70+
# password: ${{ secrets.DOCKER_PASSWORD }}
71+
72+
- name: Log in to GitHub Packages
73+
uses: docker/login-action@v3.2.0
74+
with:
75+
registry: ghcr.io
76+
username: ${{ github.actor }}
77+
password: ${{ secrets.GITHUB_TOKEN }}
78+
79+
- name: Build and Push Docker Image (Edge & Latest Channel)
80+
if: github.event.inputs.workflow_choice == 'edge' || github.event.inputs.workflow_choice == 'both' || github.event_name == 'push' || github.event_name == 'workflow_run'
81+
env:
82+
USERNAME: ${{ secrets.DOCKER_USERNAME }}
83+
run: |
84+
IMAGE="$(yq '.name' rockcraft.yaml)"
85+
VERSION="$(yq '.version' rockcraft.yaml)"
86+
ROCK="$(ls *.rock | tail -n 1)"
87+
sudo rockcraft.skopeo --insecure-policy copy oci-archive:"${ROCK}" docker-daemon:"${USERNAME}/${IMAGE}:${VERSION}-edge"
88+
# Push to Docker Hub
89+
# docker push ${USERNAME}/${IMAGE}:${VERSION}-edge
90+
# docker tag ${USERNAME}/${IMAGE}:${VERSION}-edge ${USERNAME}/${IMAGE}:latest
91+
# docker push ${USERNAME}/${IMAGE}:latest
92+
# Push to GitHub Packages
93+
GITHUB_IMAGE="ghcr.io/${{ github.repository_owner }}/${IMAGE}"
94+
docker tag ${USERNAME}/${IMAGE}:${VERSION}-edge ${GITHUB_IMAGE}:${VERSION}-edge
95+
docker push ${GITHUB_IMAGE}:${VERSION}-edge
96+
docker tag ${GITHUB_IMAGE}:${VERSION}-edge ${GITHUB_IMAGE}:latest
97+
docker push ${GITHUB_IMAGE}:latest
98+
99+
- name: Build and Push Docker Image (Stable Channel)
100+
if: github.event.inputs.workflow_choice == 'stable' || github.event.inputs.workflow_choice == 'both'
101+
env:
102+
USERNAME: ${{ secrets.DOCKER_USERNAME }}
103+
run: |
104+
IMAGE="$(yq '.name' rockcraft.yaml)"
105+
VERSION="$(yq '.version' rockcraft.yaml)"
106+
ROCK="$(ls *.rock | tail -n 1)"
107+
sudo rockcraft.skopeo --insecure-policy copy oci-archive:"${ROCK}" docker-daemon:"${USERNAME}/${IMAGE}:${VERSION}-stable"
108+
# Push to Docker Hub
109+
# docker push ${USERNAME}/${IMAGE}:${VERSION}-stable
110+
# Push to GitHub Packages
111+
GITHUB_IMAGE="ghcr.io/${{ github.repository_owner }}/${IMAGE}"
112+
docker tag ${USERNAME}/${IMAGE}:${VERSION}-stable ${GITHUB_IMAGE}:${VERSION}-stable
113+
docker push ${GITHUB_IMAGE}:${VERSION}-stable

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
*.snap
2+
*.rock
3+
.DS_Store

README.md

+89-1
Original file line numberDiff line numberDiff line change
@@ -249,8 +249,96 @@ new rules).
249249
You can edit the `/var/snap/hplip-printer-app/common/cups/snmp.conf`
250250
file for configuring SNMP network printer discovery.
251251

252+
## THE ROCK (OCI CONTAINER IMAGE)
252253

253-
## BUILDING WITHOUT SNAP
254+
### Install from Docker Hub
255+
#### Prerequisites
256+
257+
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).
258+
259+
#### Step-by-Step Guide
260+
261+
The first step is to pull the hplip-printer-app Docker image from Docker Hub.
262+
```sh
263+
sudo docker pull openprinting/hplip-printer-app
264+
```
265+
266+
Run the following Docker command to run the hplip-printer-app image:
267+
```sh
268+
sudo docker run --rm -d \
269+
--name hplip-printer-app \
270+
--network host \
271+
-e PORT=<port> \
272+
openprinting/hplip-printer-app:latest
273+
```
274+
- `PORT` is an optional environment variable used to start the printer-app on a specified port. If not provided, it will start on the default port 8000 or, if port 8000 is busy, on 8001 and so on.
275+
- **The container must be started in `--network host` mode** to allow the Printer-Application instance inside the container to access and discover printers available in the local network where the host system is in.
276+
- Alternatively using the internal network of the Docker instance (`-p <port>:8000` instead of `--network host -e PORT=<port>`) only gives access to local printers running on the host system itself.
277+
278+
### Setting Up and Running hplip-printer-app locally
279+
280+
#### Prerequisites
281+
282+
**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:
283+
```sh
284+
sudo snap install docker
285+
```
286+
287+
**Rockcraft**: Rockcraft should be installed. You can install Rockcraft using the following command:
288+
```sh
289+
sudo snap install rockcraft --classic
290+
```
291+
292+
**Skopeo**: Skopeo should be installed to compile `*.rock` files into Docker images. It comes bundled with Rockcraft, so no separate installation is required.
293+
294+
#### Step-by-Step Guide
295+
296+
**Build hplip-printer-app rock**
297+
298+
The first step is to build the Rock from the `rockcraft.yaml`. This image will contain all the configurations and dependencies required to run hplip-printer-app.
299+
300+
Open your terminal and navigate to the directory containing your `rockcraft.yaml`, then run the following command:
301+
302+
```sh
303+
rockcraft pack -v
304+
```
305+
306+
**Compile to Docker Image**
307+
308+
Once the rock is built, you need to compile docker image from it.
309+
310+
```sh
311+
sudo rockcraft.skopeo --insecure-policy copy oci-archive:<rock_image> docker-daemon:hplip-printer-app:latest
312+
```
313+
314+
**Run the hplip-printer-app Docker Container**
315+
316+
```sh
317+
sudo docker run --rm -d \
318+
--name hplip-printer-app \
319+
--network host \
320+
-e PORT=<port> \
321+
hplip-printer-app:latest
322+
```
323+
- `PORT` is an optional environment variable used to start the printer-app on a specified port. If not provided, it will start on the default port 8000 or, if port 8000 is busy, on 8001 and so on.
324+
- **The container must be started in `--network host` mode** to allow the Printer-Application instance inside the container to access and discover printers available in the local network where the host system is in.
325+
- Alternatively using the internal network of the Docker instance (`-p <port>:8000` instead of `--network host -e PORT=<port>`) only gives access to local printers running on the host system itself.
326+
327+
#### Setting up
328+
329+
Enter the web interface
330+
331+
```sh
332+
http://localhost:<port>/
333+
```
334+
335+
Use the web interface to add a printer. Supply a name, select the
336+
discovered printer, then select make and model. Also set the installed
337+
accessories, loaded media and the option defaults. If the printer is a
338+
PostScript printer, accessory configuration and option defaults can
339+
also often get polled from the printer.
340+
341+
## BUILDING WITHOUT PACKAGING OR INSTALLATION
254342

255343
You can also do a "quick-and-dirty" build without snapping and without
256344
needing to install [PAPPL](https://www.msweet.org/pappl),

0 commit comments

Comments
 (0)