-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
44 lines (36 loc) · 1.49 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
DOCKER_NAME=stock-check
DOCKER_TAG?=$(shell git rev-parse --short=7 HEAD)
DB_CONTAINER_NAME=postgres-$(DOCKER_TAG)
DB_IMAGE=postgres:10-alpine
DOCKER_BUILD_CONTEXT=./
db: clean start-db migrate
start-db:
docker run --rm -d \
--name=$(DB_CONTAINER_NAME) \
-e POSTGRES_PASSWORD=dev \
-p 5432:5432 \
$(DB_IMAGE)
# Wait for postgres server to start & be ready (accept incoming connections)
while ! docker exec $(DB_CONTAINER_NAME) pg_isready -h localhost -d postgres -U postgres; do sleep 2; done
ifeq "" "$(shell command -v sql-migrate 2> /dev/null)"
SQL_MIGRATE=docker run --rm --net=container:$(DB_CONTAINER_NAME) $(DOCKER_NAME):$(DOCKER_TAG) sql-migrate
else
SQL_MIGRATE=sql-migrate
endif
# If sql-migrate is available locally, use that - otherwise use the application image
# NOTE: If you're doing local development and don't have sql-migrate installed, you'll
# have to run `make docker-build` before this
migrate:
ifneq "$(SQL_MIGRATE)" "sql-migrate"
@echo -e "\n\n=> Running migrations in docker, since you don't have 'sql-migrate' installed."
@echo "=> If this fails, try running 'make docker-build' before running again."
@echo -e "=> Or, install github.com/rubenv/sql-migrate to make these migrations run faster locally.\n\n"
endif
$(SQL_MIGRATE) up -config=./database/migrations/user.dbconfig.yml --env localtest
docker-build:
docker build \
-f $(DOCKER_BUILD_CONTEXT)/Dockerfile \
-t $(DOCKER_NAME):$(DOCKER_TAG) \
$(DOCKER_BUILD_CONTEXT)
clean:
docker rm -f $(DB_CONTAINER_NAME) || true