From 60395a269a6b0a530a786ff47f30296a98459995 Mon Sep 17 00:00:00 2001 From: "Jonathan Leibiusky @xetorthio" Date: Thu, 17 Nov 2016 12:29:08 -0300 Subject: [PATCH] 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