Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make config and metadata visible #22

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 21 additions & 4 deletions cmd/atomfs/mount.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,12 @@ func doMount(ctx *cli.Context) error {
os.Exit(1)
}
target := ctx.Args()[1]
metadir := filepath.Join(target, "meta")
absTarget, err := filepath.Abs(target)
if err != nil {
return err
}

metadir := filepath.Join("/run", "atomfs", "meta", ReplacePathSeparators(absTarget))

complete := false

Expand All @@ -92,12 +97,24 @@ func doMount(ctx *cli.Context) error {
if err = EnsureDir(rodest); err != nil {
return err
}
absOCIDir, err := filepath.Abs(ocidir)
if err != nil {
return err
}
absMetadir, err := filepath.Abs(metadir)
if err != nil {
return err
}
absRODest, err := filepath.Abs(rodest)
if err != nil {
return err
}

opts := atomfs.MountOCIOpts{
OCIDir: ocidir,
MetadataPath: metadir,
OCIDir: absOCIDir,
MetadataPath: absMetadir,
Tag: tag,
Target: rodest,
Target: absRODest,
}

mol, err := atomfs.BuildMoleculeFromOCI(opts)
Expand Down
13 changes: 7 additions & 6 deletions cmd/atomfs/umount.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,12 @@ func doUmount(ctx *cli.Context) error {
errs = append(errs, fmt.Errorf("Failed unmounting %s: %v", mountpoint, err))
}

// Now that we've unmounted the mountpoint, we expect the following
// under there:
// $mountpoint/meta/ro - the original readonly overlay mountpoint
// $mountpoint/meta/mounts/* - the original squashfs mounts
metadir := filepath.Join(mountpoint, "meta")
// We expect the following in the metadir
//
// $metadir/ro - the original readonly overlay mountpoint
// $metadir/meta/mounts/* - the original squashfs mounts
// $metadir/meta/config.json
metadir := filepath.Join("/run/atomfs/meta", ReplacePathSeparators(mountpoint))
p := filepath.Join(metadir, "ro")
err = syscall.Unmount(p, 0)
if err != nil {
Expand All @@ -65,7 +66,7 @@ func doUmount(ctx *cli.Context) error {
mounts, err := os.ReadDir(mountsdir)
if err != nil {
errs = append(errs, fmt.Errorf("Failed reading list of mounts: %v", err))
return fmt.Errorf("Encountered errors: %#v", errs)
return fmt.Errorf("Encountered errors: %v", errs)
}

for _, m := range mounts {
Expand Down
10 changes: 10 additions & 0 deletions cmd/atomfs/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package main
import (
"fmt"
"os"
"strings"
)

func EnsureDir(dir string) error {
Expand All @@ -20,3 +21,12 @@ func PathExists(d string) bool {
}
return true
}

// remove dir separators to make one dir name. It is OK that this can't be
// cleanly backed out, we don't need it to
func ReplacePathSeparators(p string) string {
if p[0] == '/' {
p = p[1:]
}
return strings.ReplaceAll(p, "/", "-")
}
5 changes: 5 additions & 0 deletions molecule.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,11 @@ func (m Molecule) Mount(dest string) error {
return err
}

err = m.config.WriteToFile(filepath.Join(m.config.MetadataPath, "config.json"))
if err != nil {
return err
}

// now, do the actual overlay mount
err = unix.Mount("overlay", dest, "overlay", 0, mntOpts)
return errors.Wrapf(err, "couldn't do overlay mount to %s, opts: %s", dest, mntOpts)
Expand Down
14 changes: 14 additions & 0 deletions oci.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package atomfs

import (
"encoding/json"
"io/ioutil"
"path"

ispec "github.com/opencontainers/image-spec/specs-go/v1"
Expand All @@ -26,6 +28,18 @@ func (c MountOCIOpts) MountedAtomsPath(parts ...string) string {
return path.Join(append([]string{mounts}, parts...)...)
}

func (c MountOCIOpts) WriteToFile(filename string) error {
b, err := json.Marshal(c)
if err != nil {
return err
}
err = ioutil.WriteFile(filename, b, 0644)
if err != nil {
return err
}
return nil
}

func BuildMoleculeFromOCI(opts MountOCIOpts) (Molecule, error) {
oci, err := umoci.OpenLayout(opts.OCIDir)
if err != nil {
Expand Down
Loading