Repository navigation
Dev Environment Setup
First we need to recursively clone the repo and its submodules.
$ git clone --recursive git@github.com:wigginslab/min-bench.git
In order to proceed you MUST have docker installed.
Here are the instructions for installing docker on your OS of choice:
Make sure to follow ALL of the directions. However, for now I will assume you're using a mac.
Now that you have docker and docker-machine (if you're on mac) you should be able to run the following command. If you get "Not properly installed", run through the docker install process again.
$ docker && docker-machine || echo "Not properly installed"
You can run this command to see the list of docker-machines you currently have on your machine.
$ docker-machine ls
Now lets make a new docker-machine called lwb. This should take a few minutes as docker-machine creates a new VM with the virtualbox driver.
$ docker-machine create lwb --driver virtualbox
Once docker-machine is finished creating the VM you should see it up and running by listing your docker-machines again.
$ docker-machine ls
NAME ACTIVE DRIVER STATE URL SWARM DOCKER ERRORS
default - virtualbox Saved Unknown
lwb - virtualbox Running tcp://192.168.99.100:2376 v1.11.2
Now that we have a new docker-machine VM running we need to make an alias in our host file for the ip address listed for the VM. We will map the IP to leanworkbench.dev.
$ sudo vim /etc/hosts
It should look something like this.
127.0.0.1 localhost
255.255.255.255 broadcasthost
::1 localhost
# Place the ip of the `lwb` vm here with the domain name as so
192.168.99.100 leanworkbench.dev
Great. We've successfully created a new docker-machine VM to run our docker containers and mapped the ip to a new alias. Now lets see how to use the docker command.
IMPORTANT Every time you load a new shell window you need to link docker to the docker-machine
You will need to run this command every time you create a new shell window. This will connect the dockerand the docker-machine process.
$ eval "$(docker-machine env lwb)"
If you do not link docker-machine to docker you will recieve an error message when trying to build or run a container that looks like this:
$ docker: Cannot connect to the Docker daemon. Is the docker daemon running on this host?. See 'docker run --help'.
I recommend you use an alias or function in your shell's rc file, like this one.
function link-docker { if [[ -z $@ ]]; then local machine="default" else local machine=$@ fi eval "$(docker-machine env $@)" }
To use this simply put it in your shell's rc file (I use .bashrc) and type:
$ link-docker lwb
It will use
defaultby default if you provide no arguments.
Once docker is properly installed and linked we'll need to build our first local dev image to run in docker.
An image in docker is basically a series of instructions on how to configure a container. Some of the instructions are executed at build time, and some of them are built at run time.
We use the following three basic images for dev.
- assets
- web
- db
This is a container that is running a webpack dev server with hot loading. This basically means it listens to file changes from your local version of the codebase and re-creates the website on each file change. You can make changes to the FE code and see it automatically load those changes on save.
This is container that is running our python backend code. It uses your local filesystems version of the code and simply runs it in the container. Any changes you make will automatically reload the server.
This is a container that strictly runs a mongo db sever. Pretty straight forward.
When we run our start script it will run these three containers and that makes up the sum of our dev environment.
For our dev environment we only need to the build the images once.
The only time we need to rebuild the image is if there is a change to the Dockerfile associated to the image. We will let you know if any changes occur that would require this action.
To create your first dev image navigate to ../infra/bin directory and run the build-dev script.
$ cd $MINBENCH_REPO/infra/bin/ && ./build-dev
You should see a lot of flying text and docker begins to follow the instructions located in the associated Dockerfiles.
Once the installations and complications of the images are finished run this commands to the list of images on your computer.
$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
asset-builder-dev latest 1b15825d833a 8 days ago 962.9 MB
web-dev latest 310a80997d8b 9 days ago 689.3 MB
db-dev latest 282fd552add6 5 weeks ago 336.1 MB
Now that we have some images we can run them with our start-dev script.
$ cd $MINBENCH_REPO/infra/bin/ && ./start-dev
You should see some long hashed container names and either a ✓ dev started successfully! or ✗ Failed to start dev.
Check the status of the containers and see that they're all running.
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
5b034b6e815a asset-builder-dev "npm run start" About a minute ago Up About a minute 0.0.0.0:80->80/tcp assets
ec90fa5ad7b9 web-dev "python ./app.py" About a minute ago Up About a minute 0.0.0.0:3036->3036/tcp web
12990bd2fcd5 db-dev "/entrypoint.sh mongo" About a minute ago Up About a minute 0.0.0.0:27017->27017/tcp db
Congrats! You made it!
Now the dev environment should be accessible via leanworkbench.dev
It's important that you use the stop-dev script if you need to halt your dev environment. You obviously don't want it running 24/7 so make sure to properly stop the containers.
$ cd $MINBENCH_REPO/infra/bin/ && ./stop-dev
You should see this when you run the list containers command.
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES