Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build and Deploy OCI Image of hplip-printer-app Using Rockcraft #21

Merged
merged 14 commits into from
Dec 15, 2024
Merged
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
27 changes: 23 additions & 4 deletions .github/workflows/auto-update.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +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: '^debian/(\d+\.\d+\.\d+)'


- 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 }}
rock-version-schema: '^debian/(\d+\.\d+\.\d+)'
yaml-path: 'rockcraft.yaml'
33 changes: 33 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: CI Pipeline for hplip-printer-app

on:
push:
branches:
- main
- master
pull_request:
branches:
- main
- master
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
113 changes: 113 additions & 0 deletions .github/workflows/registry-actions.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
name: Pack and Publish OCI Image to Docker Registry and GitHub Packages

on:
push:
branches:
- main
- master
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

- 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' || github.ref_name == 'master'
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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*.snap
*.rock
.DS_Store
90 changes: 89 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -249,8 +249,96 @@ new rules).
You can edit the `/var/snap/hplip-printer-app/common/cups/snmp.conf`
file for configuring SNMP network printer discovery.

## THE ROCK (OCI CONTAINER IMAGE)

## BUILDING WITHOUT SNAP
### Install from Docker Hub
#### Prerequisites

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).

#### Step-by-Step Guide

The first step is to pull the hplip-printer-app Docker image from Docker Hub.
```sh
sudo docker pull openprinting/hplip-printer-app
```

Run the following Docker command to run the hplip-printer-app image:
```sh
sudo docker run --rm -d \
--name hplip-printer-app \
--network host \
-e PORT=<port> \
openprinting/hplip-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 hplip-printer-app 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:
```sh
sudo snap install docker
```

**Rockcraft**: Rockcraft should be installed. You can install Rockcraft using the following command:
```sh
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 hplip-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 hplip-printer-app.

Open your terminal and navigate to the directory containing your `rockcraft.yaml`, then run the following command:

```sh
rockcraft pack -v
```

**Compile to Docker Image**

Once the rock is built, you need to compile docker image from it.

```sh
sudo rockcraft.skopeo --insecure-policy copy oci-archive:<rock_image> docker-daemon:hplip-printer-app:latest
```

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

```sh
sudo docker run --rm -d \
--name hplip-printer-app \
--network host \
-e PORT=<port> \
hplip-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

```sh
http://localhost:<port>/
```

Use the web interface to add a printer. Supply a name, select the
discovered printer, then select make and model. Also set the installed
accessories, loaded media and the option defaults. If the printer is a
PostScript printer, 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
Loading
Loading