Skip to content

Dev Environment Setup

Dan Cadden edited this page Sep 28, 2016 · 18 revisions

Preface

Welcome to Leanworkbench! If this is your first time on the project you'll want to go through the dev environment setup below. If you have any questions feel free to reach out to **Daniel Cadden.

Index

Prerequisites

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.

Installing Docker

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 you should be able to run the following command. If you get "Not properly installed", run through the docker install process again.

$ docker || echo "Not properly installed"

You should also see a drop down on the top right of your nav bar (if you're on macOS)

Imgur

Now that we have a new docker up and running we need to make an alias in our host. We will map localhost 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 another instance of local host accociated with leanworkbench.dev
localhost leanworkbench.dev

Once docker is properly installed and linked we'll need to build our first local dev image to run in docker.

Docker Dev Images

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

Assets

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.

Web

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.

DB

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.

Creating a Dev Images

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 list the 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

Starting Dev Containers

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 is available at leanworkbench.dev and should be accessible via a browser.

Imgur

Stopping Dev Containers

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