Debian Codegraph @

.github/workflows/registry-actions.yml

raw
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/[email protected]
70 # with:
71 # username: ${{ secrets.DOCKER_USERNAME }}
72 # password: ${{ secrets.DOCKER_PASSWORD }}
73
74 - name: Log in to GitHub Packages
75 uses: docker/[email protected]
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 ORG: ${{ github.repository_owner }}
86 run: |
87 IMAGE="$(yq '.name' rock/rockcraft.yaml)"
88 VERSION="$(yq '.version' rock/rockcraft.yaml)"
89 ROCK="$(ls *.rock | tail -n 1)"
90 ORG_NAME=$(echo "${ORG}" | tr '[:upper:]' '[:lower:]')
91 sudo rockcraft.skopeo --insecure-policy copy oci-archive:"${ROCK}" docker-daemon:"${ORG_NAME}/${IMAGE}:${VERSION}-edge"
92 # Push to Docker Hub
93 # docker tag ${ORG_NAME}/${IMAGE}:${VERSION}-edge ${USERNAME}:${VERSION}-edge
94 # docker push ${USERNAME}/${IMAGE}:${VERSION}-edge
95 # docker tag ${USERNAME}/${IMAGE}:${VERSION}-edge ${USERNAME}/${IMAGE}:latest
96 # docker push ${USERNAME}/${IMAGE}:latest
97 # Push to GitHub Packages
98 GITHUB_IMAGE="ghcr.io/${ORG_NAME}/${IMAGE}"
99 docker tag ${ORG_NAME}/${IMAGE}:${VERSION}-edge ${GITHUB_IMAGE}:${VERSION}-edge
100 docker push ${GITHUB_IMAGE}:${VERSION}-edge
101 docker tag ${GITHUB_IMAGE}:${VERSION}-edge ${GITHUB_IMAGE}:latest
102 docker push ${GITHUB_IMAGE}:latest
103
104 - name: Build and Push Docker Image (Stable Channel)
105 if: github.event.inputs.workflow_choice == 'stable' || github.event.inputs.workflow_choice == 'both'
106 env:
107 USERNAME: ${{ secrets.DOCKER_USERNAME }}
108 ORG: ${{ github.repository_owner }}
109 run: |
110 IMAGE="$(yq '.name' rock/rockcraft.yaml)"
111 VERSION="$(yq '.version' rock/rockcraft.yaml)"
112 ROCK="$(ls *.rock | tail -n 1)"
113 ORG_NAME=$(echo "${ORG}" | tr '[:upper:]' '[:lower:]')
114 sudo rockcraft.skopeo --insecure-policy copy oci-archive:"${ROCK}" docker-daemon:"${ORG_NAME}/${IMAGE}:${VERSION}-stable"
115 # Push to Docker Hub
116 # docker tag ${ORG_NAME}/${IMAGE}:${VERSION}-stable ${USERNAME}:${VERSION}-stable
117 # docker push ${USERNAME}/${IMAGE}:${VERSION}-stable
118 # Push to GitHub Packages
119 GITHUB_IMAGE="ghcr.io/${ORG_NAME}/${IMAGE}"
120 docker tag ${ORG_NAME}/${IMAGE}:${VERSION}-stable ${GITHUB_IMAGE}:${VERSION}-stable
121 docker push ${GITHUB_IMAGE}:${VERSION}-stable
122