forked from loft-sh/devspace-php-laravel-nginx
-
Notifications
You must be signed in to change notification settings - Fork 0
/
devspace.yaml
executable file
·261 lines (255 loc) · 7.5 KB
/
devspace.yaml
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
version: v1beta10
# https://devspace.sh/cli/docs/configuration/variables/basics
vars:
- name: APP_IMAGE
question: Which image repository should your image be pushed to? (e.g. dockerhubuser/image, gcr.io/project/image)
- name: DB_PASSWORD
password: true
- name: DB_ROOT_PASSWORD
password: true
- name: REDIS_PASSWORD
password: true
- name: APP_DEBUG
question: Enable debugging? (true/false)
default: true
source: env
- name: NGINX_CONFIG_HASH
source: command
command: kubectl
args: ["get", "configmap", "nginx-config", "--ignore-not-found", "-o", "jsonpath={.metadata.resourceVersion}"]
# https://devspace.sh/cli/docs/configuration/images/basics
images:
app:
image: ${APP_IMAGE}
dockerfile: ./Dockerfile
# https://devspace.sh/cli/docs/configuration/deployments/basics
deployments:
- name: mysql
helm:
componentChart: false
chart:
name: mysql
version: 8.4.4
repo: https://charts.bitnami.com/bitnami
values:
image:
tag: $!{DB_MYSQL_VERSION}
auth:
rootPassword: $!{DB_ROOT_PASSWORD}
database: $!{DB_DATABASE}
username: $!{DB_USERNAME}
password: $!{DB_PASSWORD}
primary:
service:
port: ${DB_PORT}
- name: nginx-config
kubectl:
manifests:
- deploy/nginx-config-configmap.yaml
- name: app
helm:
componentChart: true
values:
replicas: 1
annotations:
nginx-config-hash: $!{NGINX_CONFIG_HASH}
containers:
- name: nginx
image: nginx:${NGINX_IMAGE_VERSION}
volumeMounts:
- containerPath: /etc/nginx/conf.d
volume:
name: nginx-config
readOnly: true
- containerPath: /assets
volume:
name: ${ASSET_VOLUME_NAME}
readOnly: true
- name: php
image: ${APP_IMAGE}
command:
- "/bin/sh"
args:
- "-c"
- |
cp -r /var/www/html/public/* /assets/;
php-fpm
env:
- name: APP_DEBUG
value: $!{APP_DEBUG}
- name: APP_KEY
value: $!{APP_KEY}
- name: DB_HOST
value: $!{DB_HOST}
- name: DB_PORT
value: $!{DB_PORT}
- name: DB_USERNAME
value: $!{DB_USERNAME}
- name: DB_PASSWORD
value: $!{DB_PASSWORD}
- name: REDIS_PASSWORD
value: $!{REDIS_PASSWORD}
volumeMounts:
- containerPath: /assets
volume:
name: ${ASSET_VOLUME_NAME}
readOnly: false
initContainers:
- name: php-init
image: ${APP_IMAGE}
command:
- "/bin/sh"
args:
- "-c"
- |
while ! mysql -h"$DB_HOST" -P"$DB_PORT" -u"$DB_USERNAME" -p"$DB_PASSWORD" -e ';' >/dev/null 2>&1 ; do
echo "Waiting for database to start..."
sleep 3
done
php artisan config:clear
php artisan cache:clear
php artisan migrate --force --no-interaction
env:
- name: APP_KEY
value: $!{APP_KEY}
- name: DB_HOST
value: $!{DB_HOST}
- name: DB_PORT
value: $!{DB_PORT}
- name: DB_USERNAME
value: $!{DB_USERNAME}
- name: DB_PASSWORD
value: $!{DB_PASSWORD}
- name: REDIS_PASSWORD
value: $!{REDIS_PASSWORD}
service:
ports:
- port: 80
volumes:
- name: nginx-config
configMap:
name: nginx-config
- name: ${ASSET_VOLUME_NAME}
size: ${ASSET_VOLUME_SIZE}
recreate: true
- name: redis
helm:
componentChart: false
chart:
name: redis
version: 12.8.3
repo: https://charts.bitnami.com/bitnami
values:
image:
tag: ${REDIS_VERSION}
networkPolicy:
enabled: true
allowExternal: true
password: $!{REDIS_PASSWORD}
cluster:
enabled: false
# https://devspace.sh/cli/docs/configuration/development/basics
dev:
ports:
- imageSelector: ${APP_IMAGE}
forward:
- port: 8080
remotePort: 80
open:
- url: http://localhost:8080
sync:
- imageSelector: ${APP_IMAGE}
excludePaths:
- .git/
- .git/
- .devspace/
- storage/logs/
- README.md
uploadExcludePaths:
- Dockerfile
- devspace.yaml
- storage/
- deploy/
- vendor/
- node_modules/
onUpload:
execRemote:
onBatch:
command: sh
args: ["-c", "cp -r /var/www/html/public/* /assets/"]
logs:
selectors:
- containerName: nginx
labelSelector:
app.kubernetes.io/component: app
autoReload:
paths:
- Dockerfile
- deploy/nginx-config-configmap.yaml
# https://devspace.sh/cli/docs/configuration/profiles/basics
profiles:
- name: production
patches:
- op: remove
path: hooks
# https://devspace.sh/cli/docs/configuration/commands/basics
commands:
- name: artisan
description: Entry point for artisan commands.
command: devspace enter -c php -- php artisan
- name: composer
description: Entry point for composer commands.
command: devspace enter -c php -- composer
- name: php
description: Entry point for PHP commands.
command: devspace enter -c php -- php
- name: npm
description: Entry point for NPM commands.
command: devspace enter -c php -- npm
- name: generate-key
description: Generate APP_KEY.
command: TMP_FILE=.devspace/app_key.tmp && docker run --rm -v $PWD:/app composer/composer bash -c "composer install --no-dev --no-interaction && php artisan key:generate --show >$TMP_FILE" && devspace set var APP_KEY="$(cat $TMP_FILE)" && rm $TMP_FILE
- name: mysql
description: Enter to MySQL shell.
command: devspace enter -c mysql -- mysql -h'${DB_HOST}' -P'${DB_PORT}' -u'${DB_USERNAME}' -p'${DB_PASSWORD}' '${DB_DATABASE}'
# https://devspace.sh/cli/docs/configuration/hooks/basics
hooks:
- command: sh
args:
- -c
- |
while ! mysql -u root -p"${DB_ROOT_PASSWORD}" -e ";" >/dev/null 2>&1 ; do
echo "Waiting for database to be ready...";
sleep 3;
done
echo "CREATE USER IF NOT EXISTS '${DB_USERNAME}'@'%' IDENTIFIED BY '${DB_PASSWORD}'; ALTER USER '${DB_USERNAME}' IDENTIFIED BY '${DB_PASSWORD}';" | mysql -u root -p'${DB_ROOT_PASSWORD}'
where:
container:
labelSelector:
app.kubernetes.io/name: mysql
app.kubernetes.io/component: primary
when:
after:
deployments: mysql
- command: "npm"
args: ["run", "watch"]
background: true
silent: true
where:
container:
labelSelector:
app.kubernetes.io/component: "app"
containerName: php
when:
after:
deployments: all
- command: "sh"
args: ["-c", "nginx -t && nginx -s reload"]
where:
container:
labelSelector:
app.kubernetes.io/component: "app"
containerName: nginx
when:
after:
deployments: all