Skip to content

Commit c18ac38

Browse files
authored
Add rockcraft support for ipp-usb (#94)
Add support for building an OCI container image of ipp-usb which can be run with docker.
1 parent c7b05f1 commit c18ac38

8 files changed

Lines changed: 488 additions & 1 deletion

File tree

.github/workflows/auto-update.yml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
name: Push new tag update to stable branch
2+
3+
on:
4+
schedule:
5+
- cron: '9 7 * * *'
6+
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
17+
18+
jobs:
19+
update-yamls:
20+
runs-on: ubuntu-latest
21+
steps:
22+
- name: Checkout this repo
23+
uses: actions/checkout@v3
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' }}
27+
uses: ubuntu/desktop-snaps@stable
28+
with:
29+
token: ${{ secrets.GITHUB_TOKEN }}
30+
repo: ${{ github.repository }}
31+
yaml-path: 'snap/snapcraft.yaml'
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+
yaml-path: 'rock/rockcraft.yaml'
40+
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
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+
with:
35+
path: rock
36+
37+
- name: Upload Rock Artifact
38+
uses: actions/upload-artifact@v4
39+
with:
40+
name: ipp-usb-rock
41+
path: ${{ steps.rockcraft.outputs.rock }}
42+
43+
publish-rock:
44+
needs: build-rock
45+
if: github.ref_name == 'main'|| github.ref_name == 'master'
46+
runs-on: ubuntu-latest
47+
steps:
48+
- name: Checkout repository
49+
uses: actions/checkout@v4
50+
51+
- name: Download Rock Artifact
52+
uses: actions/download-artifact@v4
53+
with:
54+
name: ipp-usb-rock
55+
56+
- name: Install Dependencies
57+
run: |
58+
sudo snap install rockcraft --classic
59+
sudo snap install docker
60+
sudo snap install yq
61+
62+
- name: Ensure Docker Daemon is Running
63+
run: |
64+
sudo systemctl start docker
65+
sudo systemctl enable docker
66+
sudo systemctl is-active --quiet docker || sudo systemctl start docker
67+
68+
#- name: Log in to Docker Hub
69+
# uses: docker/login-action@v3.2.0
70+
# with:
71+
# username: ${{ secrets.DOCKER_USERNAME }}
72+
# password: ${{ secrets.DOCKER_PASSWORD }}
73+
74+
- name: Log in to GitHub Packages
75+
uses: docker/login-action@v3.2.0
76+
with:
77+
registry: ghcr.io
78+
username: ${{ github.actor }}
79+
password: ${{ secrets.GITHUB_TOKEN }}
80+
81+
- name: Build and Push Docker Image (Edge & Latest Channel)
82+
if: github.event.inputs.workflow_choice == 'edge' || github.event.inputs.workflow_choice == 'both' || github.event_name == 'push' || github.event_name == 'workflow_run'
83+
env:
84+
USERNAME: ${{ secrets.DOCKER_USERNAME }}
85+
run: |
86+
IMAGE="$(yq '.name' rock/rockcraft.yaml)"
87+
VERSION="$(yq '.version' rock/rockcraft.yaml)"
88+
ROCK="$(ls *.rock | tail -n 1)"
89+
# Push to Docker Hub
90+
sudo rockcraft.skopeo --insecure-policy copy oci-archive:"${ROCK}" docker-daemon:"${USERNAME}/${IMAGE}:${VERSION}-edge"
91+
docker push ${USERNAME}/${IMAGE}:${VERSION}-edge
92+
docker tag ${USERNAME}/${IMAGE}:${VERSION}-edge ${USERNAME}/${IMAGE}:latest
93+
docker push ${USERNAME}/${IMAGE}:latest
94+
# Push to GitHub Packages
95+
GITHUB_IMAGE="ghcr.io/${{ github.repository_owner }}/${IMAGE}"
96+
docker tag ${USERNAME}/${IMAGE}:${VERSION}-edge ${GITHUB_IMAGE}:${VERSION}-edge
97+
docker push ${GITHUB_IMAGE}:${VERSION}-edge
98+
docker tag ${GITHUB_IMAGE}:${VERSION}-edge ${GITHUB_IMAGE}:latest
99+
docker push ${GITHUB_IMAGE}:latest
100+
101+
- name: Build and Push Docker Image (Stable Channel)
102+
if: github.event.inputs.workflow_choice == 'stable' || github.event.inputs.workflow_choice == 'both'
103+
env:
104+
USERNAME: ${{ secrets.DOCKER_USERNAME }}
105+
run: |
106+
IMAGE="$(yq '.name' rock/rockcraft.yaml)"
107+
VERSION="$(yq '.version' rock/rockcraft.yaml)"
108+
ROCK="$(ls *.rock | tail -n 1)"
109+
# Push to Docker Hub
110+
sudo rockcraft.skopeo --insecure-policy copy oci-archive:"${ROCK}" docker-daemon:"${USERNAME}/${IMAGE}:${VERSION}-stable"
111+
docker push ${USERNAME}/${IMAGE}:${VERSION}-stable
112+
# Push to GitHub Packages
113+
GITHUB_IMAGE="ghcr.io/${{ github.repository_owner }}/${IMAGE}"
114+
docker tag ${USERNAME}/${IMAGE}:${VERSION}-stable ${GITHUB_IMAGE}:${VERSION}-stable
115+
docker push ${GITHUB_IMAGE}:${VERSION}-stable

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,5 @@ ipp-usb
22
tags
33
*.swp
44
*.orig
5+
*.rock
6+

README.md

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,111 @@ trigger" to find the already passed appearal event of a device which
225225
is already present. So the shell script is an auxiliary daemon to
226226
start ipp-usb when needed.
227227

228+
## The ipp-usb Rock
229+
230+
### Install from GitHub Container Registry
231+
#### Prerequisites
232+
233+
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).
234+
```sh
235+
sudo snap install docker
236+
```
237+
238+
#### Step-by-Step Guide
239+
240+
You can pull the `ipp-usb` Docker image from the GitHub Container Registry.
241+
242+
**From GitHub Container Registry** <br>
243+
To pull the image from the GitHub Container Registry, run the following command:
244+
```sh
245+
sudo docker pull ghcr.io/openprinting/ipp-usb:latest
246+
```
247+
248+
To run the container after pulling the image, use:
249+
```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+
```
256+
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).
260+
261+
To check the logs of `ipp-usb`, run:
262+
```sh
263+
sudo docker logs -f ipp-usb
264+
```
265+
266+
### Building and Running `ipp-usb` Locally
267+
268+
#### Prerequisites
269+
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:
271+
```sh
272+
sudo snap install docker
273+
```
274+
275+
**Rockcraft**: Rockcraft should be installed. You can install Rockcraft using the following command:
276+
```sh
277+
sudo snap install rockcraft --classic
278+
```
279+
280+
#### Step-by-Step Guide
281+
282+
**Build the `ipp-usb` Rock Image**
283+
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`.
285+
286+
Navigate to the directory containing `rockcraft.yaml`, then run:
287+
```sh
288+
rockcraft pack -v
289+
```
290+
291+
**Compile to Docker Image**
292+
293+
Once the `.rock` file is built, compile a Docker image from it using:
294+
```sh
295+
sudo rockcraft.skopeo --insecure-policy copy oci-archive:<rock_image_name> docker-daemon:ipp-usb:latest
296+
```
297+
298+
**Run the `ipp-usb` Docker Container**
299+
300+
```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
306+
```
307+
308+
### Accessing the Container Shell
309+
310+
To enter the running `ipp-usb` container and access a shell inside it, use:
311+
```sh
312+
sudo docker exec -it ipp-usb bash
313+
```
314+
This allows you to inspect logs, debug issues, or manually run commands inside the container.
315+
316+
### Configuration
317+
318+
The `ipp-usb` container uses a configuration file located at:
319+
```
320+
/etc/ipp-usb.conf
321+
```
322+
To customize the configuration, mount a modified config file:
323+
```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-container \
329+
ghcr.io/openprinting/ipp-usb:latest
330+
```
331+
332+
228333
## Installation from source
229334

230335
You will need to install the following packages (exact name depends

0 commit comments

Comments
 (0)