Skip to content

Commit

Permalink
config: add a Makefile to run and manage docker environment
Browse files Browse the repository at this point in the history
create a Makefile inspired by gazr normalization to be able to easily
deploy and manage the docker environment.
this config let you launch basic docker-compose command to run and
manage the services inside containers.
add a section to the USER_GUIDE to explain how to use the Makefile
commands to run your environment.

Fixes: MLH#3
Refs: https://gazr.io/
  • Loading branch information
antoine-amara committed Apr 12, 2019
1 parent d9288f2 commit a24a9fd
Show file tree
Hide file tree
Showing 2 changed files with 116 additions and 0 deletions.
59 changes: 59 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
##
# MLH Hackathon Nodejs Starter
# commands to run and manipulate docker environment
##
DKR=docker-compose
NODE=nodejs

default: help;

init: ## initialize your environment from the begining, build docker stuff, install dependencies and run the watch mode.
${DKR} build
make dependencies
make watch

watch: ## run the application in development mode with a live reload, display the status of the containers and display the logs.
${DKR} up -d
make status
echo ""
make logs

run: ## run the production mode of the app, no livereload here, just launch nodejs and display the status of components.
${DKR} run --rm ${NODE} npm run deploy
make status

stop: ## stop the entire application, the database data is preserved.
${DKR} down

restart: ## restart all components (nodejs and database).
make stop
make watch

dependencies: ## install (or reinstall) npm dependencies.
${DKR} run --rm ${NODE} npm install

status: ## display status of each component, Up -> UNIX process is running. Exit -> UNIX process was killed or crash.
${DKR} ps

logs: ## display nodejs server logs.
${DKR} logs -f ${NODE}

command: ## launch a bash command inside your environment. example: make command cmd="npm install --save express"
${DKR} run --rm ${NODE} ${cmd}

destroy: ## stop, clean and destroy everything. delete node_modules, destroy process and delete the entire database.
read -p "This command will stop your env, clean the repo and destroy the database. Did you want to continue? (y/n)" resp ; \
echo "" ; \
if [ "$$resp" = "y" ]; then \
${DKR} run --rm ${NODE} rm -rf ./node_modules ; ${DKR} down -v --remove-orphans ; \
fi

help: ## display this help.
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' ${MAKEFILE_LIST} | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'

.PHONY:
init watch run stop restart dependencies status logs destroy
.SILENT:
init watch run stop restart dependencies status logs destroy

# end
57 changes: 57 additions & 0 deletions docs/USER_GUIDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,63 @@ The `DATABASE_URL` variable is the path to your database system. This is where y

The `GITHUB_CLIENT_ID` and `GITHUB_CLIENT_SECRET` variables are the app credentials from your [GitHub OAuth app](https://github.com/settings/developers).

## <a name='docker'>Deploy development environment with docker</a>

You can easily and quickly deploy an environment with Docker containers. A
Makefile is available with some commands to quick and easy launch.

### What you need ?

* a docker daemon running on your machine.
* docker-compose tools to be able to launch the environment.

### How to use.

The first time you want to launch the environment, you have to initialize it
(build stuff for docker and install the dependencies), for that just launch:

```sh
make init
```

This command will initialize and launch the entire process in watch mode.
(Nodejs process with livereload).

If your environment was already been initialized, you can just use a command to
run the application:

```sh
make watch # run the nodejs app in development mode with a livereload.
# OR
make run # run the nodejs app in production mode.
```

If you want to visualize the logs of the Nodejs app:

```sh
make logs
```

If you want to switch off your environment:

```sh
make stop
```

Finally, when your work is finished and you don't need the environment at all,
you can stop and destroy all stuff and data (node_modules and database data):

```sh
make destroy
```

**Note**: if you want advanced commands for this docker environment, consult the
help:

```sh
make help
```

## Deployment

### Deploy to Heroku
Expand Down

0 comments on commit a24a9fd

Please sign in to comment.