Workflow

Updated reference guide...

All Services

The following commands are for spinning up all the containers...

Environment Variables

Development:

$ export REACT_APP_USERS_SERVICE_URL=http://DOCKER_MACHINE_DEV_IP
$ export TEST_URL=http://DOCKER_MACHINE_DEV_IP

Staging:

$ export REACT_APP_USERS_SERVICE_URL=http://DOCKER_MACHINE_STAGING_IP
$ export SECRET_KEY=SOMETHING_SUPER_SECRET
$ export TEST_URL=http://DOCKER_MACHINE_STAGING_IP

Production:

$ export REACT_APP_USERS_SERVICE_URL=http://DOCKER_MACHINE_PROD_IP
$ export SECRET_KEY=SOMETHING_SUPER_SECRET
$ export TEST_URL=http://DOCKER_MACHINE_PROD_IP
Start

Build the images:

$ docker-compose build

Run the containers:

$ docker-compose up -d

Create and seed the database:

$ docker-compose run users-service python manage.py recreate_db
$ docker-compose run users-service python manage.py seed_db

Run the unit and integration tests:

$ docker-compose run users-service python manage.py test

Run the e2e tests:

$ testcafe chrome e2e
Stop

Stop the containers:

$ docker-compose stop

Bring down the containers:

$ docker-compose down

Remove images:

$ docker rmi $(docker images -q)

Individual Services

The following commands are for spinning up individual containers...

Users DB

Build and run:

$ docker-compose up -d --build users-db

Test:

$ docker exec -ti users-db psql -U postgres -W
Users

Build and run:

$ docker-compose up -d --build users-service

Create and seed the database:

$ docker-compose run users-service python manage.py recreate_db
$ docker-compose run users-service python manage.py seed_db

Run the unit and integration tests:

$ docker-compose run users-service python manage.py test
Web

Set env variable:

$ export REACT_APP_USERS_SERVICE_URL=http://DOCKER_MACHINE_DEV_IP

Build and run:

$ docker-compose up -d --build web-service

To test, navigate to http://DOCKER_MACHINE_DEV_IP:9000 in your browser.

Keep in mind that you won't be able to register or log in until Nginx is set up

To take advantage of auto/hot/live reload, it is recommended to develop out of the container. Navigate to the flask-microservices-client directory, set the env variable:

$ export REACT_APP_USERS_SERVICE_URL=http://DOCKER_MACHINE_DEV_IP

Then run npm start.

Nginx

Build and run:

$ docker-compose up -d --build nginx

To test, navigate to http://DOCKER_MACHINE_DEV_IP in your browser. Also, run the e2e tests:

$ export TEST_URL=http://DOCKER_MACHINE_DEV_IP
$ testcafe chrome e2e
Swagger

Build and run:

$ docker-compose up -d --build swagger

To test, navigate to http://DOCKER_MACHINE_DEV_IP:8080 in your browser.

Aliases

To save some previous keystrokes, create aliases for both the docker-compose and docker-machine commands - dc and dm, respectively.

Simply add the following lines to your .bashrc file:

alias dc='docker-compose'
alias dm='docker-machine'

Save the file, then execute it:

$ source ~/.bashrc

Test out the new aliases!

On Windows? You will first need to create a PowerShell Profile (if you don't already have one), and then you can add the aliases to it using Set-Alias - i.e., Set-Alias dc docker-compose.

"Saved" State

Is the VM stuck in a "Saved" state?

$ docker-machine ls

NAME   ACTIVE   DRIVER       STATE     URL                         SWARM   DOCKER        ERRORS
aws    *        amazonec2    Running   tcp://34.207.173.181:2376           v17.05.0-ce
dev    -        virtualbox   Saved                                         Unknown

To break out of this, you'll need to power off the VM:

  1. Start virtualbox - virtualbox
  2. Select the VM and click "start"
  3. Exit the VM and select "Power off the machine"
  4. Exit virtualbox

The VM should now have a "Stopped" state:

$ docker-machine ls

NAME   ACTIVE   DRIVER       STATE     URL                         SWARM   DOCKER        ERRORS
aws    *        amazonec2    Running   tcp://34.207.173.181:2376           v17.05.0-ce
dev    -        virtualbox   Stopped                                       Unknown

Now you can start the machine:

$ docker-machine start dev

It should be "Running":

$ docker-machine ls

NAME   ACTIVE   DRIVER       STATE     URL                         SWARM   DOCKER        ERRORS
aws    *        amazonec2    Running   tcp://34.207.173.181:2376           v17.05.0-ce
dev    -        virtualbox   Running   tcp://192.168.99.100:2376           v17.05.0-ce

Other Commands

Want to force a build?

$ docker-compose build --no-cache

Remove images:

$ docker rmi $(docker images -q)

Reset Docker environment back to localhost, unsetting all Docker environment variables:

$ eval $(docker-machine env -u)


Workflow

Updated reference guide...

All Services

The following commands are for spinning up all the containers...

Environment Variables

Development:

$ export REACT_APP_USERS_SERVICE_URL=http://DOCKER_MACHINE_DEV_IP
$ export TEST_URL=http://DOCKER_MACHINE_DEV_IP

Staging:

$ export REACT_APP_USERS_SERVICE_URL=http://DOCKER_MACHINE_STAGING_IP
$ export SECRET_KEY=SOMETHING_SUPER_SECRET
$ export TEST_URL=http://DOCKER_MACHINE_STAGING_IP

Production:

$ export REACT_APP_USERS_SERVICE_URL=http://DOCKER_MACHINE_PROD_IP
$ export SECRET_KEY=SOMETHING_SUPER_SECRET
$ export TEST_URL=http://DOCKER_MACHINE_PROD_IP
Start

Build the images:

$ docker-compose build

Run the containers:

$ docker-compose up -d

Create and seed the database:

$ docker-compose run users-service python manage.py recreate_db
$ docker-compose run users-service python manage.py seed_db

Run the unit and integration tests:

$ docker-compose run users-service python manage.py test

Run the e2e tests:

$ testcafe chrome e2e
Stop

Stop the containers:

$ docker-compose stop

Bring down the containers:

$ docker-compose down

Remove images:

$ docker rmi $(docker images -q)

Individual Services

The following commands are for spinning up individual containers...

Users DB

Build and run:

$ docker-compose up -d --build users-db

Test:

$ docker exec -ti users-db psql -U postgres -W
Users

Build and run:

$ docker-compose up -d --build users-service

Create and seed the database:

$ docker-compose run users-service python manage.py recreate_db
$ docker-compose run users-service python manage.py seed_db

Run the unit and integration tests:

$ docker-compose run users-service python manage.py test
Web

Set env variable:

$ export REACT_APP_USERS_SERVICE_URL=http://DOCKER_MACHINE_DEV_IP

Build and run:

$ docker-compose up -d --build web-service

To test, navigate to http://DOCKER_MACHINE_DEV_IP:9000 in your browser.

Keep in mind that you won't be able to register or log in until Nginx is set up

To take advantage of auto/hot/live reload, it is recommended to develop out of the container. Navigate to the flask-microservices-client directory, set the env variable:

$ export REACT_APP_USERS_SERVICE_URL=http://DOCKER_MACHINE_DEV_IP

Then run npm start.

Nginx

Build and run:

$ docker-compose up -d --build nginx

To test, navigate to http://DOCKER_MACHINE_DEV_IP in your browser. Also, run the e2e tests:

$ export TEST_URL=http://DOCKER_MACHINE_DEV_IP
$ testcafe chrome e2e
Swagger

Build and run:

$ docker-compose up -d --build swagger

To test, navigate to http://DOCKER_MACHINE_DEV_IP:8080 in your browser.

Aliases

To save some previous keystrokes, create aliases for both the docker-compose and docker-machine commands - dc and dm, respectively.

Simply add the following lines to your .bashrc file:

alias dc='docker-compose'
alias dm='docker-machine'

Save the file, then execute it:

$ source ~/.bashrc

Test out the new aliases!

On Windows? You will first need to create a PowerShell Profile (if you don't already have one), and then you can add the aliases to it using Set-Alias - i.e., Set-Alias dc docker-compose.

"Saved" State

Is the VM stuck in a "Saved" state?

$ docker-machine ls

NAME   ACTIVE   DRIVER       STATE     URL                         SWARM   DOCKER        ERRORS
aws    *        amazonec2    Running   tcp://34.207.173.181:2376           v17.05.0-ce
dev    -        virtualbox   Saved                                         Unknown

To break out of this, you'll need to power off the VM:

  1. Start virtualbox - virtualbox
  2. Select the VM and click "start"
  3. Exit the VM and select "Power off the machine"
  4. Exit virtualbox

The VM should now have a "Stopped" state:

$ docker-machine ls

NAME   ACTIVE   DRIVER       STATE     URL                         SWARM   DOCKER        ERRORS
aws    *        amazonec2    Running   tcp://34.207.173.181:2376           v17.05.0-ce
dev    -        virtualbox   Stopped                                       Unknown

Now you can start the machine:

$ docker-machine start dev

It should be "Running":

$ docker-machine ls

NAME   ACTIVE   DRIVER       STATE     URL                         SWARM   DOCKER        ERRORS
aws    *        amazonec2    Running   tcp://34.207.173.181:2376           v17.05.0-ce
dev    -        virtualbox   Running   tcp://192.168.99.100:2376           v17.05.0-ce

Other Commands

Want to force a build?

$ docker-compose build --no-cache

Remove images:

$ docker rmi $(docker images -q)

Reset Docker environment back to localhost, unsetting all Docker environment variables:

$ eval $(docker-machine env -u)