mirror of https://github.com/knative/func.git
Mirror buildpack run images in ghcr.io/knative (#2775)
Signed-off-by: Matej Vašek <mvasek@redhat.com>
This commit is contained in:
parent
fffde39adb
commit
8a061c4ed1
|
@ -16,4 +16,13 @@ jobs:
|
||||||
- name: Build and Push
|
- name: Build and Push
|
||||||
env:
|
env:
|
||||||
GITHUB_TOKEN: ${{ github.token }}
|
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
|
||||||
|
|
||||||
|
|
|
@ -132,6 +132,11 @@ func buildBuilderImage(ctx context.Context, variant, arch string) (string, error
|
||||||
return "", fmt.Errorf("cannot parse builder.toml: %w", err)
|
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
|
// temporary fix, for some reason paketo does not distribute several buildpacks for ARM64
|
||||||
// we need ot fix that up
|
// we need ot fix that up
|
||||||
if arch == "arm64" {
|
if arch == "arm64" {
|
||||||
|
@ -1038,3 +1043,47 @@ func fixupGoDistPkgRefs(buildpackToml, arch string) error {
|
||||||
|
|
||||||
return nil
|
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
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue