-
-
Notifications
You must be signed in to change notification settings - Fork 17
/
Makefile
271 lines (209 loc) · 6.64 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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
# Include file with .env variables if exists
-include .env
# Define default values for variables
COMPOSE_FILE ?= docker-compose.yml
BASE_IMAGE_DOCKERFILE ?= ./.docker/prod/base/Dockerfile
IMAGE_REGISTRY ?= prod
IMAGE_TAG ?= latest
#-----------------------------------------------------------
# Management
#-----------------------------------------------------------
# Create shared gateway network
gateway:
docker network create gateway
# Init variables for development environment
env.dev:
cp ./.env.dev ./.env
# Init variables for production environment
env.prod:
cp ./.env.prod ./.env
# Build and restart containers
install: build.all up
# Start containers
up:
docker-compose -f ${COMPOSE_FILE} up -d
# Stop containers
down:
docker-compose -f ${COMPOSE_FILE} down --remove-orphans
# Build containers
build:
docker-compose -f ${COMPOSE_FILE} build
# Build all containers
build.all: build.base build
# Build the base app image
build.base:
docker build --file ${BASE_IMAGE_DOCKERFILE} --tag ${IMAGE_REGISTRY}/genealogy:${IMAGE_TAG} .
# Show list of running containers
ps:
docker-compose -f ${COMPOSE_FILE} ps
# Restart containers
restart:
docker-compose -f ${COMPOSE_FILE} restart
# Reboot containers
reboot: down up
# View output from containers
logs:
docker-compose -f ${COMPOSE_FILE} logs --tail 500
# Follow output from containers (short of 'follow logs')
fl:
docker-compose -f ${COMPOSE_FILE} logs --tail 500 -f
# Prune stopped docker containers and dangling images
prune:
docker system prune
#-----------------------------------------------------------
# Application
#-----------------------------------------------------------
# Enter the app container
app.bash:
docker-compose -f ${COMPOSE_FILE} exec app /bin/bash
# Restart the app container
restart.app:
docker-compose -f ${COMPOSE_FILE} restart app
# Alias to restart the app container
ra: restart.app
# Run the tinker service
tinker:
docker-compose -f ${COMPOSE_FILE} exec app php artisan tinker
# Clear the app cache
cache.clear:
docker-compose -f ${COMPOSE_FILE} exec app php artisan cache:clear
# Migrate the database
db.migrate:
docker-compose -f ${COMPOSE_FILE} exec app php artisan migrate
# Alias to migrate the database
migrate: db.migrate
# Rollback the database
db.rollback:
docker-compose -f ${COMPOSE_FILE} exec app php artisan migrate:rollback
# Seed the database
db.seed:
docker-compose -f ${COMPOSE_FILE} exec app php artisan db:seed
# Fresh the database state
db.fresh:
docker-compose -f ${COMPOSE_FILE} exec app php artisan migrate:fresh
# Refresh the database
db.refresh: db.fresh db.seed
# Dump database into file (only for development environment) (TODO: replace file name with env variable)
db.dump:
docker-compose -f ${COMPOSE_FILE} exec postgres pg_dump -U ${DB_USERNAME} -d ${DB_DATABASE} > ./.docker/postgres/dumps/dump.sql
# TODO: add command to import db dump
# Restart the queue process
queue.restart:
docker-compose -f ${COMPOSE_FILE} exec queue php artisan queue:restart
# Install composer dependencies
composer.install:
docker-compose -f ${COMPOSE_FILE} exec app composer install
# Install composer dependencies from stopped containers
r.composer.install:
docker-compose -f ${COMPOSE_FILE} run --rm --no-deps app composer install
# Alias to install composer dependencies
ci: composer.install
# Update composer dependencies
composer.update:
docker-compose -f ${COMPOSE_FILE} exec app composer update
# Alias to update composer dependencies
cu: composer.update
# Show outdated composer dependencies
composer.outdated:
docker-compose -f ${COMPOSE_FILE} exec app composer outdated
# PHP composer autoload command
composer.autoload:
docker-compose -f ${COMPOSE_FILE} exec app composer dump-autoload
# Generate a symlink to the storage directory
storage.link:
docker-compose -f ${COMPOSE_FILE} exec app php artisan storage:link --relative
# Give permissions of the storage folder to the www-data
storage.perm:
sudo chmod -R 755 storage
sudo chown -R www-data:www-data storage
# Give permissions of the storage folder to the current user
storage.perm.me:
sudo chmod -R 755 storage
sudo chown -R "$(shell id -u):$(shell id -g)" storage
# Give files ownership to the current user
own.me:
sudo chown -R "$(shell id -u):$(shell id -g)" .
# Reload the Octane workers
octane.reload:
docker-compose -f ${COMPOSE_FILE} exec app php artisan octane:reload
# Alias to reload the Octane workers
or: octane.reload
#-----------------------------------------------------------
# Testing (only for development environment)
#-----------------------------------------------------------
# Run phpunit tests (requires 'phpunit/phpunit' composer package)
test:
docker-compose -f ${COMPOSE_FILE} exec app ./vendor/bin/phpunit --order-by=defects --stop-on-defect
# Alias to run phpunit tests
t: test
# Run phpunit tests with the coverage mode (TODO: install PCOV or other lib)
coverage:
docker-compose -f ${COMPOSE_FILE} exec app ./vendor/bin/phpunit --coverage-html ./.coverage
# Run dusk tests (requires 'laravel/dusk' composer package)
dusk:
docker-compose -f ${COMPOSE_FILE} exec app php artisan dusk
# Generate code metrics (requires 'phpmetrics/phpmetrics' composer package)
metrics:
docker-compose -f ${COMPOSE_FILE} exec app ./vendor/bin/phpmetrics --report-html=./.metrics api/app
#-----------------------------------------------------------
# Redis
#-----------------------------------------------------------
# Enter the redis container
redis:
docker-compose -f ${COMPOSE_FILE} exec redis redis-cli
# Flush the redis state
redis.flush:
docker-compose -f ${COMPOSE_FILE} exec redis redis-cli FLUSHALL
#-----------------------------------------------------------
# Swarm
#-----------------------------------------------------------
# Deploy the stack
swarm.deploy:
docker stack deploy --compose-file ${COMPOSE_FILE} api
# Remove/stop the stack
swarm.rm:
docker stack rm api
# List of stack services
swarm.services:
docker stack services api
# List the tasks in the stack
swarm.ps:
docker stack ps api
# Init the Docker Swarm Leader node
swarm.init:
docker swarm init
#-----------------------------------------------------------
# Danger zone
# Do not use these commands
#-----------------------------------------------------------
# Remove all app files and folders (leave only dockerized template)
danger.app.prune:
sudo rm -rf \
.idea \
.vscode \
.vscode \
app \
bootstrap \
config \
database \
lang \
public \
resources \
routes \
storage \
vendor \
tests \
.editorconfig \
.env \
.env.example \
.gitattributes \
.gitignore \
.phpunit.result.cache \
.styleci.yml \
artisan \
composer.json \
composer.lock \
package.json \
phpunit.xml \
README.md \
webpack.mix.js