1
0
mirror of https://github.com/containers/buildah.git synced 2026-10-24 18:59:18 +03:00
Files
buildah/tests/tutorial/tutorial.go
Brent Baude b9396adba9 RUN-4547: Move buildah import paths
Like skopeo, we need to move buildah import paths to
go.podman.io/buildah. The redirection is built into
containers/go.podman.io as part of https://github.com/containers/go.podman.io/pull/6

Fixes: RUN-4547

Signed-off-by: Brent Baude <bbaude@redhat.com>
2026-04-20 15:24:38 -05:00

66 lines
1.4 KiB
Go

package main
import (
"context"
"errors"
"fmt"
"os"
"path/filepath"
specs "github.com/opencontainers/runtime-spec/specs-go"
"go.podman.io/buildah"
"go.podman.io/buildah/define"
"go.podman.io/buildah/imagebuildah"
"go.podman.io/storage"
"go.podman.io/storage/pkg/unshare"
)
func main() {
if buildah.InitReexec() {
return
}
unshare.MaybeReexecUsingUserNamespace(false)
buildStoreOptions, err := storage.DefaultStoreOptions()
if err != nil {
panic(err)
}
buildStore, err := storage.GetStore(buildStoreOptions)
if err != nil {
panic(err)
}
defer func() {
if _, err := buildStore.Shutdown(false); err != nil {
if !errors.Is(err, storage.ErrLayerUsedByContainer) {
fmt.Printf("failed to shutdown storage: %q", err)
}
}
}()
d, err := os.MkdirTemp("", "")
if err != nil {
panic(err)
}
defer os.RemoveAll(d)
dockerfile := filepath.Join(d, "Dockerfile")
f, err := os.Create(dockerfile)
if err != nil {
panic(err)
}
fmt.Fprintf(f, "FROM quay.io/libpod/alpine\nRUN echo CUT START; find /sys/fs/cgroup -print | sort ; echo CUT END")
f.Close()
buildOptions := define.BuildOptions{
ContextDirectory: d,
NamespaceOptions: []define.NamespaceOption{
{Name: string(specs.NetworkNamespace), Host: true},
},
}
_, _, err = imagebuildah.BuildDockerfiles(context.TODO(), buildStore, buildOptions, dockerfile)
if err != nil {
panic(err)
}
}