Skip to content
This repository has been archived by the owner on Oct 24, 2022. It is now read-only.

Commit

Permalink
Fix development/test environment workflow using Make and Docker
Browse files Browse the repository at this point in the history
  • Loading branch information
suvash committed Oct 9, 2017
1 parent 1dab010 commit e8037b5
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 21 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ All notable changes to this project will be documented in this file. This change

## [Unreleased]
### Fixed
- Fix `Makefile`, `Dockerfile`, `docker-compose.yml` and `README.md` for better development environment workflow.
- Fix `extras` params in docs for `mix.exs`, so that docs are generated properly in `hex.pm`

## [0.1.0] - 2017-08-12
Expand Down
10 changes: 7 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
FROM elixir:1.5.1
ENV DEBIAN_FRONTEND="noninteractive"

RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app

COPY ./mix.* /usr/src/app/
RUN yes | mix do deps.get \
&& yes | MIX_ENV=test mix do deps.get, deps.compile
COPY mix.exs mix.lock /usr/src/app/
COPY config /usr/src/app/config
RUN mix local.hex --force \
&& mix local.rebar --force \
&& mix deps.get \
&& mix deps.compile

COPY . /usr/src/app
CMD ["elixir"]
49 changes: 33 additions & 16 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,24 +1,41 @@
.DEFAULT_GOAL:=test
.PHONY: run bash test tail-mqtt tail-mqtt-tls stop prune
.DEFAULT_GOAL:=help
SHELL:=/bin/bash

RUN_SERVICE:=hulaaki
HULAAKI_SERVICE:=hulaaki
MQTT_SERVICE:=mqtt_server

run:
$(if $(CMD), docker-compose run --rm $(RUN_SERVICE) $(CMD), $(error -- CMD must be set))
DOCKER_COMPOSE:=docker-compose -f docker-compose.yml
DOCKER_COMPOSE_RUN_HULAAKI:=$(DOCKER_COMPOSE) run --rm $(HULAAKI_SERVICE)

bash: CMD=/bin/bash
bash: run
.PHONY: help build start stop stop-clean tail-logs run-hulaaki bash test prune

test: CMD=mix test
test: run
help: ## Display this help
$(info)
@awk 'BEGIN {FS = ":.*##"} /^[a-zA-Z_-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 }' $(MAKEFILE_LIST)

build: ## (Force) Build the docker images (automatically run by `make start`)
$(DOCKER_COMPOSE) build

start: build ## Start the MQTT service container daemonised
$(DOCKER_COMPOSE) up -d $(MQTT_SERVICE)

stop: ## Stop all the service containers
$(DOCKER_COMPOSE) down

start:
docker-compose up -d $(MQTT_SERVICE)
stop-clean: ## Stop all the service containers, cleanup project images, dangling/orphaned volumes
$(DOCKER_COMPOSE) down --rmi local --volumes --remove-orphans

tail-logs:
docker-compose logs -f $(MQTT_SERVICE)
tail-logs: ## Tail the logs for MQTT service container
$(DOCKER_COMPOSE) logs -f $(MQTT_SERVICE)

run-hulaaki: ## Run a one-off command in a new hulaaki service container. Specify using CMD (eg. make run-web CMD=mix test)
$(if $(CMD), $(DOCKER_COMPOSE_RUN_HULAAKI) $(CMD), $(error -- CMD must be set))

bash: CMD=/bin/bash
bash: run-hulaaki ## Spawn a bash shell for hulaaki service

test: CMD=mix test
test: run-hulaaki ## Run the test for hulaaki service

stop:
docker-compose down
docker system prune -f
prune: ## Cleanup dangling/orphaned docker resources globally
docker system prune --volumes -f
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,14 @@ standard ports), you should just be able to run `mix test` as you
would do on other mix projects.

As prefered by the author, you can also use the provided Makefile to
run the tests. The only dependency required is Docker on your machine.
run the tests. In that case, you'll need the following on your machine
- GNU Make ( Version 4.0 and up )
- [Docker Engine](https://docs.docker.com/engine/installation/) ( Version 17.06.1 and hopefully upwards )
- [Docker Compose](https://github.com/docker/compose/releases) ( Version 1.16.1 and hopefully upwards )

```
# Make sure you have Docker and Docker Compose running on your machine
# Get help
$ make help
# Start the MQTT servers (better to start separately to warm them up)
$ make start
Expand Down
1 change: 1 addition & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ services:
restart: always
volumes:
- ./:/usr/src/app
- /usr/src/app/deps
depends_on:
- mqtt_server
links:
Expand Down

0 comments on commit e8037b5

Please sign in to comment.