Skip to content

Commit

Permalink
feat(import): allow importing of container images
Browse files Browse the repository at this point in the history
"""
import:
- path: docker://alpine:edge
  dest: /
"""

Signed-off-by: Ramkumar Chinchani <[email protected]>
  • Loading branch information
rchincha committed Sep 11, 2023
1 parent 5ec5d86 commit 73c04a8
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
26 changes: 26 additions & 0 deletions pkg/stacker/import.go
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,32 @@ func acquireUrl(c types.StackerConfig, storage types.Storage, i string, cache st
}

return p, nil
} else if url.Scheme == "docker" {
if idest != "" && idest[len(idest)-1:] != "/" {
return "", errors.Errorf("The destination path must be directory: %s", idest)
}

is := types.ImageSource{Type: "docker", Url: i}
if err := importContainersImage(is, c, false); err != nil {
return "", err
}

dname, err := os.MkdirTemp(c.RootFSDir, "import-rootfs-*")
if err != nil {
return "", err
}

bsopt := BaseLayerOpts{
Config: types.StackerConfig{RootFSDir: c.RootFSDir},
Name: path.Base(dname),
Layer: types.Layer{From: is},
Storage: storage,
}
if err := setupContainersImageRootfs(bsopt); err != nil {
return "", err
}

return dname, nil
}

return "", errors.Errorf("unsupported url scheme %s", i)
Expand Down
13 changes: 13 additions & 0 deletions test/import.bats
Original file line number Diff line number Diff line change
Expand Up @@ -393,3 +393,16 @@ EOF

stacker build
}

@test "importing container images" {
cat > stacker.yaml <<EOF
cimg-import:
from:
type: oci
url: $CENTOS_OCI
import:
- path: docker://alpine:edge
dest: /
EOF
stacker build
}

0 comments on commit 73c04a8

Please sign in to comment.