-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
162 lines (130 loc) · 4.71 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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
#
# For more information on some of the magic targets, variables and flags used, see:
# - [1] https://www.gnu.org/software/make/manual/html_node/Special-Targets.html
# - [2] https://www.gnu.org/software/make/manual/html_node/Secondary-Expansion.html
# - [3] https://www.gnu.org/software/make/manual/html_node/Suffix-Rules.html
# - [4] https://www.gnu.org/software/make/manual/html_node/Options-Summary.html
# - [5] https://www.gnu.org/software/make/manual/html_node/Special-Variables.html
#
# Ensure (intermediate) targets are deleted when an error occurred executing a recipe, see [1]
.DELETE_ON_ERROR:
# Enable a second expansion of the prerequisites, see [2]
.SECONDEXPANSION:
# Disable built-in implicit rules and variables, see [3, 4]
.SUFFIXES:
MAKEFLAGS += --no-builtin-rules
MAKEFLAGS += --no-builtin-variables
# Disable printing of directory changes, see [4]
MAKEFLAGS += --no-print-directory
# Warn about undefined variables -- useful during development of makefiles, see [4]
MAKEFLAGS += --warn-undefined-variables
# Show an auto-generated help if no target is provided, see [5]
.DEFAULT_GOAL := help
help:
@echo
@printf "%-20s %s\n" Target Description
@echo
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-20s\033[0m %s\n", $$1, $$2}'
@echo
#
# PROJECT TARGETS
#
# To learn more about automatic variables that can be used in target recipes, see:
# https://www.gnu.org/software/make/manual/html_node/Automatic-Variables.html
#
PROJECT := eve
# Target that makes sure containers are built
CONTAINERS = $(shell find docker -name Dockerfile | sed 's/Dockerfile/.build/')
# Runtime dependencies
RUNTIME-DEPENDENCIES = traefik vendor/composer/installed.json $(CONTAINERS)
# Passed from ENV by travis-ci, but if not available use HEAD (currently checked out commit)
TRAVIS_COMMIT ?= $(shell git rev-parse HEAD)
# Take the short hash as release version
RELEASE = $(shell git rev-parse --short $(TRAVIS_COMMIT))
# Docker permissions
DOCKER_UID = $(shell id -u)
DOCKER_GID = $(shell id -g)
DOCKER_USER = $(DOCKER_UID):$(DOCKER_GID)
export DOCKER_UID
export DOCKER_GID
.PHONY: traefik-network
traefik-network:
-docker network create traefik
.PHONY: traefik
traefik: traefik-network
traefik: ## run traefik
@docker inspect -f {{.State.Running}} traefik &>/dev/null || docker run \
--restart unless-stopped \
--name traefik \
--network traefik \
--volume /var/run/docker.sock:/var/run/docker.sock \
--publish 80:80 \
--expose 8080 \
--label traefik.port=8080 \
--label traefik.enable=true \
--detach \
traefik --api --accesslog --docker --docker.domain=localhost --docker.exposedbydefault=false
.PHONY: traefik-cleanup
traefik-cleanup: ## clean up traefik
@docker stop traefik &>/dev/null
@docker rm traefik &>/dev/null
@-docker network rm traefik &>/dev/null
.PHONY: traefik-restart
traefik-restart: traefik-cleanup traefik
traefik-restart: ## restart traefik
.PHONY: containers
containers: $(CONTAINERS)
containers: ## build all containers
@touch $(CONTAINERS)
.PHONY: fg
fg: $(RUNTIME-DEPENDENCIES)
fg: ## launch the docker-compose setup (foreground)
docker-compose --project-name $(PROJECT) up --remove-orphans --abort-on-container-exit
.PHONY: up
up: $(RUNTIME-DEPENDENCIES)
up: ## launch the docker-compose setup (background)
docker-compose --project-name $(PROJECT) up --remove-orphans --detach
.PHONY: down
down: ## terminate the docker-compose setup
-docker-compose --project-name $(PROJECT) down --remove-orphans
.PHONY: logs
logs: $(RUNTIME-DEPENDENCIES)
logs: ## show logs
docker-compose --project-name $(PROJECT) logs
.PHONY: tail
tail: $(RUNTIME-DEPENDENCIES)
tail: ## tail logs
docker-compose --project-name $(PROJECT) logs -f
.PHONY: shell
shell: export APP_ENV := dev
shell: export COMPOSER_HOME := /tmp
shell: $(RUNTIME-DEPENDENCIES)
shell: ## spawn a shell inside a php-fpm container
docker-compose --project-name $(PROJECT) run --rm -e APP_ENV -e COMPOSER_HOME --user $(DOCKER_USER) --name pastebin-shell php-fpm sh
#
# PATH BASED TARGETS
#
docker/%/.build: $$(shell find $$(@D) -type f -not -name .build)
docker-compose build $*
@touch $@
var/cache:
mkdir -p $@
var/log:
mkdir -p $@
vendor:
mkdir -p $@
vendor/composer/installed.json: export APP_ENV := dev
vendor/composer/installed.json: export COMPOSER_HOME := /tmp
vendor/composer/installed.json: composer.json composer.lock vendor var/cache var/log $(CONTAINERS)
docker run --rm \
--interactive \
--env APP_ENV \
--env COMPOSER_HOME \
--user $(DOCKER_USER) \
--volume /etc/passwd:/etc/passwd:ro \
--volume /etc/group:/etc/group:ro \
--volume $(shell pwd):/app \
--workdir /app \
--name pastebin-composer \
composer install --no-interaction --no-progress --no-suggest --prefer-dist
@touch $@