Skip to content

Commit a692f29

Browse files
committed
ci: Uses worker cache from main GHA cache
be79188 added in new GHA caches for worker images. The hope here is to be able to use these to cut down on a bunch of CI time. Signed-off-by: Brian Goff <[email protected]>
1 parent 40028b7 commit a692f29

File tree

4 files changed

+43
-0
lines changed

4 files changed

+43
-0
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,8 @@ jobs:
153153
run: docker run --rm --privileged tonistiigi/binfmt:latest --install all
154154
- name: Setup source policy
155155
uses: ./.github/actions/setup-source-policy
156+
- name: Expose GitHub tokens for caching
157+
uses: crazy-max/ghaction-github-runtime@3cb05d89e1f492524af3d41a1c98c83bc3025124 # v3.1.0
156158
- name: Run integration tests
157159
run: |
158160
set -ex

docker-bake.hcl

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,12 @@ target "runc-azlinux" {
7878
tags = tgt == "container" ? ["runc:mariner2"] : []
7979
// only output non-container targets to the fs
8080
output = tgt != "container" ? ["_output"] : []
81+
cache-from = [
82+
{
83+
type = "gha"
84+
scope = "main.${distro}/worker"
85+
}
86+
]
8187
}
8288

8389
target "runc-jammy" {
@@ -101,6 +107,12 @@ target "runc-jammy" {
101107
tags = tgt == "container" ? ["runc:jammy"] : []
102108
// only output non-container targets to the fs
103109
output = tgt != "container" ? ["_output"] : []
110+
cache-from = [
111+
{
112+
type = "gha"
113+
scope = "main.jammy/worker"
114+
}
115+
]
104116
}
105117

106118
target "runc-test" {
@@ -176,6 +188,12 @@ dependencies:
176188
}
177189
target = "${distro}/container/depsonly"
178190
tags = ["local/dalec/deps-only:${distro}"]
191+
cache-from = [
192+
{
193+
type = "gha"
194+
scope = "main.${distro}/worker"
195+
}
196+
]
179197
}
180198

181199
target "test-deps-only" {

test/testenv/build.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ import (
66
"encoding/json"
77
"io"
88
"os"
9+
"path"
910
"path/filepath"
11+
"strings"
1012
"testing"
1113

1214
"github.com/moby/buildkit/client"
@@ -209,3 +211,22 @@ func lookupProjectRoot(cur string) (string, error) {
209211

210212
return cur, nil
211213
}
214+
215+
func withCICache(opts *client.SolveOpt) {
216+
if os.Getenv("GITHUB_ACTIONS") != "true" {
217+
// not running in a github action, nothing to do
218+
return
219+
}
220+
221+
target, _, ok := strings.Cut(opts.FrontendAttrs["target"], "/")
222+
if !ok && target == "" {
223+
return
224+
}
225+
226+
opts.CacheImports = append(opts.CacheImports, client.CacheOptionsEntry{
227+
Type: "gha",
228+
Attrs: map[string]string{
229+
"scope": "main." + path.Join(target, "worker"),
230+
},
231+
})
232+
}

test/testenv/buildx.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,8 @@ func (b *BuildxEnv) RunTest(ctx context.Context, t *testing.T, f TestFunc, opts
357357
f(&so)
358358
}
359359

360+
withCICache(&so)
361+
360362
_, err = c.Build(ctx, so, "", func(ctx context.Context, gwc gwclient.Client) (*gwclient.Result, error) {
361363
gwc = &clientForceDalecWithInput{gwc}
362364

0 commit comments

Comments
 (0)