Mirror buildpack run images in ghcr.io/knative (#2775)

Signed-off-by: Matej Vašek <mvasek@redhat.com>
This commit is contained in:
Matej Vašek 2025-04-09 21:24:12 +02:00 committed by GitHub
parent fffde39adb
commit 8a061c4ed1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 59 additions and 1 deletions

View File

@ -16,4 +16,13 @@ jobs:
- name: Build and Push
env:
GITHUB_TOKEN: ${{ github.token }}
run: make wf-update-builder
run: |
docker run -d -p 5000:5000 --name registry registry:2.7
echo '{"insecure-registries" : "localhost:5000" }' | \
sudo tee /etc/docker/daemon.json
mkdir -p "$HOME/.config/containers/"
echo -e '\n[[registry]]\nlocation = "localhost:5000"\ninsecure = true\n' >> \
"$HOME/.config/containers/registries.conf"
skopeo login ghcr.io -u gh-action -p "$GITHUB_TOKEN"
make wf-update-builder

View File

@ -132,6 +132,11 @@ func buildBuilderImage(ctx context.Context, variant, arch string) (string, error
return "", fmt.Errorf("cannot parse builder.toml: %w", err)
}
err = fixupStacks(ctx, &builderConfig)
if err != nil {
return "", fmt.Errorf("cannot fix up stacks: %w", err)
}
// temporary fix, for some reason paketo does not distribute several buildpacks for ARM64
// we need ot fix that up
if arch == "arm64" {
@ -1038,3 +1043,47 @@ func fixupGoDistPkgRefs(buildpackToml, arch string) error {
return nil
}
func fixupStacks(ctx context.Context, builderConfig *builder.Config) error {
var err error
oldBuild := builderConfig.Stack.BuildImage
parts := strings.Split(oldBuild, "/")
newBuilder := "localhost:5000/" + parts[len(parts)-1]
err = copyImage(ctx, oldBuild, newBuilder)
if err != nil {
return fmt.Errorf("cannot mirror build image: %w", err)
}
builderConfig.Stack.BuildImage = newBuilder
builderConfig.Build.Image = newBuilder
oldRun := builderConfig.Stack.RunImage
parts = strings.Split(oldRun, "/")
newRun := "ghcr.io/knative/" + parts[len(parts)-1]
err = copyImage(ctx, oldRun, newRun)
if err != nil {
return fmt.Errorf("cannot mirror build image: %w", err)
}
builderConfig.Stack.RunImage = newRun
builderConfig.Run.Images = []builder.RunImageConfig{{
Image: newRun,
}}
return nil
}
func copyImage(ctx context.Context, srcRef, destRef string) error {
_, _ = fmt.Fprintf(os.Stderr, "copying: %s => %s\n", srcRef, destRef)
cmd := exec.CommandContext(ctx, "skopeo", "copy",
"--multi-arch=all",
"docker://"+srcRef,
"docker://"+destRef,
)
cmd.Stderr = os.Stderr
cmd.Stdout = os.Stdout
err := cmd.Run()
if err != nil {
return fmt.Errorf("error while running skopeo: %w", err)
}
return nil
}