forked from OpenPrinting/ghostscript-printer-app
-
Notifications
You must be signed in to change notification settings - Fork 0
169 lines (155 loc) · 6.7 KB
/
registry-actions.yml
File metadata and controls
169 lines (155 loc) · 6.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
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:
strategy:
matrix:
include:
- arch: 'amd64'
runner: ubuntu-22.04
- arch: 'arm64'
runner: ubuntu-22.04-arm
runs-on: ${{ matrix.runner }}
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-${{ matrix.arch }}
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:
pattern: cups-rock-*
merge-multiple: true
- 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' rockcraft.yaml)"
VERSION="$(yq '.version' rockcraft.yaml)"
ORG_NAME=$(echo "${ORG}" | tr '[:upper:]' '[:lower:]')
GITHUB_IMAGE="ghcr.io/${ORG_NAME}/${IMAGE}"
# Upload each rock to the container registry
declare -a digests=()
for rock in *.rock; do
echo "Create container from ${rock}"
digest=$(rockcraft.skopeo --insecure-policy inspect "oci-archive:${rock}" --format "{{ .Digest }}")
echo "Digest: ${digest}"
digests+=($digest)
ARCH=$(rockcraft.skopeo --insecure-policy inspect "oci-archive:${rock}" --format "{{ .Architecture }}")
echo "Architecture: ${ARCH}"
rockcraft.skopeo --insecure-policy copy oci-archive:${rock} "docker-daemon:${ORG_NAME}/${IMAGE}:${VERSION}-${ARCH}-edge"
# Push to Docker Hub
# docker tag ${ORG_NAME}/${IMAGE}:${VERSION}-${ARCH}-edge ${USERNAME}:${VERSION}-${ARCH}-edge
# docker push ${USERNAME}/${IMAGE}:${VERSION}-${ARCH}-edge
# Push to GitHub Packages
docker tag ${ORG_NAME}/${IMAGE}:${VERSION}-${ARCH}-edge ${GITHUB_IMAGE}:${VERSION}-${ARCH}-edge
docker push ${GITHUB_IMAGE}:${VERSION}-${ARCH}-edge
done
# Create and upload a multi-arch manifest for Docker Hub
# args=("manifest" "create" "${ORG_NAME}/${IMAGE}:${VERSION}-edge")
# for digest in "${digests[@]}"; do
# args+=("${ORG_NAME}/${IMAGE}@${digest}")
# done
# echo "create multi-arch container with args: ${args[@]}"
# docker "${args[@]}"
# 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
# Create and upload a multi-arch manifest for Github Packages
args=("manifest" "create" "${GITHUB_IMAGE}:${VERSION}-edge")
for digest in "${digests[@]}"; do
args+=("${GITHUB_IMAGE}@${digest}")
done
echo "create multi-arch container with args: ${args[@]}"
docker "${args[@]}"
# Push to GitHub Packages
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' rockcraft.yaml)"
VERSION="$(yq '.version' rockcraft.yaml)"
ORG_NAME=$(echo "${ORG}" | tr '[:upper:]' '[:lower:]')
# Upload each rock to the container registry
declare -a digests=()
for rock in *.rock; do
digest=$(rockcraft.skopeo --insecure-policy inspect "oci-archive:${rock}" --format "{{ .Digest }}")
digests+=($digest)
rockcraft.skopeo --insecure-policy copy oci-archive:${rock} "docker://${ORG_NAME}/${IMAGE}@${digest}"
done
# Create and upload a multi-arch manifest
args=("manifest" "create" "--insecure" "${ORG_NAME}/${IMAGE}:${VERSION}-stable")
for digest in "${digests[@]}"; do
args+=(--amend "${ORG_NAME}/${IMAGE}@${digest}")
done
docker "${args[@]}"
# 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