developing and testing microservices with docker
Check out the blog post.
Fork/Clone this repo
Download Docker (if necessary)
Make sure you are using a Docker version >= 17:
$ docker -v
Docker version 17.03.0-ce, build 60ccb22
$ export NODE_ENV=development
Register with the OpenWeatherMap API, and add the key as an environment variable:
$ export OPENWEATHERMAP_API_KEY=YOUR_KEY_HERE
Build the images:
$ docker-compose build
Run the containers:
$ docker-compose up -d
With the apps up, run:
$ sh migrate.sh
Test out the following services...
Endpoint | HTTP Method | CRUD Method | Result |
---|---|---|---|
/users/ping | GET | READ | pong |
/users/register | POST | CREATE | add a user |
/users/login | POST | CREATE | log in a user |
/users/user | GET | READ | get user info |
Endpoint | HTTP Method | CRUD Method | Result |
---|---|---|---|
/locations/ping | GET | READ | pong |
/locations | GET | READ | get all locations |
/locations/user | GET | READ | get all locations by user |
/locations/:id | GET | READ | get a single location |
/locations | POST | CREATE | add a single location |
/locations/:id | PUT | UPDATE | update a single location |
/locations/:id | DELETE | DELETE | delete a single location |
Endpoint | HTTP Method | CRUD Method | Result |
---|---|---|---|
/ | GET | READ | render main page |
/login | GET | READ | render login page |
/login | POST | CREATE | log in a user |
/register | GET | READ | render register page |
/register | POST | CREATE | register a new user |
/logout | GET | READ | log a user out |
/add | POST | CREATE | add a new location |
/user | GET | READ | get user info |
To access, get the container id from docker ps
and then open psql
:
$ docker exec -ti <container-id> psql -U postgres
With the app running, update the NODE_ENV environment variable and then run the tests
:
$ export NODE_ENV=test
$ docker-compose up -d
$ docker-compose run tests npm test
Update NODE_ENV
when you're ready to develop again:
$ export NODE_ENV=development
$ docker-compose up -d
To stop the containers:
$ docker-compose stop
To bring down the containers:
$ docker-compose down
Want to force a build?
$ docker-compose build --no-cache
Remove images:
$ docker rmi $(docker images -q)
Run unit and integration tests:
$ export NODE_ENV=test
$ docker-compose up -d
$ docker-compose run users-service npm test
$ docker-compose run locations-service npm test