Skip to content

Commit

Permalink
Add SESSION_ID to instance and remove unnecessary stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
marcosnils committed Sep 12, 2017
1 parent ddcf5cf commit 4d643d0
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 44 deletions.
13 changes: 3 additions & 10 deletions Dockerfile.dind
Original file line number Diff line number Diff line change
@@ -1,18 +1,11 @@
ARG VERSION=docker:17.06.0-ce-dind
ARG VERSION=docker:17.07-dind
FROM ${VERSION}

RUN apk add --no-cache git tmux py2-pip apache2-utils vim build-base gettext-dev curl bash-completion bash util-linux jq openssh qemu-img qemu-system-x86_64
RUN apk add --no-cache git tmux py2-pip apache2-utils vim build-base gettext-dev curl bash-completion bash util-linux jq openssh zfs

ENV GOPATH /root/go
ENV PATH $PATH:$GOPATH

# Use specific moby commit due to vendoring mismatch
ENV MOBY_COMMIT="a73c3d3667f32fd61febcd2e824aa0341a57bafd"

RUN mkdir /root/go && apk add --no-cache go \
&& go get -u -d github.com/moby/tool/cmd/moby && (cd $GOPATH/src/github.com/moby/tool/cmd/moby && git checkout $MOBY_COMMIT && go install) \
&& go get -u github.com/linuxkit/linuxkit/src/cmd/linuxkit \
&& rm -rf /root/go/pkg && rm -rf /root/go/src && rm -rf /usr/lib/go

# Compile and install httping
# (used in orchestration workshop, and very useful anyway)
Expand Down Expand Up @@ -66,7 +59,7 @@ CMD cat /etc/hosts >/etc/hosts.bak && \
sed -i "s/\DOCKER_TLSCACERT/$DOCKER_TLSCACERT/" /etc/docker/daemon.json && \
sed -i "s/\DOCKER_TLSCERT/$DOCKER_TLSCERT/" /etc/docker/daemon.json && \
sed -i "s/\DOCKER_TLSKEY/$DOCKER_TLSKEY/" /etc/docker/daemon.json && \
umount /var/lib/docker && mount -t securityfs none /sys/kernel/security && \
mount -t securityfs none /sys/kernel/security && \
echo "root:root" | chpasswd &> /dev/null && \
/usr/sbin/sshd -o PermitRootLogin=yes -o PrintMotd=no 2>/dev/null && \
dockerd &>/docker.log & \
Expand Down
3 changes: 0 additions & 3 deletions daemon.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,8 @@
"experimental": true,
"debug": true,
"log-level": "info",
"graph": "/graph",
"insecure-registries": ["127.0.0.1"],
"hosts": ["unix:///var/run/docker.sock", "tcp://0.0.0.0:2375"],
"storage-driver": "DOCKER_STORAGE_DRIVER",
"dns": ["PWD_IP_ADDRESS", "8.8.8.8"],
"tls": DOCKER_TLSENABLE,
"tlscacert": "DOCKER_TLSCACERT",
"tlscert": "DOCKER_TLSCERT",
Expand Down
29 changes: 12 additions & 17 deletions docker/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,29 +226,25 @@ func (d *docker) DeleteContainer(id string) error {
}

type CreateContainerOpts struct {
Image string
WindowsEndpoint string
SessionId string
PwdIpAddress string
ContainerName string
Hostname string
ServerCert []byte
ServerKey []byte
CACert []byte
Privileged bool
HostFQDN string
Labels map[string]string
Networks []string
Image string
SessionId string
ContainerName string
Hostname string
ServerCert []byte
ServerKey []byte
CACert []byte
Privileged bool
HostFQDN string
Labels map[string]string
Networks []string
}

func (d *docker) CreateContainer(opts CreateContainerOpts) error {
// Make sure directories are available for the new instance container
containerDir := "/var/run/pwd"
containerCertDir := fmt.Sprintf("%s/certs", containerDir)

env := []string{}

env = append(env, fmt.Sprintf("WINDOWS_ENDPOINT=%s", opts.WindowsEndpoint))
env := []string{fmt.Sprintf("SESSION_ID=%s", opts.SessionId)}

// Write certs to container cert dir
if len(opts.ServerCert) > 0 {
Expand Down Expand Up @@ -296,7 +292,6 @@ func (d *docker) CreateContainer(opts CreateContainerOpts) error {
t := true
h.Resources.OomKillDisable = &t

env = append(env, fmt.Sprintf("PWD_IP_ADDRESS=%s", opts.PwdIpAddress))
env = append(env, fmt.Sprintf("PWD_HOST_FQDN=%s", opts.HostFQDN))
cf := &container.Config{
Hostname: opts.Hostname,
Expand Down
3 changes: 1 addition & 2 deletions handlers/get_instance_images.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ import (
func GetInstanceImages(rw http.ResponseWriter, req *http.Request) {
instanceImages := []string{
config.GetDindImageName(),
"franela/dind:overlay2-dev",
"franela/ucp:2.4.1",
"franela/dind:dev",
}
json.NewEncoder(rw).Encode(instanceImages)
}
1 change: 0 additions & 1 deletion provisioner/dind.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ func (d *DinD) InstanceNew(session *types.Session, conf types.InstanceConfig) (*
opts := docker.CreateContainerOpts{
Image: conf.ImageName,
SessionId: session.Id,
PwdIpAddress: session.PwdIpAddress,
ContainerName: containerName,
Hostname: conf.Hostname,
ServerCert: conf.ServerCert,
Expand Down
3 changes: 0 additions & 3 deletions pwd/instance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ func TestInstanceNew(t *testing.T) {
expectedContainerOpts := docker.CreateContainerOpts{
Image: expectedInstance.Image,
SessionId: session.Id,
PwdIpAddress: session.PwdIpAddress,
ContainerName: expectedInstance.Name,
Hostname: expectedInstance.Hostname,
ServerCert: nil,
Expand Down Expand Up @@ -153,7 +152,6 @@ func TestInstanceNew_WithNotAllowedImage(t *testing.T) {
expectedContainerOpts := docker.CreateContainerOpts{
Image: expectedInstance.Image,
SessionId: session.Id,
PwdIpAddress: session.PwdIpAddress,
ContainerName: expectedInstance.Name,
Hostname: expectedInstance.Hostname,
ServerCert: nil,
Expand Down Expand Up @@ -222,7 +220,6 @@ func TestInstanceNew_WithCustomHostname(t *testing.T) {
expectedContainerOpts := docker.CreateContainerOpts{
Image: expectedInstance.Image,
SessionId: session.Id,
PwdIpAddress: session.PwdIpAddress,
ContainerName: expectedInstance.Name,
Hostname: expectedInstance.Hostname,
ServerCert: nil,
Expand Down
14 changes: 6 additions & 8 deletions pwd/session_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/play-with-docker/play-with-docker/docker"
"github.com/play-with-docker/play-with-docker/event"
"github.com/play-with-docker/play-with-docker/provisioner"
"github.com/play-with-docker/play-with-docker/pwd/types"
"github.com/play-with-docker/play-with-docker/storage"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
Expand Down Expand Up @@ -63,8 +64,6 @@ func TestSessionNew(t *testing.T) {
assert.Equal(t, "localhost", s.Host)
assert.False(t, s.Ready)

assert.Equal(t, "10.0.0.1", s.PwdIpAddress)

_d.AssertExpectations(t)
_f.AssertExpectations(t)
_s.AssertExpectations(t)
Expand Down Expand Up @@ -97,31 +96,31 @@ func TestSessionSetup(t *testing.T) {
_s.On("InstanceCount").Return(0, nil)
_s.On("InstanceFindBySessionId", "aaaabbbbcccc").Return([]*types.Instance{}, nil)

_d.On("CreateContainer", docker.CreateContainerOpts{Image: "franela/dind", SessionId: "aaaabbbbcccc", PwdIpAddress: "10.0.0.1", ContainerName: "aaaabbbb_manager1", Hostname: "manager1", Privileged: true, HostFQDN: "localhost", Networks: []string{"aaaabbbbcccc"}}).Return(nil)
_d.On("CreateContainer", docker.CreateContainerOpts{Image: "franela/dind", SessionId: "aaaabbbbcccc", ContainerName: "aaaabbbb_manager1", Hostname: "manager1", Privileged: true, HostFQDN: "localhost", Networks: []string{"aaaabbbbcccc"}}).Return(nil)
_d.On("GetContainerIPs", "aaaabbbb_manager1").Return(map[string]string{"aaaabbbbcccc": "10.0.0.2"}, nil)
_f.On("GetForInstance", mock.AnythingOfType("*types.Instance")).Return(_d, nil)
_d.On("SwarmInit").Return(&docker.SwarmTokens{Manager: "managerToken", Worker: "workerToken"}, nil)
_e.M.On("Emit", event.INSTANCE_NEW, "aaaabbbbcccc", []interface{}{"aaaabbbb_manager1", "10.0.0.2", "manager1", "ip10-0-0-2-aaaabbbbcccc"}).Return()

_d.On("CreateContainer", docker.CreateContainerOpts{Image: "franela/dind", SessionId: "aaaabbbbcccc", PwdIpAddress: "10.0.0.1", ContainerName: "aaaabbbb_manager2", Hostname: "manager2", Privileged: true, HostFQDN: "localhost", Networks: []string{"aaaabbbbcccc"}}).Return(nil)
_d.On("CreateContainer", docker.CreateContainerOpts{Image: "franela/dind", SessionId: "aaaabbbbcccc", ContainerName: "aaaabbbb_manager2", Hostname: "manager2", Privileged: true, HostFQDN: "localhost", Networks: []string{"aaaabbbbcccc"}}).Return(nil)
_d.On("GetContainerIPs", "aaaabbbb_manager2").Return(map[string]string{"aaaabbbbcccc": "10.0.0.3"}, nil)
_f.On("GetForInstance", mock.AnythingOfType("*types.Instance")).Return(_d, nil)
_d.On("SwarmJoin", "10.0.0.2:2377", "managerToken").Return(nil)
_e.M.On("Emit", event.INSTANCE_NEW, "aaaabbbbcccc", []interface{}{"aaaabbbb_manager2", "10.0.0.3", "manager2", "ip10-0-0-3-aaaabbbbcccc"}).Return()

_d.On("CreateContainer", docker.CreateContainerOpts{Image: "franela/dind:overlay2-dev", SessionId: "aaaabbbbcccc", PwdIpAddress: "10.0.0.1", ContainerName: "aaaabbbb_manager3", Hostname: "manager3", Privileged: true, HostFQDN: "localhost", Networks: []string{"aaaabbbbcccc"}}).Return(nil)
_d.On("CreateContainer", docker.CreateContainerOpts{Image: "franela/dind:overlay2-dev", SessionId: "aaaabbbbcccc", ContainerName: "aaaabbbb_manager3", Hostname: "manager3", Privileged: true, HostFQDN: "localhost", Networks: []string{"aaaabbbbcccc"}}).Return(nil)
_d.On("GetContainerIPs", "aaaabbbb_manager3").Return(map[string]string{"aaaabbbbcccc": "10.0.0.4"}, nil)
_f.On("GetForInstance", mock.AnythingOfType("*types.Instance")).Return(_d, nil)
_d.On("SwarmJoin", "10.0.0.2:2377", "managerToken").Return(nil)
_e.M.On("Emit", event.INSTANCE_NEW, "aaaabbbbcccc", []interface{}{"aaaabbbb_manager3", "10.0.0.4", "manager3", "ip10-0-0-4-aaaabbbbcccc"}).Return()

_d.On("CreateContainer", docker.CreateContainerOpts{Image: "franela/dind", SessionId: "aaaabbbbcccc", PwdIpAddress: "10.0.0.1", ContainerName: "aaaabbbb_worker1", Hostname: "worker1", Privileged: true, HostFQDN: "localhost", Networks: []string{"aaaabbbbcccc"}}).Return(nil)
_d.On("CreateContainer", docker.CreateContainerOpts{Image: "franela/dind", SessionId: "aaaabbbbcccc", ContainerName: "aaaabbbb_worker1", Hostname: "worker1", Privileged: true, HostFQDN: "localhost", Networks: []string{"aaaabbbbcccc"}}).Return(nil)
_d.On("GetContainerIPs", "aaaabbbb_worker1").Return(map[string]string{"aaaabbbbcccc": "10.0.0.5"}, nil)
_f.On("GetForInstance", mock.AnythingOfType("*types.Instance")).Return(_d, nil)
_d.On("SwarmJoin", "10.0.0.2:2377", "workerToken").Return(nil)
_e.M.On("Emit", event.INSTANCE_NEW, "aaaabbbbcccc", []interface{}{"aaaabbbb_worker1", "10.0.0.5", "worker1", "ip10-0-0-5-aaaabbbbcccc"}).Return()

_d.On("CreateContainer", docker.CreateContainerOpts{Image: "franela/dind", SessionId: "aaaabbbbcccc", PwdIpAddress: "10.0.0.1", ContainerName: "aaaabbbb_other", Hostname: "other", Privileged: true, HostFQDN: "localhost", Networks: []string{"aaaabbbbcccc"}}).Return(nil)
_d.On("CreateContainer", docker.CreateContainerOpts{Image: "franela/dind", SessionId: "aaaabbbbcccc", ContainerName: "aaaabbbb_other", Hostname: "other", Privileged: true, HostFQDN: "localhost", Networks: []string{"aaaabbbbcccc"}}).Return(nil)
_d.On("GetContainerIPs", "aaaabbbb_other").Return(map[string]string{"aaaabbbbcccc": "10.0.0.6"}, nil)
_e.M.On("Emit", event.INSTANCE_NEW, "aaaabbbbcccc", []interface{}{"aaaabbbb_other", "10.0.0.6", "other", "ip10-0-0-6-aaaabbbbcccc"}).Return()

Expand Down Expand Up @@ -166,4 +165,3 @@ func TestSessionSetup(t *testing.T) {
_g.AssertExpectations(t)
_e.M.AssertExpectations(t)
}
*/

0 comments on commit 4d643d0

Please sign in to comment.