Last active
January 16, 2018 19:16
-
-
Save xcoulon/026164a1fbcf0a27a3316dd052808c23 to your computer and use it in GitHub Desktop.
Makefile for the go-url-shortener app
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# If nothing was specified, run all targets as if in a fresh clone | |
.PHONY: all | |
## Default target | |
all: start-db build kill-db clean | |
POSTGRES_PASSWORD:=mysecretpassword | |
UNAME_S := $(shell uname -s) | |
.PHONY: init | |
init: | |
@rm -rf .tmp | |
@mkdir .tmp | |
.PHONY: clean | |
clean: | |
@rm -rf .tmp | |
.PHONY: start-db | |
start-db: init | |
@echo "starting the test db container..." | |
ifeq ($(UNAME_S),Darwin) | |
@echo "docker.for.mac.host.internal" > .tmp/postgres.host | |
else | |
@echo "localhost" > .tmp/postgres.host | |
endif | |
docker run -P -d --cidfile .tmp/postgres.cid -e POSTGRES_PASSWORD=$(POSTGRES_PASSWORD) postgres:10.1 > /dev/null | |
docker inspect `cat .tmp/postgres.cid` \ | |
--format='{{ with index .NetworkSettings.Ports "5432/tcp" }}{{ with index . 0 }}{{ index . "HostPort" }}{{ end }}{{ end }}' \ | |
> .tmp/postgres.port | |
@echo "test db instance is listening on `cat .tmp/postgres.host`:`cat .tmp/postgres.port`" | |
.PHONY: build | |
build: start-db | |
@echo "building the application image..." | |
docker build --build-arg POSTGRES_HOST=`cat .tmp/postgres.host` \ | |
--build-arg POSTGRES_PORT=`cat .tmp/postgres.port` \ | |
--build-arg POSTGRES_PASSWORD=$(POSTGRES_PASSWORD) \ | |
. \ | |
-t xcoulon/go-url-shortener:latest | |
.PHONY: kill-db | |
kill-db: | |
@echo "killing the test db container..." | |
docker rm -f `cat .tmp/postgres.cid` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment