diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..7a6353d --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.envrc diff --git a/commands/create.go b/commands/create.go index 23a0cc6..f63fe0b 100644 --- a/commands/create.go +++ b/commands/create.go @@ -9,13 +9,14 @@ import ( ) type Create struct { - Handle string `short:"n" long:"handle" description:"name to give container"` - RootFS string `short:"r" long:"rootfs" description:"rootfs image with which to create the container"` - Env []string `short:"e" long:"env" description:"set environment variables"` - Grace time.Duration `short:"g" long:"grace" description:"grace time (resetting ttl) of container"` - Privileged bool `short:"p" long:"privileged" description:"privileged user in the container is privileged in the host"` - Network string `long:"network" description:"the subnet of the container"` - BindMounts []string `short:"m" long:"bind-mount" description:"bind mount host-path:container-path"` + Handle string `short:"n" long:"handle" description:"name to give container"` + RootFS string `short:"r" long:"rootfs" description:"rootfs image with which to create the container"` + Env []string `short:"e" long:"env" description:"set environment variables"` + Grace time.Duration `short:"g" long:"grace" description:"grace time (resetting ttl) of container"` + Privileged bool `short:"p" long:"privileged" description:"privileged user in the container is privileged in the host"` + Network string `long:"network" description:"the subnet of the container"` + BindMounts []string `short:"m" long:"bind-mount" description:"bind mount host-path:container-path"` + LimitMemory uint64 `short:"k" long:"limit-memory" description:"limits the memory used by the container. Value in bytes"` } func (command *Create) Execute(args []string) error { @@ -43,6 +44,11 @@ func (command *Create) Execute(args []string) error { Env: command.Env, Network: command.Network, BindMounts: bindMounts, + Limits: garden.Limits{ + Memory: garden.MemoryLimits{ + LimitInBytes: command.LimitMemory, + }, + }, }) failIf(err) diff --git a/commands/properties.go b/commands/properties.go index ba3530d..eda50cb 100644 --- a/commands/properties.go +++ b/commands/properties.go @@ -17,6 +17,9 @@ func (command *Properties) Execute(maybeHandle []string) error { properties, err := container.Properties() failIf(err) + memoryLimits, err := container.CurrentMemoryLimits() + failIf(err) + if command.AsJSON { toPrint, err := json.MarshalIndent(properties, "", " ") failIf(err) @@ -25,6 +28,7 @@ func (command *Properties) Execute(maybeHandle []string) error { for k, v := range properties { fmt.Printf("%s\t%s\n", k, v) } + fmt.Printf("memory.limit\t%d bytes\n", memoryLimits.LimitInBytes) } return nil diff --git a/scripts/build b/scripts/build index 47d25e4..d8a2ff3 100755 --- a/scripts/build +++ b/scripts/build @@ -8,4 +8,4 @@ for platform in linux darwin; do go build -o ${workspace}/gaol_${platform} github.com/contraband/gaol done -open ${workspace} +echo Output is in "${workspace}" diff --git a/test/create.bats b/test/create.bats index 25981f3..fb3718b 100755 --- a/test/create.bats +++ b/test/create.bats @@ -11,6 +11,15 @@ load test_helper assert_match $handle } +@test "a container can be created with memory limits" { + handle=$(gaol create --limit-memory 52428800) + assert_success + + run gaol properties $handle + assert_success + assert_match "memory.limit\t52428800 bytes" +} + @test "a created container can have its handle chosen" { run gaol create -n awesome-handle @@ -22,4 +31,3 @@ load test_helper assert_success assert_match $handle } - diff --git a/test/properties.bats b/test/properties.bats new file mode 100644 index 0000000..7a526fb --- /dev/null +++ b/test/properties.bats @@ -0,0 +1,9 @@ +#!/usr/bin/env bats + +load test_helper + +@test "a container reports its limits" { + run gaol properties $(gaol create) + assert_success + assert_match "memory.limit\t0 bytes" +}