-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathaction.yml
220 lines (207 loc) · 8.38 KB
/
action.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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
name: 'OCI ReChunker'
description: 'ReChunker allows you to repartition an existing OCI OS image into
a set of equal-sized package bundles, or chunks. Between releases, only
a subset of chunks are updated, reducing bandwidth use, and pulling is faster
due to their larger number.'
inputs:
ref:
description: |
The image reference that will be rechunked. Use any reference
that works under `podman create <ref>`.
required: true
prev-ref:
description: |
The previous image reference, if any. Used for versioning
the current image and to avoid layer shifts (important; may be skipped).
clear-plan:
description: |
If set, a new plan will be recreated.
prev-ref-fail:
description: |
If set, fail if the previous image reference is not found.
max-layers:
description: |
The number of layers (chunks) the output image will have.
skip_compression:
description: |
Skip compression of the output image. Use only if you are
recompressing the output (e.g., zstd:chunked). Saves 3-5min or 30% of runtime.
labels:
description: |
The labels to apply to the output image, e.g.,
`org.opencontainers.image.title=My Image`.
Separate by newline.
description:
description: |
The description of the image. Populates `org.opencontainers.image.description=<description>`.
Can be provided as part of labels instead. However you can use this field
with the | operator for multiline descriptions.
version:
description: |
The version of the image. Populates `org.opencontainers.image.version=<version>`.
If the `prev-ref` image manifest contains the same version, this will be
sufixed with .1, .2, etc.
Use `<date>` for the current date in the format `YYMMDD` (240305).
Example: `3.1_<date>` becomes `3.1_240305`.
default: '<date>'
pretty:
description: |
The pretty version of the image. Can be used as the <pretty> variable to
make substitutions in the labels.
rechunk:
description: |
The rechunker OCI image to use. Cannot use a Dockerfile, as building the
image takes around 5 minutes. Always tag it with the action version.
FIXME: old versions will expire after 90 days, so you might have to fork
this action to your org's page or update every few months.
This is temporary, until the changes to `ostree-rs-ext` are merged and
the upstream version can be used, after which point the Containerfile
will build in seconds.
default: 'ghcr.io/hhd-dev/rechunk:latest'
keep-ref:
description: |
By default, this action will remove the ref image provided in `ref`.
This variable will disable discarding it after the OSTree commit is created.
May cause the storage overflow.
changelog:
description: |
The changelog of the image. Can be substituted with the <changelog> variable
and will be placed
git:
description: |
The git repository to use for the action. Used for versioning the output.
Defaults to the current repository.
revision:
description: |
The revision that will be recorded in the image metadata and in
"org.opencontainers.image.revision". Used for the <commit>
tag along with the git path.
If <commit> is not used, providing it as part of a "org.opencontainers.image.revision"
is the same.
formatters:
description: |
The formatters to use for the changelog. The format is as follows:
```
formatter=<format>
```
Formatter is a string up to the first = and defines the formatter name.
After that and until the end of the line is the format.
Use \n for newlines. Different formatters use different
substitutions (e.g., <name>), refer to the examples for specifics.
You can use the characters `<`, `>`, `=` freely. Substitution is only
performed on exact tag matches.
meta:
description: |
The metadata file to use for the image. Specified as a path.
outputs:
ref:
description: |
The reference of the rechunked image. Will be in the form of `oci:<dir>`,
with dir being the directory of the OCI image, relative to workdir.
value: ${{ steps.rechunk.outputs.ref }}
version:
description: |
The version of the rechunked image to be used as a tag.
value: ${{ steps.rechunk.outputs.version }}
location:
description: |
The filesystem location of the rechunked image, so that it can be removed.
value: ${{ steps.rechunk.outputs.location }}
changelog:
description: |
The changelog of the image, with the <changelog> variable substituted.
value: ${{ steps.rechunk.outputs.changelog }}
manifest:
description: |
The skopeo manifest of the rechunked image.
value: ${{ steps.rechunk.outputs.manifest }}
runs:
using: 'composite'
steps:
- name: Mount Image
id: mount
shell: bash
run: |
CREF=$(sudo podman create ${{ inputs.ref }} bash)
MOUNT=$(sudo podman mount $CREF)
echo "container=$CREF" >> $GITHUB_OUTPUT
echo "mount=$MOUNT" >> $GITHUB_OUTPUT
- name: Create OSTree Commit
shell: bash
run: |
# Pruning
echo Pruning
sudo podman run --rm \
-v "${{ steps.mount.outputs.mount }}":/var/tree \
-e TREE=/var/tree \
-u 0:0 \
${{ inputs.rechunk }} \
/sources/rechunk/1_prune.sh
# OSTree commit
echo Committing to OSTree
sudo podman run --rm \
-v "${{ steps.mount.outputs.mount }}":/var/tree \
-e TREE=/var/tree \
-v "cache_ostree:/var/ostree" \
-e REPO=/var/ostree/repo \
-e RESET_TIMESTAMP=1 \
-u 0:0 \
${{ inputs.rechunk }} \
/sources/rechunk/2_create.sh
# Cleanup and make space
echo Unmounting and removing container
sudo podman unmount ${{ steps.mount.outputs.container }}
sudo podman rm ${{ steps.mount.outputs.container }}
if [ -z "${{ inputs.keep-ref }}" ]; then
sudo podman rmi ${{ inputs.ref }}
fi
- name: Rechunk OSTree Commit
id: rechunk
shell: bash
run: |
OUT_NAME=$(echo ${{ inputs.ref }} | rev | cut -d'/' -f1 | rev | sed 's/:/_/')
GIT_PATH="${{ inputs.git }}"
if [ -z "$GIT_PATH" ]; then
GIT_PATH="${{ github.workspace }}"
fi
# Self hosted runners do not have this
mkdir -p "${{ github.workspace }}"
META_FN="${{ inputs.meta }}"
if [ -n "$META_FN" ]; then
cp "$META_FN" "${{ github.workspace }}/_meta_in.yml"
fi
sudo podman run --rm \
-v "${{ github.workspace }}:/workspace" \
-v "$GIT_PATH:/var/git" \
-v "cache_ostree:/var/ostree" \
-e REPO=/var/ostree/repo \
-e MAX_LAYERS="${{ inputs.max-layers }}" \
-e SKIP_COMPRESSION="${{ inputs.skip_compression }}" \
-e PREV_REF="${{ inputs.prev-ref }}" \
-e OUT_NAME="$OUT_NAME" \
-e LABELS="${{ inputs.labels }}" \
-e FORMATTERS="${{ inputs.formatters }}" \
-e VERSION="${{ inputs.version }}" \
-e VERSION_FN="/workspace/version.txt" \
-e PRETTY="${{ inputs.pretty }}" \
-e DESCRIPTION="${{ inputs.description }}" \
-e CHANGELOG="${{ inputs.changelog }}" \
-e OUT_REF="oci:$OUT_NAME" \
-e GIT_DIR="/var/git" \
-e CLEAR_PLAN="${{ inputs.clear-plan }}" \
-e REVISION="${{ inputs.revision }}" \
-e PREV_REF_FAIL="${{ inputs.prev-ref-fail }}" \
-u 0:0 \
${{ inputs.rechunk }} \
/sources/rechunk/3_chunk.sh
echo "version=$(sudo cat ${{ github.workspace }}/version.txt)" >> $GITHUB_OUTPUT
echo "ref=oci:${{ github.workspace }}/$OUT_NAME" >> $GITHUB_OUTPUT
echo "location=${{ github.workspace }}/$OUT_NAME" >> $GITHUB_OUTPUT
echo "changelog=${{ github.workspace }}/$OUT_NAME.changelog.txt" >> $GITHUB_OUTPUT
echo "manifest=${{ github.workspace }}/$OUT_NAME.manifest.json" >> $GITHUB_OUTPUT
# Remove root permissions
sudo chown $(id -u):$(id -g) -R "${{ github.workspace }}/$OUT_NAME"
# Remove cached OSTree volume
sudo podman volume rm cache_ostree
echo "Github Action output:"
cat $GITHUB_OUTPUT