-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makefile
83 lines (72 loc) · 2.75 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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# Project variables
PROJECT_NAME ?= musings-fe
TARGET_MAX_CHAR_NUM=10
# File names
DOCKER_DEV_COMPOSE_FILE := docker-compose.yml
.PHONY: help build start stop clean
#@-- help command to show usage of make commands --@#
help:
@echo ''
@echo 'Usage:'
@echo '${YELLOW} make ${RESET} ${GREEN}<target> [options]${RESET}'
@echo ''
@echo 'Targets:'
@awk '/^[a-zA-Z\-\_0-9]+:/ { \
message = match(lastLine, /^## (.*)/); \
if (message) { \
command = substr($$1, 0, index($$1, ":")-1); \
message = substr(lastLine, RSTART + 3, RLENGTH); \
printf " ${YELLOW}%-$(TARGET_MAX_CHAR_NUM)s${RESET} %s\n", command, message; \
} \
} \
{ lastLine = $$0 }' $(MAKEFILE_LIST)
@echo ''
#@-- command to build the application image--@#
background:
@ ${INFO} "Building required docker images"
@ docker-compose -f $(DOCKER_DEV_COMPOSE_FILE) build web
@ ${INFO} "Starting background local development server"
@ docker-compose -f $(DOCKER_DEV_COMPOSE_FILE) up -d
#@-- command to start the application container --@#
start:
@ ${INFO} "Building required docker images"
@ docker-compose -f $(DOCKER_DEV_COMPOSE_FILE) build web
@ ${SUCCESS} "Build Completed successfully"
@ echo " "
@ ${INFO} "Starting local development server"
@ docker-compose -f $(DOCKER_DEV_COMPOSE_FILE) up -d
#@-- command to stop the application container --@#
stop:
${INFO} "Stop development server containers"
@ docker-compose -f $(DOCKER_DEV_COMPOSE_FILE) down -v
${SUCCESS} "All containers stopped successfully"
#@-- command to test the application --@#
test:background
@ ${INFO} "Running tests in docker container"
@ docker-compose -f $(DOCKER_DEV_COMPOSE_FILE) exec web yarn test
#@-- command to remove the images created --@#
clean:
${INFO} "Cleaning your local environment"
${EXTRA} "Note all ephemeral volumes will be destroyed"
@ docker-compose -f $(DOCKER_DEV_COMPOSE_FILE) down -v
@ docker images -q -f label=application=$(PROJECT_NAME) | xargs -I ARGS docker rmi -f ARGS
${INFO} "Removing dangling images"
@ docker system prune
${SUCCESS} "Clean complete"
#@-- command to ssh into service container --@#
ssh:background
${INFO} "Opening web container terminal"
@ docker-compose -f $(DOCKER_DEV_COMPOSE_FILE) exec web bash
#@-- help should be run by default when no command is specified --@#
default: help
# COLORS
GREEN := $(shell tput -Txterm setaf 2)
YELLOW := $(shell tput -Txterm setaf 3)
WHITE := $(shell tput -Txterm setaf 7)
MAGENTA := $(shell tput -Txterm setaf 5)
NC := "\e[0m"
RESET := $(shell tput -Txterm sgr0)
# Shell Functions
INFO := @bash -c 'printf $(YELLOW); echo "===> $$1"; printf $(NC)' SOME_VALUE
EXTRA := @bash -c 'printf "\n"; printf $(MAGENTA); echo "===> $$1"; printf "\n"; printf $(NC)' SOME_VALUE
SUCCESS := @bash -c 'printf $(GREEN); echo "===> $$1"; printf $(NC)' SOME_VALUE