-
Notifications
You must be signed in to change notification settings - Fork 0
177 lines (161 loc) · 5.96 KB
/
build.yml
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
170
171
172
173
174
175
176
177
name: build-bonito
on:
push:
branches:
- main
paths-ignore:
- '**.md'
- '**.txt'
schedule:
- cron: '0 5 * * *' # 5am UTC everyday (timed against official fedora container pushes)
workflow_dispatch:
env:
SOURCE_IMAGE_REGISTRY: quay.io/fedora-ostree-desktops
TARGET_IMAGE_REGISTRY: ghcr.io/${{ github.repository_owner }}
jobs:
build_bonito:
name: Build and push image
runs-on: ubuntu-24.04
permissions:
contents: read
packages: write
id-token: write
strategy:
fail-fast: false
matrix:
source_image_name:
- sway-atomic
- kinoite
fedora_version: [41]
include:
- fedora_version: 41
is_current_version: true
- source_image_name: sway-atomic
target_image_name: bonito-sway
- source_image_name: kinoite
target_image_name: bonito-kde
steps:
# Checkout push-to-registry action github repository
- name: Checkout Push to Registry action
uses: actions/checkout@v4
- name: Generate path to base image's repository
id: base-image
run: |
echo "path=${{ env.SOURCE_IMAGE_REGISTRY }}/${{ matrix.source_image_name }}" >> $GITHUB_OUTPUT
- name: Generate tags
id: generate-tags
shell: bash
run: |
# Generate a timestamp for creating an image version history
TIMESTAMP="$(date +%Y%m%d)"
MAJOR_VERSION="${{ matrix.fedora_version }}"
BUILD_TAGS=("${MAJOR_VERSION}" "${MAJOR_VERSION}-${TIMESTAMP}")
if [[ "${{ matrix.is_current_version }}" == "true" ]]; then
BUILD_TAGS+=("latest")
fi
echo "Generated the following build tags: "
for TAG in "${BUILD_TAGS[@]}"; do
echo "${TAG}"
done
echo "tags=${BUILD_TAGS[*]}" >> $GITHUB_OUTPUT
- name: Get base image version
id: labels
uses: Wandalen/[email protected]
with:
attempt_limit: 3
attempt_delay: 15000
command: |
set -eo pipefail
ver=$(skopeo inspect docker://${{ steps.base-image.outputs.path }}:${{ matrix.fedora_version }} | jq -r '.Labels["org.opencontainers.image.version"]')
if [ -z "$ver" ] || [ "null" = "$ver" ]; then
echo "inspected image version must not be empty or null"
exit 1
fi
echo "base_image_version=$ver" >> $GITHUB_OUTPUT
- name: Pull base image
uses: Wandalen/[email protected]
with:
attempt_limit: 3
attempt_delay: 15000
command: |
# pull the base image used for FROM in containerfile so
# we can retry on that unfortunately common failure case
podman pull ${{ steps.base-image.outputs.path }}:${{ matrix.fedora_version }}
# Generate image metadata
- name: Image Metadata
uses: docker/metadata-action@v5
id: meta
with:
images: |
${{ matrix.target_image_name }}
labels: |
org.opencontainers.image.title=${{ matrix.target_image_name }}
org.opencontainers.image.version=${{ steps.labels.outputs.outputs && fromJSON(steps.labels.outputs.outputs).base_image_version }}
org.opencontainers.image.description=A Universal Blue ${{ matrix.target_image_name }} image customized by ryanpz
io.artifacthub.package.readme-url=https://raw.githubusercontent.com/${{ github.repository }}/main/README.md
io.artifacthub.package.logo-url=https://avatars.githubusercontent.com/u/23235374?v=4
# Build image using Buildah action
- name: Build Image
id: build-image
uses: redhat-actions/buildah-build@v2
with:
containerfiles: |
./Containerfile
image: ${{ matrix.target_image_name }}
tags: |
${{ steps.generate-tags.outputs.tags }}
build-args: |
SOURCE_IMAGE_NAME=${{ matrix.source_image_name }}
SOURCE_IMAGE_TAG=${{ matrix.fedora_version }}
SOURCE_IMAGE=${{ steps.base-image.outputs.path }}
labels: ${{ steps.meta.outputs.labels }}
oci: false
- name: Push To GHCR
uses: Wandalen/[email protected]
id: push
env:
REGISTRY_USER: ${{ github.actor }}
REGISTRY_PASSWORD: ${{ github.token }}
with:
action: redhat-actions/push-to-registry@v2
attempt_limit: 3
attempt_delay: 15000
with: |
image: ${{ steps.build-image.outputs.image }}
tags: ${{ steps.build-image.outputs.tags }}
registry: ${{ env.TARGET_IMAGE_REGISTRY }}
username: ${{ env.REGISTRY_USER }}
password: ${{ env.REGISTRY_PASSWORD }}
extra-args: |
--disable-content-trust
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
# Sign container
- uses: sigstore/[email protected]
- name: Sign container image
run: |
cosign sign -y --key env://COSIGN_PRIVATE_KEY ${{ env.TARGET_IMAGE_REGISTRY }}/${{ steps.build-image.outputs.image }}@${TAGS}
env:
TAGS: ${{ steps.push.outputs.outputs && fromJSON(steps.push.outputs.outputs).digest }}
COSIGN_EXPERIMENTAL: false
COSIGN_PRIVATE_KEY: ${{ secrets.SIGNING_SECRET }}
- name: Echo outputs
run: |
echo "${{ toJSON(steps.push.outputs) }}"
check:
name: Check all builds successful
if: ${{ !cancelled() }}
runs-on: ubuntu-latest
needs: [build_bonito]
steps:
- name: Exit on failure
if: ${{ needs.build_bonito.result == 'failure' }}
shell: bash
run: exit 1
- name: Exit
shell: bash
run: exit 0