From 60395a269a6b0a530a786ff47f30296a98459995 Mon Sep 17 00:00:00 2001 From: "Jonathan Leibiusky @xetorthio" Date: Thu, 17 Nov 2016 12:29:08 -0300 Subject: [PATCH 1/4] Adds a Makefile to make the virtual box creation, start and app run reproducible. This allows to develop PWD on a container, which is nice and also necessary once "reverse proxy" feature is introduced. --- Makefile | 30 ++++++++++++++++++++++++++++++ docker-compose.yml | 15 +++++++++++++++ 2 files changed, 45 insertions(+) create mode 100644 Makefile create mode 100644 docker-compose.yml diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..57c31f3 --- /dev/null +++ b/Makefile @@ -0,0 +1,30 @@ +# Prepares the virtual box instance +prepare: + # Creates the virtual box + -docker-machine create -d virtualbox --virtualbox-boot2docker-url https://github.com/boot2docker/boot2docker/releases/download/v1.13.0-rc1/boot2docker.iso pwd && true + # Makes sure the docker daemon has the DinD image pulled + -docker-machine ssh pwd "docker pull franela/pwd-1.12.3-experimental-dind" + # Daemon should be swarm + -docker-machine ssh pwd "docker swarm init --advertise-addr $$(docker-machine ip pwd)" + # Stops to daemon to do further configurations on the box + -docker-machine stop pwd + # Adds the host GOPATH as a shared folder in the box + -VBoxManage sharedfolder add pwd --name gopathsrc --hostpath ${GOPATH}src --automount + # Do port forwaring so we can reach the app using localhost:3000 + -VBoxManage modifyvm pwd --natpf1 "nameformapping,tcp,,3000,,3000" + +# Starts the virtual box instance +start: + # Starts the machine + -docker-machine start pwd + # Make sure the folder where we'll mount the shared folder exists + docker-machine ssh pwd "sudo mkdir -p /go/src" + # Mount the host's GOPATH shared folder + docker-machine ssh pwd "sudo mount -t vboxsf gopathsrc /go/src" + +# Runs the app +run: + @eval $$(docker-machine env pwd); \ + docker-compose up + +.PHONY: prepare start run diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..e454826 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,15 @@ +version: '2' +services: + web: + # use the latest golang image + image: golang + # go to the right place and starts the app + command: /bin/sh -c 'cd /go/src/github.com/franela/play-with-docker; go run api.go' + ports: + # app exposes port 3000 + - "3000:3000" + volumes: + # since this app creates networks and launches containers, we need to talk to docker daemon + - /var/run/docker.sock:/var/run/docker.sock + # mount the box mounted shared folder to the container + - /go/src:/go/src From c2ec79584f16bbcb3a908c06b853d046deedd401 Mon Sep 17 00:00:00 2001 From: "Jonathan Leibiusky @xetorthio" Date: Thu, 17 Nov 2016 17:35:33 -0300 Subject: [PATCH 2/4] Add a name to the container --- docker-compose.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docker-compose.yml b/docker-compose.yml index e454826..5545a8a 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,6 +1,8 @@ version: '2' services: web: + # pwd daemon container always needs to be named this way + container_name: pwd # use the latest golang image image: golang # go to the right place and starts the app From 47d4ceab84c82fb2cdb176e8c5b53c84eab78775 Mon Sep 17 00:00:00 2001 From: "Jonathan Leibiusky @xetorthio" Date: Fri, 18 Nov 2016 10:02:32 -0300 Subject: [PATCH 3/4] Give a good name for the nat rule --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 57c31f3..68a0aff 100644 --- a/Makefile +++ b/Makefile @@ -11,7 +11,7 @@ prepare: # Adds the host GOPATH as a shared folder in the box -VBoxManage sharedfolder add pwd --name gopathsrc --hostpath ${GOPATH}src --automount # Do port forwaring so we can reach the app using localhost:3000 - -VBoxManage modifyvm pwd --natpf1 "nameformapping,tcp,,3000,,3000" + -VBoxManage modifyvm pwd --natpf1 "localhost,tcp,,3000,,3000" # Starts the virtual box instance start: From 903489c3955defc4d387717a272841f348bcfb86 Mon Sep 17 00:00:00 2001 From: "Jonathan Leibiusky @xetorthio" Date: Mon, 21 Nov 2016 20:48:29 -0300 Subject: [PATCH 4/4] Remove unncesary make target and add instructions on how to use the makefile --- Makefile | 4 ---- README.md | 5 +++++ 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/Makefile b/Makefile index 68a0aff..e91a018 100644 --- a/Makefile +++ b/Makefile @@ -22,9 +22,5 @@ start: # Mount the host's GOPATH shared folder docker-machine ssh pwd "sudo mount -t vboxsf gopathsrc /go/src" -# Runs the app -run: - @eval $$(docker-machine env pwd); \ - docker-compose up .PHONY: prepare start run diff --git a/README.md b/README.md index 223e0ec..d5d4773 100644 --- a/README.md +++ b/README.md @@ -21,6 +21,11 @@ just run `docker swarm init`. It's also necessary to manually load the IPVS kernel module because as swarms are created in `dind`, the daemon won't load it automatically. Run the following command for that purpose: `sudo lsmod xt_ipvs` +If you are developing, there is a `Makefile` file with 2 targets that can set the whole environment for you (using docker-machine and virtual box). +Just run once `make create`, which will create the docker-machine environment. +Additionally, every time you want to start you environment run `make start`. +And to start the application on a container on the docker machine host, run: `eval $(docker-machine env pwd) && docker-compose up` + ## Installation