Skip to content

Commit

Permalink
Create draft of FreeBSD runtime spec
Browse files Browse the repository at this point in the history
  • Loading branch information
mateuszkwiatkowski committed Apr 9, 2021
1 parent ea57e3b commit 759dccf
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 7 deletions.
51 changes: 49 additions & 2 deletions oci/config/convert/default.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ import (
"github.com/pkg/errors"
)

// Example returns an example spec file, used as a "good sane default".
// Example returns an example spec file for Linux images, used as a "good sane default".
// XXX: Really we should just use runc's directly.
func Example() rspec.Spec {
func Example_Linux() rspec.Spec {
return rspec.Spec{
Version: rspec.Version,
Root: &rspec.Root{
Expand Down Expand Up @@ -172,6 +172,53 @@ func Example() rspec.Spec {
}
}

// Example returns an example spec file for FreeBSD images, used as a "good sane default".
// XXX: Really we should just use runc's directly.
func Example_FreeBSD() rspec.Spec {
return rspec.Spec{
Version: rspec.Version,
Root: &rspec.Root{
Path: "rootfs",
Readonly: false,
},
Process: &rspec.Process{
Terminal: true,
User: rspec.User{},
Args: []string{
"sh",
},
Env: []string{
"PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
"TERM=xterm",
},
Cwd: "/",
NoNewPrivileges: true,
Rlimits: []rspec.POSIXRlimit{
{
Type: "RLIMIT_NOFILE",
Hard: uint64(1024),
Soft: uint64(1024),
},
},
},
Hostname: "umoci-default",
Mounts: []rspec.Mount{
{
Destination: "/dev",
Type: "devfs",
Source: "devfs",
Options: []string{},
},
{
Destination: "/dev/fd",
Type: "fdescfs",
Source: "fdescfs",
Options: []string{},
},
},
}
}

// ToRootless converts a specification to a version that works with rootless
// containers. This is done by removing options and other settings that clash
// with unprivileged user namespaces.
Expand Down
12 changes: 7 additions & 5 deletions oci/config/convert/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,13 @@ const (
// configuration specified by the OCI runtime-tools. It is equivalent to
// MutateRuntimeSpec("runtime-tools/generate".New(), image).Spec().
func ToRuntimeSpec(rootfs string, image ispec.Image) (rspec.Spec, error) {
spec := Example()
var spec rspec.Spec
switch image.OS {
case "linux": spec = Example_Linux()
case "freebsd": spec = Example_FreeBSD()
default: return rspec.Spec{}, errors.Errorf("unsupported OS: %s", image.OS)
}

if err := MutateRuntimeSpec(&spec, rootfs, image); err != nil {
return rspec.Spec{}, err
}
Expand Down Expand Up @@ -110,10 +116,6 @@ func MutateRuntimeSpec(spec *rspec.Spec, rootfs string, image ispec.Image) error
return errors.Wrap(err, "creating image generator")
}

if ig.OS() != "linux" {
return errors.Errorf("unsupported OS: %s", image.OS)
}

allocateNilStruct(spec)

// FIXME: We need to figure out if we're modifying an incompatible runtime spec.
Expand Down

0 comments on commit 759dccf

Please sign in to comment.