Skip to content

Commit

Permalink
Build and Deploy OCI Image of ps-printer-app Using Rockcraft (#29)
Browse files Browse the repository at this point in the history
- 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 patch 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
  • Loading branch information
rudra-iitm authored Dec 15, 2024
1 parent e6d6fe3 commit 75f0980
Show file tree
Hide file tree
Showing 10 changed files with 1,032 additions and 7 deletions.
28 changes: 24 additions & 4 deletions .github/workflows/auto-update.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,39 @@ name: Push new tag update to stable branch

on:
schedule:
# Daily for now
- cron: '9 7 * * *'
workflow_dispatch:
inputs:
workflow_choice:
description: "Choose YAML to update"
required: true
default: "both"
type: choice
options:
- snapcraft
- rockcraft
- both

jobs:
update-snapcraft-yaml:
update-yamls:
runs-on: ubuntu-latest
steps:
- name: Checkout this repo
uses: actions/checkout@v3
- name: Run desktop-snaps action

- name: Run desktop-snaps action (Snapcraft)
if: ${{ github.event_name == 'schedule' || github.event.inputs.workflow_choice == 'snapcraft' || github.event.inputs.workflow_choice == 'both' }}
uses: ubuntu/desktop-snaps@stable
with:
token: ${{ secrets.GITHUB_TOKEN }}
repo: ${{ github.repository }}
version-schema: '^(\d{8})'

- name: Run desktop-snaps action (Rockcraft)
if: ${{ github.event_name == 'schedule' || github.event.inputs.workflow_choice == 'rockcraft' || github.event.inputs.workflow_choice == 'both' }}
uses: ubuntu/desktop-snaps@stable
with:
token: ${{ secrets.GITHUB_TOKEN }}
repo: ${{ github.repository }}
version-schema: '^(\d{8})'
rock-version-schema: '^(\d{8})'
yaml-path: 'rockcraft.yaml'
31 changes: 31 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: CI Pipeline for ps-printer-app

on:
push:
branches:
- main
pull_request:
branches:
- main
workflow_dispatch:

jobs:
build-rock:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Pack with Rockcraft
uses: canonical/craft-actions/rockcraft-pack@main
id: rockcraft

build-snap:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Build Snap Package
uses: snapcore/action-build@v1
id: snapcraft
114 changes: 114 additions & 0 deletions .github/workflows/registry-actions.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
name: Pack and Publish OCI Image to Docker Registry and GitHub Packages

on:
push:
branches:
- main
workflow_dispatch:
inputs:
workflow_choice:
description: "Choose Release Channel"
required: true
default: "edge"
type: choice
options:
- edge
- stable
- both
workflow_run:
workflows: ["Push new tag update to stable branch"]
types:
- completed

jobs:
build-rock:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Pack with Rockcraft
uses: canonical/craft-actions/rockcraft-pack@main
id: rockcraft
with:
path: rock

- name: Upload Rock Artifact
uses: actions/upload-artifact@v4
with:
name: cups-rock
path: ${{ steps.rockcraft.outputs.rock }}

publish-rock:
needs: build-rock
if: github.ref_name == 'main'
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Download Rock Artifact
uses: actions/download-artifact@v4
with:
name: cups-rock

- name: Install Dependencies
run: |
sudo snap install rockcraft --classic
sudo snap install docker
sudo snap install yq
- name: Ensure Docker Daemon is Running
run: |
sudo systemctl start docker
sudo systemctl enable docker
sudo systemctl is-active --quiet docker || sudo systemctl start docker
# - name: Log in to Docker Hub
# uses: docker/[email protected]
# with:
# username: ${{ secrets.DOCKER_USERNAME }}
# password: ${{ secrets.DOCKER_PASSWORD }}

- name: Log in to GitHub Packages
uses: docker/[email protected]
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build and Push Docker Image (Edge & Latest Channel)
if: github.event.inputs.workflow_choice == 'edge' || github.event.inputs.workflow_choice == 'both' || github.event_name == 'push' || github.event_name == 'workflow_run'
env:
USERNAME: ${{ secrets.DOCKER_USERNAME }}
run: |
IMAGE="$(yq '.name' rockcraft.yaml)"
VERSION="$(yq '.version' rockcraft.yaml)"
ROCK="$(ls *.rock | tail -n 1)"
sudo rockcraft.skopeo --insecure-policy copy oci-archive:"${ROCK}" docker-daemon:"${USERNAME}/${IMAGE}:${VERSION}-edge"
# Push to Docker Hub
# docker push ${USERNAME}/${IMAGE}:${VERSION}-edge
# docker tag ${USERNAME}/${IMAGE}:${VERSION}-edge ${USERNAME}/${IMAGE}:latest
# docker push ${USERNAME}/${IMAGE}:latest
# Push to GitHub Packages
GITHUB_IMAGE="ghcr.io/${{ github.repository_owner }}/${IMAGE}"
docker tag ${USERNAME}/${IMAGE}:${VERSION}-edge ${GITHUB_IMAGE}:${VERSION}-edge
docker push ${GITHUB_IMAGE}:${VERSION}-edge
docker tag ${GITHUB_IMAGE}:${VERSION}-edge ${GITHUB_IMAGE}:latest
docker push ${GITHUB_IMAGE}:latest
- name: Build and Push Docker Image (Stable Channel)
if: github.event.inputs.workflow_choice == 'stable' || github.event.inputs.workflow_choice == 'both'
env:
USERNAME: ${{ secrets.DOCKER_USERNAME }}
run: |
IMAGE="$(yq '.name' rockcraft.yaml)"
VERSION="$(yq '.version' rockcraft.yaml)"
ROCK="$(ls *.rock | tail -n 1)"
sudo rockcraft.skopeo --insecure-policy copy oci-archive:"${ROCK}" docker-daemon:"${USERNAME}/${IMAGE}:${VERSION}-stable"
# Push to Docker Hub
# docker push ${USERNAME}/${IMAGE}:${VERSION}-stable
# Push to GitHub Packages
GITHUB_IMAGE="ghcr.io/${{ github.repository_owner }}/${IMAGE}"
docker tag ${USERNAME}/${IMAGE}:${VERSION}-stable ${GITHUB_IMAGE}:${VERSION}-stable
docker push ${GITHUB_IMAGE}:${VERSION}-stable
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*.rock
.DS_Store
88 changes: 86 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -293,8 +293,93 @@ new rules).
You can edit the `/var/snap/ps-printer-app/common/cups/snmp.conf` file
for configuring SNMP network printer discovery.

## THE ROCK (OCI CONTAINER IMAGE)

## BUILDING WITHOUT SNAP
### Install from DockerHub

#### Prerequisites

**Docker Installed**: Ensure Docker is installed on your system. You can download it from the [official Docker website](https://www.docker.com/get-started).

#### Step-by-Step Guide

The first step is to pull the ps-printer-app Docker image from DockerHub:
```
sudo docker pull openprinting/ps-printer-app
```

Then run the following Docker command to run the ps-printer-app image in a container:
```sh
sudo docker run --rm -d \
--name ps-printer-app \
--network host \
-e PORT:<port> \
openprinting/ps-printer-app:latest
```
- `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.
- **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.
- 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.

### Setting up and running a ps-printer-app container locally

#### Prerequisites

**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:
```
sudo snap install docker
```

**Rockcraft**: Rockcraft should be installed. You can install Rockcraft using the following command:
```
sudo snap install rockcraft --classic
```

**Skopeo**: Skopeo should be installed to compile `*.rock` files into Docker images. It comes bundled with Rockcraft, so no separate installation is required.

#### Step-by-Step Guide

**Build the ps-printer-app Rock**

The first step is to build the Rock from the `rockcraft.yaml`. This image will contain all the configurations and dependencies required to run ps-printer-app.

Open your terminal and navigate to the directory containing your `rockcraft.yaml` (base directory of this package), then run the following command:
```
rockcraft pack -v
```

**Compile to Docker image**

Once the rock is built, you need to compile a docker image from it:
```
sudo rockcraft.skopeo --insecure-policy copy oci-archive:<rock_image> docker-daemon:ps-printer-app:latest
```

**Run the ps-printer-app Docker Container**

```sh
sudo docker run --rm -d \
--name ps-printer-app \
--network host \
-e PORT:<port> \
ps-printer-app:latest
```
- `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.
- **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.
- 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.

#### Setting up

Enter the web interface:
```
http://localhost:<port>/
```
Use the web interface to add a printer. Supply a name, select the
discovered printer, then select automatic driver selection or choose a
make and model. Also set the installed accessories, loaded media and
the option defaults. Accessory configuration and option defaults can
also often get polled from the printer.

## BUILDING WITHOUT PACKAGING OR INSTALLATION

You can also do a "quick-and-dirty" build without snapping and without
needing to install [PAPPL](https://www.msweet.org/pappl),
Expand Down Expand Up @@ -371,7 +456,6 @@ Apple Raster, PWG Raster):
TESTPAGE=/path/to/my/testpage/my_testpage.ps PPD_PATHS=/path/to/my/ppds:/my/second/place ./ps-printer-app server
```


## LEGAL STUFF

The PostScript Printer Application is Copyright © 2020 by Till Kamppeter.
Expand Down
Loading

0 comments on commit 75f0980

Please sign in to comment.