Skip to content

Commit 150a4fe

Browse files
author
creack
committed
Merge master within fs
2 parents 6908628 + f0ef0e3 commit 150a4fe

9 files changed

Lines changed: 200 additions & 80 deletions

File tree

Vagrantfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ Vagrant::Config.run do |config|
77
# please see the online documentation at vagrantup.com.
88

99
# Every Vagrant virtual environment requires a box to build off of.
10-
config.vm.box = "quantal64"
10+
config.vm.box = "quantal64_3.5.0-25"
1111

1212
# The url from where the 'config.vm.box' box will be fetched if it
1313
# doesn't already exist on the user's system.
14-
config.vm.box_url = "http://unworkable.org/~niallo/quantal64.box"
14+
config.vm.box_url = "http://get.docker.io/vbox/ubuntu/12.10/quantal64_3.5.0-25.box"
1515

1616
# Boot with a GUI so you can see the screen. (Default is headless)
1717
# config.vm.boot_mode = :gui

client/client.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ func InteractiveMode(scripts ...string) error {
111111
if err != nil {
112112
return err
113113
}
114+
defer os.Remove(rcfile.Name())
114115
io.WriteString(rcfile, "enable -n help\n")
115116
os.Setenv("PATH", tmp+":"+os.Getenv("PATH"))
116117
os.Setenv("PS1", "\\h docker> ")

container.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,13 @@ type Container struct {
5353
}
5454

5555
type Config struct {
56-
Hostname string
57-
User string
58-
Ram int64
59-
Ports []int
60-
Tty bool // Attach standard streams to a tty, including stdin if it is not closed.
61-
OpenStdin bool // Open stdin
56+
Hostname string
57+
User string
58+
Memory int64 // Memory limit (in bytes)
59+
MemorySwap int64 // Total memory usage (memory + swap); set `-1' to disable swap
60+
Ports []int
61+
Tty bool // Attach standard streams to a tty, including stdin if it is not closed.
62+
OpenStdin bool // Open stdin
6263
}
6364

6465
type NetworkSettings struct {

container_test.go

Lines changed: 62 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,12 @@ package docker
22

33
import (
44
"./fs"
5+
"bufio"
56
"fmt"
67
"io"
78
"io/ioutil"
9+
"math/rand"
10+
"os"
811
"sort"
912
"strings"
1013
"testing"
@@ -23,7 +26,7 @@ func TestCommitRun(t *testing.T) {
2326
[]string{"-c", "echo hello > /world"},
2427
GetTestImage(docker),
2528
&Config{
26-
Ram: 33554432,
29+
Memory: 33554432,
2730
},
2831
)
2932
if err != nil {
@@ -65,7 +68,7 @@ func TestCommitRun(t *testing.T) {
6568
[]string{"/world"},
6669
img,
6770
&Config{
68-
Ram: 33554432,
71+
Memory: 33554432,
6972
},
7073
)
7174
if err != nil {
@@ -100,7 +103,7 @@ func TestRun(t *testing.T) {
100103
[]string{"-al"},
101104
GetTestImage(docker),
102105
&Config{
103-
Ram: 33554432,
106+
Memory: 33554432,
104107
},
105108
)
106109
if err != nil {
@@ -349,7 +352,7 @@ func TestUser(t *testing.T) {
349352
// Set a username
350353
container, err = docker.Create(
351354
"user_root",
352-
"/bin/id",
355+
"id",
353356
[]string{},
354357
GetTestImage(docker),
355358
&Config{
@@ -393,7 +396,7 @@ func TestUser(t *testing.T) {
393396
// Set a different user by uid
394397
container, err = docker.Create(
395398
"user_uid1",
396-
"/usr/bin/id",
399+
"id",
397400
[]string{},
398401
GetTestImage(docker),
399402
&Config{
@@ -417,7 +420,7 @@ func TestUser(t *testing.T) {
417420
// Set a different user by username
418421
container, err = docker.Create(
419422
"user_daemon",
420-
"/usr/bin/id",
423+
"id",
421424
[]string{},
422425
GetTestImage(docker),
423426
&Config{
@@ -616,6 +619,59 @@ func TestEnv(t *testing.T) {
616619
}
617620
}
618621

622+
func grepFile(t *testing.T, path string, pattern string) {
623+
f, err := os.Open(path)
624+
if err != nil {
625+
t.Fatal(err)
626+
}
627+
defer f.Close()
628+
r := bufio.NewReader(f)
629+
var (
630+
line string
631+
)
632+
err = nil
633+
for err == nil {
634+
line, err = r.ReadString('\n')
635+
if strings.Contains(line, pattern) == true {
636+
return
637+
}
638+
}
639+
t.Fatalf("grepFile: pattern \"%s\" not found in \"%s\"", pattern, path)
640+
}
641+
642+
func TestLXCConfig(t *testing.T) {
643+
docker, err := newTestDocker()
644+
if err != nil {
645+
t.Fatal(err)
646+
}
647+
defer nuke(docker)
648+
// Memory is allocated randomly for testing
649+
rand.Seed(time.Now().UTC().UnixNano())
650+
memMin := 33554432
651+
memMax := 536870912
652+
mem := memMin + rand.Intn(memMax-memMin)
653+
container, err := docker.Create(
654+
"config_test",
655+
"/bin/true",
656+
[]string{},
657+
GetTestImage(docker),
658+
&Config{
659+
Hostname: "foobar",
660+
Memory: int64(mem),
661+
},
662+
)
663+
if err != nil {
664+
t.Fatal(err)
665+
}
666+
defer docker.Destroy(container)
667+
container.generateLXCConfig()
668+
grepFile(t, container.lxcConfigPath, "lxc.utsname = foobar")
669+
grepFile(t, container.lxcConfigPath,
670+
fmt.Sprintf("lxc.cgroup.memory.limit_in_bytes = %d", mem))
671+
grepFile(t, container.lxcConfigPath,
672+
fmt.Sprintf("lxc.cgroup.memory.memsw.limit_in_bytes = %d", mem*2))
673+
}
674+
619675
func BenchmarkRunSequencial(b *testing.B) {
620676
docker, err := newTestDocker()
621677
if err != nil {

install.sh

Lines changed: 44 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,55 @@
1-
# This script is meant for quick & easy install via 'curl URL-OF-SCRIPPT | bash'
2-
# Courtesy of Jeff Lindsay <progrium@gmail.com>
3-
4-
cd /tmp
5-
6-
echo "Ensuring dependencies are installed..."
7-
apt-get --yes install lxc wget bsdtar 2>&1 > /dev/null
8-
9-
echo "Downloading docker binary..."
10-
wget -q https://dl.dropbox.com/u/20637798/docker.tar.gz 2>&1 > /dev/null
11-
tar -xf docker.tar.gz 2>&1 > /dev/null
1+
#!/bin/sh
2+
# This script is meant for quick & easy install via 'curl URL-OF-SCRIPT | sh'
3+
# Original version by Jeff Lindsay <progrium@gmail.com>
4+
# Revamped by Jerome Petazzoni <jerome@dotcloud.com>
5+
#
6+
# This script canonical location is http://get.docker.io/; to update it, run:
7+
# s3cmd put -m text/x-shellscript -P install.sh s3://get.docker.io/index
8+
9+
echo "Ensuring basic dependencies are installed..."
10+
apt-get -qq update
11+
apt-get -qq install lxc wget bsdtar
12+
13+
echo "Looking in /proc/filesystems to see if we have AUFS support..."
14+
if grep -q aufs /proc/filesystems
15+
then
16+
echo "Found."
17+
else
18+
echo "Ahem, it looks like the current kernel does not support AUFS."
19+
echo "Let's see if we can load the AUFS module with modprobe..."
20+
if modprobe aufs
21+
then
22+
echo "Module loaded."
23+
else
24+
echo "Ahem, things didn't turn out as expected."
25+
KPKG=linux-image-extra-$(uname -r)
26+
echo "Trying to install $KPKG..."
27+
if apt-get -qq install $KPKG
28+
then
29+
echo "Installed."
30+
else
31+
echo "Oops, we couldn't install the -extra kernel."
32+
echo "Are you sure you are running a supported version of Ubuntu?"
33+
echo "Proceeding anyway, but Docker will probably NOT WORK!"
34+
fi
35+
fi
36+
fi
1237

13-
echo "Installing into /usr/local/bin..."
14-
mv docker/docker /usr/local/bin
15-
mv dockerd/dockerd /usr/local/bin
38+
echo "Downloading docker binary and uncompressing into /usr/local/bin..."
39+
curl -s http://get.docker.io/builds/$(uname -s)/$(uname -m)/docker-master.tgz |
40+
tar -C /usr/local/bin --strip-components=1 -zxf- \
41+
docker-master/docker docker-master/dockerd
1642

17-
if [[ -f /etc/init/dockerd.conf ]]
43+
if [ -f /etc/init/dockerd.conf ]
1844
then
1945
echo "Upstart script already exists."
2046
else
2147
echo "Creating /etc/init/dockerd.conf..."
2248
echo "exec /usr/local/bin/dockerd" > /etc/init/dockerd.conf
2349
fi
2450

25-
echo "Restarting dockerd..."
26-
restart dockerd > /dev/null
27-
28-
echo "Cleaning up..."
29-
rmdir docker
30-
rmdir dockerd
31-
rm docker.tar.gz
51+
echo "Starting dockerd..."
52+
start dockerd > /dev/null
3253

33-
echo "Finished!"
54+
echo "Done."
3455
echo

lxc_template.go

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,16 +85,32 @@ lxc.mount.entry = /etc/resolv.conf {{$ROOTFS}}/etc/resolv.conf none bind,ro 0 0
8585
lxc.cap.drop = audit_control audit_write mac_admin mac_override mknod net_raw setfcap setpcap sys_admin sys_boot sys_module sys_nice sys_pacct sys_rawio sys_resource sys_time sys_tty_config
8686
8787
# limits
88-
{{if .Config.Ram}}
89-
lxc.cgroup.memory.limit_in_bytes = {{.Config.Ram}}
88+
{{if .Config.Memory}}
89+
lxc.cgroup.memory.limit_in_bytes = {{.Config.Memory}}
90+
lxc.cgroup.memory.soft_limit_in_bytes = {{.Config.Memory}}
91+
{{with $memSwap := getMemorySwap .Config}}
92+
lxc.cgroup.memory.memsw.limit_in_bytes = {{$memSwap}}
93+
{{end}}
9094
{{end}}
9195
`
9296

9397
var LxcTemplateCompiled *template.Template
9498

99+
func getMemorySwap(config *Config) int64 {
100+
// By default, MemorySwap is set to twice the size of RAM.
101+
// If you want to omit MemorySwap, set it to `-1'.
102+
if config.MemorySwap < 0 {
103+
return 0
104+
}
105+
return config.Memory * 2
106+
}
107+
95108
func init() {
96109
var err error
97-
LxcTemplateCompiled, err = template.New("lxc").Parse(LxcTemplate)
110+
funcMap := template.FuncMap{
111+
"getMemorySwap": getMemorySwap,
112+
}
113+
LxcTemplateCompiled, err = template.New("lxc").Funcs(funcMap).Parse(LxcTemplate)
98114
if err != nil {
99115
panic(err)
100116
}

puppet/modules/docker/manifests/init.pp

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,19 @@
11
class docker {
22

33
# update this with latest docker binary distro
4-
$docker_url = "https://dl.dropbox.com/u/20637798/docker.tar.gz"
4+
$docker_url = "http://docker.io.s3.amazonaws.com/builds/$kernel/$hardwaremodel/docker-master.tgz"
55
# update this with latest go binary distry
66
$go_url = "http://go.googlecode.com/files/go1.0.3.linux-amd64.tar.gz"
77

8-
98
Package { ensure => "installed" }
109

11-
package { ["lxc", "debootstrap", "wget", "bsdtar"]: }
10+
package { ["lxc", "debootstrap", "wget", "bsdtar", "git",
11+
"linux-image-3.5.0-25-generic",
12+
"linux-image-extra-3.5.0-25-generic",
13+
"virtualbox-guest-utils",
14+
"linux-headers-3.5.0-25-generic"]: }
15+
16+
notify { "docker_url = $docker_url": withpath => true }
1217

1318
exec { "debootstrap" :
1419
require => Package["debootstrap"],
@@ -26,7 +31,7 @@
2631
exec { "fetch-docker" :
2732
require => Package["wget"],
2833
command => "/usr/bin/wget -O - $docker_url | /bin/tar xz -C /home/vagrant",
29-
creates => "/home/vagrant/docker/dockerd"
34+
creates => "/home/vagrant/docker-master"
3035
}
3136

3237
file { "/etc/init/dockerd.conf":
@@ -39,10 +44,21 @@
3944

4045
exec { "copy-docker-bin" :
4146
require => Exec["fetch-docker"],
42-
command => "/bin/cp /home/vagrant/docker/docker /usr/local/bin",
47+
command => "/bin/cp /home/vagrant/docker-master/docker /usr/local/bin",
4348
creates => "/usr/local/bin/docker"
4449
}
4550

51+
exec { "copy-dockerd-bin" :
52+
require => Exec["fetch-docker"],
53+
command => "/bin/cp /home/vagrant/docker-master/dockerd /usr/local/bin",
54+
creates => "/usr/local/bin/dockerd"
55+
}
56+
57+
exec { "vbox-add" :
58+
require => Package["linux-headers-3.5.0-25-generic"],
59+
command => "/etc/init.d/vboxadd setup",
60+
}
61+
4662
service { "dockerd" :
4763
ensure => "running",
4864
start => "/sbin/initctl start dockerd",

puppet/modules/docker/templates/dockerd.conf

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,6 @@ start on runlevel [3]
77
respawn
88

99
script
10-
/home/vagrant/dockerd/dockerd
10+
test -f /etc/default/locale && . /etc/default/locale || true
11+
LANG=$LANG LC_ALL=$LANG /usr/local/bin/dockerd
1112
end script

0 commit comments

Comments
 (0)