Workflow

Part 5, Lesson 9



Updated reference guide...

Development Environment

The following commands are for spinning up all the containers in your development environment...

Environment Variables
$ export REACT_APP_USERS_SERVICE_URL=http://DOCKER_MACHINE_DEV_IP
$ export TEST_URL=http://DOCKER_MACHINE_DEV_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

Enter psql:

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

Stop the containers:

$ docker-compose stop

Bring down the containers:

$ docker-compose down

Aliases

To save some precious 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 exited containers:

$ docker rm -v $(docker ps -a -q -f status=exited)

Remove images:

$ docker rmi $(docker images -q)

Remove untagged images:

$ docker rmi $(docker images | grep “^<none>” | awk ‘{print $3})

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

$ eval $(docker-machine env -u)

Development Workflow

Try out the following development workflow...

Development:

  1. Create a new feature branch from the master branch
  2. Make code changes locally
  3. Open PR against the development branch
  4. New build is triggered on Travis CI
  5. If the tests pass, merge the PR
  6. New build is triggered on Travis CI
  7. If the tests pass, images are created, tagged development, and pushed to Docker Hub

Staging:

  1. Open PR from the development branch against the staging branch
  2. New build is triggered on Travis CI
  3. If the tests pass, merge the PR
  4. New build is triggered on Travis CI
  5. If the tests pass, images are created, tagged staging, and pushed to ECR

Production:

  1. Open PR from the development branch against the staging branch
  2. New build is triggered on Travis CI
  3. If the tests pass, merge the PR
  4. New build is triggered on Travis CI
  5. If the tests pass, images are created, tagged production, and pushed to ECR
  6. Merge the changes into the master branch

Workflow

Updated reference guide...

Development Environment

The following commands are for spinning up all the containers in your development environment...

Environment Variables
$ export REACT_APP_USERS_SERVICE_URL=http://DOCKER_MACHINE_DEV_IP
$ export TEST_URL=http://DOCKER_MACHINE_DEV_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

Enter psql:

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

Stop the containers:

$ docker-compose stop

Bring down the containers:

$ docker-compose down

Aliases

To save some precious 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 exited containers:

$ docker rm -v $(docker ps -a -q -f status=exited)

Remove images:

$ docker rmi $(docker images -q)

Remove untagged images:

$ docker rmi $(docker images | grep “^<none>” | awk ‘{print $3})

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

$ eval $(docker-machine env -u)

Development Workflow

Try out the following development workflow...

Development:

  1. Create a new feature branch from the master branch
  2. Make code changes locally
  3. Open PR against the development branch
  4. New build is triggered on Travis CI
  5. If the tests pass, merge the PR
  6. New build is triggered on Travis CI
  7. If the tests pass, images are created, tagged development, and pushed to Docker Hub

Staging:

  1. Open PR from the development branch against the staging branch
  2. New build is triggered on Travis CI
  3. If the tests pass, merge the PR
  4. New build is triggered on Travis CI
  5. If the tests pass, images are created, tagged staging, and pushed to ECR

Production:

  1. Open PR from the development branch against the staging branch
  2. New build is triggered on Travis CI
  3. If the tests pass, merge the PR
  4. New build is triggered on Travis CI
  5. If the tests pass, images are created, tagged production, and pushed to ECR
  6. Merge the changes into the master branch