Skip to content

Commit

Permalink
write molecule config to metadata path
Browse files Browse the repository at this point in the history
The molecule config contains the OCI path and tag, which is important if
we want to track what container image is mounted at a particular path,
and thus what container might need to stop if a verity error is detected
in one of the atoms in the molecule it's using.

This commit writes that config to a JSON file in the metadata path.

Signed-off-by: Michael McCracken <[email protected]>
  • Loading branch information
mikemccracken committed Oct 1, 2024
1 parent 820120d commit 7fadf7d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
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

0 comments on commit 7fadf7d

Please sign in to comment.