Files
mhoennigandClaude Fable 5.1 c4b4866584 image metadata: import --change, inspect, run honors ENTRYPOINT/CMD/Env/WorkingDir
Every image stores the execution-relevant part of the OCI image
config (Env, Entrypoint, Cmd, WorkingDir, Labels, architecture, os)
in its image.json; images written before read back with an empty
config. import -c/--change applies ENTRYPOINT, CMD (exec or shell
form), ENV, WORKDIR, LABEL like docker import --change; USER, EXPOSE
and the rest are refused with a reason. inspect IMAGE... prints a
docker-shaped JSON array (RepoTags, Created, Architecture, Os,
Config, plus a Werkdock section). run merges the flags with the
config the docker way: image Env then -e, -w over WorkingDir,
--entrypoint over Entrypoint (dropping Cmd), arguments over Cmd — so
run IMAGE without a command works.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-09-05 22:40:26 +02:00

56 lines
1.5 KiB
Go

package cli
import (
"errors"
"flag"
"fmt"
"io"
"werkdock/internal/store"
)
// importCmd creates an image from a plain rootfs archive — `docker
// import` semantics: `werkdock import ARCHIVE [REPOSITORY[:TAG]]`.
func importCmd(args []string) int {
fs := flag.NewFlagSet("import", flag.ContinueOnError)
fs.SetOutput(io.Discard)
var changes stringList
fs.Var(&changes, "c", "apply a Dockerfile instruction to the image (ENTRYPOINT, CMD, ENV, WORKDIR, LABEL)")
fs.Var(&changes, "change", "apply a Dockerfile instruction to the image (ENTRYPOINT, CMD, ENV, WORKDIR, LABEL)")
if err := fs.Parse(args); err != nil {
return fail(err)
}
var config store.ImageConfig
for _, change := range changes {
if err := store.ApplyChange(&config, change); err != nil {
return fail(fmt.Errorf("--change %w", err))
}
}
rest := fs.Args()
if len(rest) == 0 {
return fail(errors.New("import needs an ARCHIVE (werkdock import ARCHIVE [REPOSITORY[:TAG]])"))
}
if len(rest) > 2 {
return fail(fmt.Errorf("unexpected argument %q", rest[2]))
}
archive := rest[0]
reference := store.ImageNameFromArchive(archive)
if len(rest) == 2 {
reference = rest[1]
}
return importArchive(archive, reference, config)
}
func importArchive(archive, reference string, config store.ImageConfig) int {
st, err := store.Default()
if err != nil {
return fail(err)
}
if err := st.Import(archive, reference, config); err != nil {
return fail(err)
}
ref, _ := store.ParseReference(reference)
fmt.Printf("Imported image: %s\n", ref.Short())
return 0
}