-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
185 lines (137 loc) · 6.02 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
.DEFAULT_GOAL := d-shell
## █░█ ▄▀█ █▀█ █ ▄▀█ █▄▄ █░░ █▀▀ █▀
## ▀▄▀ █▀█ █▀▄ █ █▀█ █▄█ █▄▄ ██▄ ▄█
## populate as needed for testing
## ... never commit!
COMPOSER_USER := ***
COMPOSER_PASS := ***
## ... commit these :o)
kube := kind
k8s_prt := 8080:80
k8s_nsp := default
k8s_pod := kubectl -n $(k8s_nsp) get pod -l app=justice-gov-uk-local -o jsonpath="{.items[0].metadata.name}"
# ░░ ░░ ░░ ░░ ░░ ░░ ░░ ░░ ░░ ░░ ░░ ░░
init: setup key-gen run
d-compose: local-stop
docker compose up -d nginx phpmyadmin php-fpm
d-shell: setup key-gen dory d-compose composer
setup:
@chmod +x ./bin/*
@[ -f "./.env" ] || cp .env.example .env
restart:
@docker compose down php-fpm
@make d-compose
node-assets:
npm install
npm run watch
jekyll-serve:
cd /home/pages && bundle install
cd /home/pages && bundle exec jekyll serve --host 0.0.0.0 --livereload --livereload-port 35729
composer-assets:
@chmod +x ./bin/composer-post-install.sh
@chmod +x ./bin/local-composer-assets.sh
@docker compose exec php-fpm ./bin/local-composer-assets.sh ash
composer-copy:
@chmod +x ./bin/local-composer-assets-copy.sh
@./bin/local-composer-assets-copy.sh
composer: composer-assets
# Open a bash shell on the running php container
bash:
docker compose exec php-fpm bash
nginx:
docker compose exec --workdir /var/www/html nginx ash
node:
docker compose exec --workdir /node node bash
# Remove ignored git files – e.g. composer dependencies and built theme assets
# But keep .env file, .idea directory (PhpStorm config), and uploaded media files
clean:
@if [ -d ".git" ]; then git clean -xdf --exclude ".env" --exclude ".idea" --exclude "public/app/uploads"; fi
@clear
# Remove all ignored git files (including media files)
deep-clean:
@if [ -d ".git" ]; then git clean -xdf --exclude ".idea"; fi
# Remove ALL docker images on the system
docker-clean:
bin/local-docker-clean.sh
# Run the application
run: local-stop dory
docker compose up
down:
docker compose down
# Launch the application, open browser, no stdout
launch: local-stop dory
bin/local-launch.sh
# Start the Dory Proxy
dory:
@chmod +x ./bin/local-dory-check.sh && ./bin/local-dory-check.sh
# Starts the application, includes the local-ssh container for migrations.
migrate:
docker compose --profile local-ssh up
# Run tests
test:
composer test && composer test:unit
# Fix tests
test-fixes:
composer test:fix
# JWT secret generation
key-gen:
@chmod +x ./bin/local-key-gen.sh && ./bin/local-key-gen.sh
#####
## Mock production, K8S deployment
#####
build-nginx:
@echo "\n--> Building local Nginx <---------------------------|\n"; sleep 3;
docker image build -t justice-nginx:latest --target build-nginx \
--build-arg COMPOSER_USER="${COMPOSER_USER}" --build-arg COMPOSER_PASS="${COMPOSER_PASS}" .
# FastCGI Process Manager for PHP
# https://www.php.net/manual/en/install.fpm.php
# https://www.plesk.com/blog/various/php-fpm-the-future-of-php-handling/
build-fpm:
@echo "\n--> Building local FPM <---------------------------|\n"; sleep 3;
docker image build -t justice-fpm:latest --target build-fpm \
--build-arg COMPOSER_USER="${COMPOSER_USER}" --build-arg COMPOSER_PASS="${COMPOSER_PASS}" .
build: build-fpm build-nginx
@if [ ${kube} == 'kind' ]; then kind load docker-image justice-fpm:latest; kind load docker-image justice-nginx:latest; fi
@echo "\n--> Done.\n"
deploy: clear
@echo "\n--> Local Kubernetes deployment <---------------------------|\n"
kubectl apply -f deploy/local
cluster:
@if [ "${kube}" != 'kind' ]; then echo "\n--> Please, activate the kind cluster to assist in local app development on Kubernetes"; echo "--> Amend the variable named kube on line 3 in Makefile to read 'kind' (without quotes)"; echo "--> ... or, install kind from scratch: https://kind.sigs.k8s.io/docs/user/quick-start/#installation \n"; sleep 8; fi
@if [ "${kube}" == 'kind' ]; then kind create cluster --config=deploy/config/local/cluster.yml; kubectl apply -f https://projectcontour.io/quickstart/contour.yaml; fi
@if [ "${kube}" == 'kind' ]; then kubectl patch daemonsets -n projectcontour envoy -p '{"spec":{"template":{"spec":{"nodeSelector":{"ingress-ready":"true"},"tolerations":[{"key":"node-role.kubernetes.io/control-plane","operator":"Equal","effect":"NoSchedule"},{"key":"node-role.kubernetes.io/master","operator":"Equal","effect":"NoSchedule"}]}}}}'; fi
kind: local-kube-start clear cluster local-kube-build
@if [ "${kube}" == 'kind' ]; then echo "\n--> Verifying..."; echo "--> Use ctrl + C to exit when ready\n"; kubectl get pods -w; fi
local-kube-start:
@if [ -n "$(docker ps | grep dory_dnsmasq)" ]; then dory down; fi # lets make sure port 80 is free
@docker container start kind-control-plane
local-stop:
@echo "\n--> Checking if we should stop the kind-control-plane container..."
@docker container stop kind-control-plane || true >/dev/null 2>&1
@echo "--> Done.\n"
local-kube-build: build deploy
@if [ "${kube}" == 'kind' ]; then echo "\n--> Verifying..."; echo "--> Use ctrl + C to exit when ready\n"; kubectl get pods -w; fi
clear:
@clear
log-nginx: clear
@echo "\n--> NGINX LOGS <---------------------------|\n"
@$(k8s_pod) | xargs -t kubectl logs -f -n $(k8s_nsp) -c nginx
log-fpm: clear
@echo "\n--> FPM PHP LOGS <-------------------------|\n"
@$(k8s_pod) | xargs kubectl logs -f -n $(k8s_nsp) -c fpm
logs-nginx-flash:
@echo "\n--> NGINX LOGS <---------------------------|\n"
@$(k8s_pod) | xargs kubectl logs -n $(k8s_nsp) -c nginx
logs-fpm-flash:
@echo "\n--> FPM PHP LOGS <-------------------------|\n"
@$(k8s_pod) | xargs kubectl logs -n $(k8s_nsp) -c fpm
logs: clear logs-fpm-flash logs-nginx-flash
@echo "\n---------------------------------------------\n"
port-forward:
@$(k8s_pod) | echo $$(cat -)" "$(k8s_prt) | xargs kubectl -n $(k8s_nsp) port-forward
apply:
kubectl apply -f deploy/local
unapply:
@$(k8s_pod) | xargs kubectl -n $(k8s_nsp) delete pod
apply-production:
kubectl apply -f deploy/production