Repository navigation
147 lines (129 loc) · 6.15 KB
/
Copy pathimage.yml
File metadata and controls
147 lines (129 loc) · 6.15 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
name: Base image
# The base image: ~1.5 GB of apt against a live archive, so it is path-triggered like the
# other two rather than run on every push.
#
# The build runs `docker run --cap-add SYS_ADMIN` and not `docker buildx build`, because
# mkosi assembles a root filesystem by unsharing a user and mount namespace and BuildKit
# forbids it. See image/Dockerfile — the alternative was a buildkitd started with an
# entitlement flag, which would make the build depend on how the runner's builder was
# created.
on:
# image/** and e2fsprogs/**, which makes the filesystem, and versions.yaml when it moves one of
# their pins; see the note in qemu.yml.
push:
branches: [main]
paths:
- image/**
- e2fsprogs/**
- cmd/spin-machine-dev/**
- internal/build/**
- versions.yaml
- go.mod
- .github/workflows/image.yml
pull_request:
paths:
- image/**
- e2fsprogs/**
- cmd/spin-machine-dev/**
- internal/build/**
- versions.yaml
- go.mod
- .github/workflows/image.yml
workflow_dispatch:
permissions:
contents: read
# The BuildKit cache: main writes it, everything else reads it (internal/build.CacheRegistry).
packages: write
concurrency:
group: image-${{ github.head_ref || github.ref_name }}
# Never on main: a cancelled run there is a commit nobody proved.
cancel-in-progress: ${{ github.ref_name != 'main' }}
# As ci.yml: go-tools' downloads, and the image's own from GitHub releases, ask with it: GitHub
# sheds anonymous ones first.
env:
GITHUB_TOKEN: ${{ github.token }}
jobs:
# Whether this change can reach e2fsprogs or the image; see the note in qemu.yml.
changed:
runs-on: ubuntu-latest
timeout-minutes: 10
outputs:
build: ${{ steps.touches.outputs.build }}
steps:
- name: Checkout
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
fetch-depth: 0
- name: Set up Go
uses: actions/setup-go@b7ad1dad31e06c5925ef5d2fc7ad053ef454303e # v7.0.0
with:
go-version-file: go.mod
cache: true
# spin-machine-dev built and on the PATH, so a step's exit status is the verb's (go run makes
# it 1): the verbs below are the ones a person types (docs/cli.md).
- name: spin-machine-dev
run: go tool task bin
- name: Does the change reach the image
id: touches
env:
BASE: ${{ github.event.pull_request.base.sha || github.event.before }}
run: spin-machine-dev changed --base "$BASE" --pins alpine,e2fsprogs,ubuntu,systemd-source,mkosi,task,git-lfs,buildkit image e2fsprogs go.mod cmd/spin-machine-dev internal/build .github/workflows/image.yml
build:
needs: changed
if: needs.changed.outputs.build == 'true'
runs-on: ubuntu-latest
timeout-minutes: 60
steps:
- name: Checkout
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
# spin-machine-dev is Go, and reads the builds' pins from versions.yaml.
- name: Set up Go
uses: actions/setup-go@b7ad1dad31e06c5925ef5d2fc7ad053ef454303e # v7.0.0
with:
go-version-file: go.mod
cache: true
# spin-machine-dev built and on the PATH, so a step's exit status is the verb's (go run makes
# it 1): the verbs below are the ones a person types (docs/cli.md).
- name: spin-machine-dev
run: go tool task bin
# A builder of its own (the docker-container driver): Docker's default one cannot export its
# cache. What it reads and writes is the cache image in GitHub's registry that the build
# names (--cache-registry, internal/build.CacheRegistry), so the runner itself keeps nothing between runs.
- uses: docker/setup-buildx-action@f87e5991a6d7451dcb8d9637bfbc97413f497069 # v4.4.1
# The cache is one of this repository's packages, and reading it takes a login as much as
# writing it does. Without one BuildKit says it could not import the cache, carries on
# without it, and the build passes at the cold time.
- name: Log in to GitHub Packages
uses: docker/login-action@8aa5831fb8d48d8f76594c7ddde61ae58019f550 # v4.8.0
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
# The image is made and checked with the static e2fsprogs this repository builds, not
# the build container's, and image/build.sh stops when it is not there.
- name: Build e2fsprogs
env:
# main's lanes write the cache back; everything else only reads it.
CACHE_EXPORT: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }}
run: spin-machine-dev build e2fsprogs --jobs 4 --cache-registry --cache-export="$CACHE_EXPORT"
# image/build.sh asserts what came out on the finished filesystem rather than
# trusting the build that made it: that there is an /sbin/init and a /bin/sh, that
# the directories the guest mounts over exist, that no identity is baked in, and
# that the units masked for measured reasons are still masked. A package upgrade
# that undoes one of those fails here.
#
# mkosi's own package cache is deliberately not restored between runs. It is ~1.5 GB
# of .debs, and saving and restoring that costs about what downloading it costs — so
# it would buy minutes of cache traffic in exchange for minutes of archive traffic,
# and a cache entry large enough to push others out of the repository's 10 GB.
#
# It builds the systemd the image installs first, and says what the image is, by sha256,
# on the run's summary.
- name: Build the base image
env:
# main's lanes write the cache back; everything else only reads it.
CACHE_EXPORT: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }}
run: spin-machine-dev build image --jobs 4 --cache-registry --cache-export="$CACHE_EXPORT"
# Not uploaded as an artifact: it is ~860 MB and the release workflow rebuilds it
# from the same inputs. What this job is for is finding out that it still builds and
# still passes its own checks.