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

Introduces CUPS Packaging with Snapcraft and Rockcraft #1137

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
42 changes: 42 additions & 0 deletions .github/workflows/auto-update.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: Push new tag update to stable branch

on:
schedule:
- 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-yamls:
runs-on: ubuntu-latest
steps:
- name: Checkout this repo
uses: actions/checkout@v3

- 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: 'v(\d+\.\d+\.\d+)'
yaml-path: 'packaging/snapcraft.yaml'

- 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: 'v(\d+\.\d+\.\d+)'
yaml-path: 'packaging/rockcraft.yaml'
readme-path: packaging/README.md
146 changes: 146 additions & 0 deletions .github/workflows/packages-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
name: CI Pipeline for Containerized CUPS

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

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

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

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

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
with:
path: packaging

test:
needs: build-rock
if: github.ref == 'refs/heads/main' || github.ref == 'refs/heads/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 for Testing
run: |
sudo snap install rockcraft --classic
sudo snap install docker
sudo apt-get update
sudo apt-get install -y avahi-utils
sudo apt-get install -y curl cups-ipp-utils cups-client screen

- name: Ensure Docker Daemon is Running
run: |
# Start and enable Docker daemon if not already active
sudo systemctl start docker
sudo systemctl enable docker
sudo systemctl is-active --quiet docker || sudo systemctl start docker

- name: Build Docker Image
run: |
# Build Docker image from the latest .rock artifact
ROCK="$(ls *.rock | tail -n 1)"
sudo rockcraft.skopeo --insecure-policy copy oci-archive:"${ROCK}" docker-daemon:cups:latest

- name: Run CUPS container
env:
CUPS_ADMIN: "print"
CUPS_PASSWORD: "print"
run: |
# Run CUPS container with environment variables for admin credentials
sudo docker run --rm -d --name cups -p 8080:631 \
-e CUPS_ADMIN="${CUPS_ADMIN}" -e CUPS_PASSWORD="${CUPS_PASSWORD}" \
cups:latest

- name: Wait for CUPS to be ready
run: |
# Wait until CUPS server is ready to accept connections
until curl -s http://localhost:8080 | grep -q 'CUPS'; do
echo "Waiting for CUPS..."
sleep 5
done

- name: Start ippeveprinter
run: |
# Start the ippeveprinter service for printing
screen -S ippeveprinter-session -d -m /usr/sbin/ippeveprinter -f application/pdf myprinter
sleep 10

- name: Add CUPS printer
env:
CUPS_ADMIN: "print"
run: |
# Add a test printer to the CUPS server
sudo docker exec -u "${CUPS_ADMIN}" cups lpadmin -p testprinter \
-v ipps://myprinter._ipps._tcp.local/ -E -m everywhere

- name: Test printing files
env:
CUPS_ADMIN: "print"
run: |
# Test printing a file from the host to the CUPS server
echo "Test Print Job" | sudo tee host-testfile.txt > /dev/null
CUPS_SERVER=localhost:8080 lp -d testprinter host-testfile.txt

# Wait for the final print job to complete
until CUPS_SERVER=localhost:8080 lpstat -W completed | grep -q 'testprinter-1'; do
echo "Waiting for print job 1 to complete..."
sleep 5
done
CUPS_SERVER=localhost:8080 lpstat -W completed | grep 'testprinter-1'

# Test printing multiple file types from inside container and wait for completion
testfiles=(
"/share/cups/ipptool/testfile.txt"
"/share/cups/ipptool/testfile.pdf"
"/share/cups/ipptool/testfile.jpg"
"/share/cups/ipptool/testfile.ps"
"/share/cups/ipptool/testfile.pcl"
)

for i in "${!testfiles[@]}"; do
sudo docker exec -u "${CUPS_ADMIN}" cups lp -d testprinter "${testfiles[i]}"
until sudo docker exec -u "${CUPS_ADMIN}" cups lpstat -W completed | grep -q "testprinter-$((i+2))"; do
echo "Waiting for print job $((i+2)) to complete..."
sleep 5
done
sudo docker exec -u "${CUPS_ADMIN}" cups lpstat -W completed | grep "testprinter-$((i+2))"
done

- name: Stop CUPS container
run: |
sudo docker stop cups
121 changes: 121 additions & 0 deletions .github/workflows/registry-actions.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
name: Pack and Publish OCI Image to Docker Registry and GitHub packaging

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-22.04
steps:
- name: Checkout repository
uses: actions/checkout@v4

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

- 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/login-action@v3.2.0
# with:
# username: ${{ secrets.DOCKER_USERNAME }}
# password: ${{ secrets.DOCKER_PASSWORD }}

- name: Log in to GitHub Packages
uses: docker/login-action@v3.2.0
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
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 }}
ORG: ${{ github.repository_owner }}
run: |
IMAGE="$(yq '.name' packaging/rockcraft.yaml)"
VERSION="$(yq '.version' packaging/rockcraft.yaml)"
ROCK="$(ls *.rock | tail -n 1)"
ORG_NAME=$(echo "${ORG}" | tr '[:upper:]' '[:lower:]')
sudo rockcraft.skopeo --insecure-policy copy oci-archive:"${ROCK}" docker-daemon:"${ORG_NAME}/${IMAGE}:${VERSION}-edge"
# Push to Docker Hub
# docker tag ${ORG_NAME}/${IMAGE}:${VERSION}-edge ${USERNAME}:${VERSION}-edge
# 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/${ORG_NAME}/${IMAGE}"
docker tag ${ORG_NAME}/${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 }}
ORG: ${{ github.repository_owner }}
run: |
IMAGE="$(yq '.name' packaging/rockcraft.yaml)"
VERSION="$(yq '.version' packaging/rockcraft.yaml)"
ROCK="$(ls *.rock | tail -n 1)"
ORG_NAME=$(echo "${ORG}" | tr '[:upper:]' '[:lower:]')
sudo rockcraft.skopeo --insecure-policy copy oci-archive:"${ROCK}" docker-daemon:"${ORG_NAME}/${IMAGE}:${VERSION}-stable"
# Push to Docker Hub
# docker tag ${ORG_NAME}/${IMAGE}:${VERSION}-stable ${USERNAME}:${VERSION}-stable
# docker push ${USERNAME}/${IMAGE}:${VERSION}-stable
# Push to GitHub Packages
GITHUB_IMAGE="ghcr.io/${ORG_NAME}/${IMAGE}"
docker tag ${ORG_NAME}/${IMAGE}:${VERSION}-stable ${GITHUB_IMAGE}:${VERSION}-stable
docker push ${GITHUB_IMAGE}:${VERSION}-stable
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -166,3 +166,10 @@
/xcode/CUPS.xcodeproj/xcuserdata/
.DS_store
container-config
packages/parts
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So these should probably have a leading / (for that matter, so should container-config above).

packages/stage
packages/prime
*.snap
*.tar*
packages/snap/.snapcraft
*.rock
Loading
Loading