-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathMakefile
171 lines (137 loc) · 4.63 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
LARADOCK=laradock
# container names
PHP_CONTAINER_NAME=$(LARADOCK)_php-fpm_1
DB_CONTAINER_NAME=$(LARADOCK)_mysql_1
WORKSPACE_CONTAINER_NAME=$(LARADOCK)_workspace_1
REDIS_CONTAINER_NAME=$(LARADOCK)_redis_1
HORIZON_CONTAINER_NAME=$(LARADOCK)_laravel-horizon_1
NODE_IMAGE_NAME=node
# mysql variables
DB_DATABASE=default
DB_USERNAME=default
DB_PASSWORD=secret
# date
DATE=$(shell date +'%Y-%m-%d')
LIST_OF_CONTAINERS_TO_RUN=nginx mysql redis laravel-horizon workspace
# some variables that required by installation target
LARADOCK_REPO=https://github.com/bazavlukd/laradock.git
# the first target is the one that executed by default
# when uesr call make with no target.
# let's do nothing in this case
.PHONY: nop
nop:
@echo "Please pass a target you want to run"
# custom targets
# put them here
#--------
# clone the repo
# replace some variabls in laradock's .env file
# create and update .env file of laravel
# replace some env variables in laravel's .env file
.PHONY: install-laradock
install-laradock:
git clone $(LARADOCK_REPO) $(LARADOCK) && \
cp $(LARADOCK)/env-example $(LARADOCK)/.env && \
sed -i "/DATA_PATH_HOST=.*/c\DATA_PATH_HOST=..\/docker-data" $(LARADOCK)/.env && \
(test -s .env || cp .env.example .env) ; \
sed -i "/DB_CONNECTION=.*/c\DB_CONNECTION=mysql" .env && \
sed -i "/DB_HOST=.*/c\DB_HOST=mysql" .env && \
sed -i "/DB_DATABASE=.*/c\DB_DATABASE=$(DB_DATABASE)" .env && \
sed -i "/DB_USERNAME=.*/c\DB_USERNAME=$(DB_USERNAME)" .env && \
sed -i "/DB_PASSWORD=.*/c\DB_PASSWORD=$(DB_PASSWORD)" .env && \
sed -i "/REDIS_HOST=.*/c\REDIS_HOST=redis" .env && \
chmod -R 777 storage
# run initial scripts
# key generate
# fix mysql passwords
# run migrations/seeds
# install composer dependencies
# install js dependencies
.PHONY: initial-build
initial-build:
docker exec -it $(WORKSPACE_CONTAINER_NAME) composer install
docker exec -it $(PHP_CONTAINER_NAME) bash -c 'php artisan key:generate'
docker exec -it $(DB_CONTAINER_NAME) mysql -u root -proot -e "ALTER USER '$(DB_USERNAME)' IDENTIFIED WITH mysql_native_password BY '$(DB_PASSWORD)';";
docker exec -it $(PHP_CONTAINER_NAME) bash -c "php artisan migrate --seed"
docker exec -it $(WORKSPACE_CONTAINER_NAME) npm install
# run all containers
.PHONY: up
up:
cd $(LARADOCK) && docker-compose up -d $(LIST_OF_CONTAINERS_TO_RUN)
# stop all containers
.PHONY: down
down:
cd $(LARADOCK) && docker-compose down
# show laravel's log in realtime
.PHONY: log
log:
tail -f storage/logs/laravel-$(DATE).log
# show docker log
.PHONY: docker-log
docker-log:
cd $(LARADOCK) && docker-compose logs -f
# JOIN containers targets
.PHONY: join-workspace
join-workspace:
docker exec -it $(WORKSPACE_CONTAINER_NAME) bash
.PHONY: join-php
join-php:
docker exec -it $(PHP_CONTAINER_NAME) bash
.PHONY: join-db
join-db:
docker exec -it $(DB_CONTAINER_NAME) mysql -u default -p default
#------------------
# javascript related targets
.PHONY: build-js
build-js:
docker exec -it $(WORKSPACE_CONTAINER_NAME) npm run-script dev
.PHONY: build-js-production
build-js-production:
docker exec -it $(WORKSPACE_CONTAINER_NAME) npm run production --silent
.PHONY: npm-install
npm-install:
docker exec -it $(WORKSPACE_CONTAINER_NAME) npm install
.PHONY: watch-js
watch-js:
docker exec -it $(WORKSPACE_CONTAINER_NAME) npm run-script watch-poll
#------------------
# queue related targets
.PHONY: queue-flush
queue-flush:
docker exec -it $(REDIS_CONTAINER_NAME) redis-cli flushall
.PHONY: horizon
horizon:
docker exec -it $(REDIS_CONTAINER_NAME) redis-cli flushall
docker exec -it $(WORKSPACE_CONTAINER_NAME) bash -c 'php artisan horizon'
#------------------
# some artisan helpers
.PHONY: key-genrate
key-generate:
docker exec -it $(PHP_CONTAINER_NAME) bash -c 'php artisan key:generate'
.PHONY: new-migration
new-migration:
@read -p "Migration name: " migrationname; \
docker exec -it $(PHP_CONTAINER_NAME) bash -c "php artisan make:migration $$migrationname";
.PHONY: run-migrations
run-migrations:
docker exec -it $(PHP_CONTAINER_NAME) bash -c "php artisan migrate"
.PHONY: run-seeds
run-seeds:
docker exec -it $(PHP_CONTAINER_NAME) bash -c 'php artisan db:seed'
.PHONY: new
new:
@read -p "Make command and name (e.g. event TestEvent): " commandname;\
docker exec -it $(PHP_CONTAINER_NAME) bash -c "php artisan make:$$commandname";
#------------------
# run tests with phpunit
.PHONY: test
test:
docker exec -it $(PHP_CONTAINER_NAME) ./vendor/bin/phpunit
# install composer dependencies
.PHONY: composer-install
composer-install:
docker exec -it $(WORKSPACE_CONTAINER_NAME) composer install
# run ngrok to expose nginx webserver on port 80
.PHONY: up-ngrok
up-ngrok:
docker exec -it $(WORKSPACE_CONTAINER_NAME) ngrok http http://nginx:80