Skip to content
Open
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.envrc
20 changes: 13 additions & 7 deletions commands/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions commands/properties.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion scripts/build
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
10 changes: 9 additions & 1 deletion test/create.bats
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -22,4 +31,3 @@ load test_helper
assert_success
assert_match $handle
}

9 changes: 9 additions & 0 deletions test/properties.bats
Original file line number Diff line number Diff line change
@@ -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"
}