forked from Langres-App/opsign
-
Notifications
You must be signed in to change notification settings - Fork 1
/
env-create.sh
executable file
·265 lines (239 loc) · 7.1 KB
/
env-create.sh
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
#!/bin/bash
# Prompt for database details
read -p "Please enter your MySQL root password: " MYSQL_ROOT_PASSWORD
read -p "Please enter your MySQL username: " MYSQL_USER
read -p "Please enter your MySQL password: " MYSQL_PASSWORD
read -p "Please enter your database name: " MYSQL_DATABASE
while true; do
read -p "Please enter your app context (prod or dev): " APP_CONTEXT
if [ "${APP_CONTEXT}" == "prod" ] || [ "${APP_CONTEXT}" == "dev" ]; then
# If the context is valid, break the loop and continue with the rest of your script
break
else
echo "Invalid app context. Please enter either the word prod or dev."
fi
done
read -p "What Timezone to use? (default Europe/Paris) " TIMEZONE
if [ -z "${TIMEZONE}" ]
then
TIMEZONE="'Europe/Paris'"
fi
while true; do
read -p "Is there a proxy in your network ? (yes/no) " PROXY_ANSWER;
if [ "${PROXY_ANSWER}" == "yes" ] || [ "${PROXY_ANSWER}" == "no" ]; then
break;
else
echo "Please answer yes or no";
fi
done
if [ "${PROXY_ANSWER}" == "yes" ]
then
read -p "Please enter your proxy address(default will be 'http://10.0.0.1'): " PROXY_ADDRESS
if [ -z "${PROXY_ADDRESS}" ]
then
PROXY_ADDRESS="http://10.0.0.1"
fi
read -p "Please enter your proxy port(default will be '80'): " PROXY_PORT
if [ -z "${PROXY_PORT}" ]
then
PROXY_PORT="80"
fi
PROXY_ENV=" http_proxy: ${PROXY_ADDRESS}:${PROXY_PORT}"
# PROXY_DOCKERFILE="ENV http_proxy=\'${PROXY_ADDRESS}:${PROXY_PORT}\'"
# sed -i "3s|.*|$PROXY_DOCKERFILE|" docker/dockerfile/Dockerfile
fi
# Generate a new secret key
APP_SECRET=$(openssl rand -hex 16)
# Create docker-compose.override.yml file to use the good entrypoint
cat > docker-compose.override.yml <<EOL
version: '3.8'
services:
webapi:
image: ghcr.io/polangres/opsignapi:main
restart: unless-stopped
entrypoint: "./${APP_CONTEXT}-entrypoint.sh"
ports:
- "52200"
environment:
DB_HOST: database
DB_USER: ${MYSQL_USER}
DB_PASSWORD: ${MYSQL_PASSWORD}
DB_DATABASE: ${MYSQL_DATABASE}
PORT: 52200
${PROXY_ENV}
APP_TIMEZONE: ${TIMEZONE}
volumes:
- ./Docs:/var/www/Docs
labels:
- traefik.enable=true
- traefik.http.routers.webapi.rule=PathPrefix(\`/opsignapi\`)
- traefik.http.routers.webapi.middlewares=strip-webapi-prefix
- traefik.http.middlewares.strip-webapi-prefix.stripprefix.prefixes=/opsignapi
- traefik.http.routers.webapi.entrypoints=web
depends_on:
- database
networks:
vpcbr:
ipv4_address: 172.23.0.4
web:
image: ghcr.io/polangres/opsignfront:main
restart: unless-stopped
depends_on:
- webapi
environment:
HOSTNAME: ${HOSTNAME}
PORT: 80
${PROXY_ENV}
APP_TIMEZONE: ${TIMEZONE}
labels:
- traefik.enable=true
- traefik.http.routers.webopsign.rule=PathPrefix(\`/opsign\`)
- traefik.http.routers.webopsign.middlewares=strip-webopsign-prefix
- traefik.http.middlewares.strip-webopsign-prefix.stripprefix.prefixes=/opsign
- traefik.http.routers.webopsign.entrypoints=web
networks:
vpcbr:
ipv4_address: 172.23.0.5
networks:
vpcbr:
driver: bridge
ipam:
config:
- subnet: 172.23.0.0/16
gateway: 172.23.0.1
EOL
# Create .env file
cat > .env <<EOL
MYSQL_ROOT_PASSWORD=${MYSQL_ROOT_PASSWORD}
MYSQL_DATABASE=${MYSQL_DATABASE}
MYSQL_USER=${MYSQL_USER}
MYSQL_PASSWORD=${MYSQL_PASSWORD}
HOSTNAME=${HOSTNAME}
###> symfony/framework-bundle ###
APP_ENV=${APP_CONTEXT}
EOL
echo ".env file created successfully!"
if [ "${APP_CONTEXT}" == "prod" ]
then
sed -i "s|^APP_ENV=dev.*|APP_ENV=prod|" .env
APP_CONTEXT="prod"
# Create docker-compose.override.yml file to use the good entrypoint
cat > docker-compose.override.yml <<EOL
version: '3.8'
services:
webapi:
image: ghcr.io/polangres/opsignapi:main
restart: unless-stopped
entrypoint: "./${APP_CONTEXT}-entrypoint.sh"
ports:
- "52200"
environment:
DB_HOST: database
DB_USER: ${MYSQL_USER}
DB_PASSWORD: ${MYSQL_PASSWORD}
DB_DATABASE: ${MYSQL_DATABASE}
PORT: 52200
${PROXY_ENV}
APP_TIMEZONE: ${TIMEZONE}
volumes:
- ./Docs:/var/www/Docs
labels:
- traefik.enable=true
- traefik.http.routers.webopsignapi.rule=PathPrefix(\`/opsignapi\`)
- traefik.http.routers.webopsignapi.middlewares=strip-webopsignapi-prefix
- traefik.http.middlewares.strip-webopsignapi-prefix.stripprefix.prefixes=/opsignapi
- traefik.http.routers.webopsignapi.entrypoints=web
depends_on:
- database
networks:
vpcbr:
ipv4_address: 172.23.0.4
web:
image: ghcr.io/polangres/opsignfront:main
restart: unless-stopped
depends_on:
- webapi
environment:
HOSTNAME: ${HOSTNAME}
PORT: 80
${PROXY_ENV}
APP_TIMEZONE: ${TIMEZONE}
labels:
- traefik.enable=true
- traefik.http.routers.webopsign.rule=PathPrefix(\`/opsign\`)
- traefik.http.routers.webopsign.middlewares=strip-webopsign-prefix
- traefik.http.middlewares.strip-webopsign-prefix.stripprefix.prefixes=/opsign
- traefik.http.routers.webopsign.entrypoints=web
networks:
vpcbr:
ipv4_address: 172.23.0.5
networks:
vpcbr:
driver: bridge
ipam:
config:
- subnet: 172.23.0.0/16
gateway: 172.23.0.1
EOL
else
APP_CONTEXT="dev"
sed -i "s|^APP_ENV=prod.*|APP_ENV=dev|" .env
# Create docker-compose.override.yml file to use the good entrypoint
cat > docker-compose.override.yml <<EOL
version: '3.8'
services:
webapi:
image: ghcr.io/polangres/opsignapi:main
restart: unless-stopped
entrypoint: "./${APP_CONTEXT}-entrypoint.sh"
ports:
- "52200"
environment:
DB_HOST: database
DB_USER: ${MYSQL_USER}
DB_PASSWORD: ${MYSQL_PASSWORD}
DB_DATABASE: ${MYSQL_DATABASE}
PORT: 52200
${PROXY_ENV}
APP_TIMEZONE: ${TIMEZONE}
volumes:
- ./Docs:/var/www/Docs
labels:
- traefik.enable=true
- traefik.http.routers.webopsignapi.rule=PathPrefix(\`/opsignapi\`)
- traefik.http.routers.webopsignapi.middlewares=strip-webopsignapi-prefix
- traefik.http.middlewares.strip-webopsignapi-prefix.stripprefix.prefixes=/opsignapi
- traefik.http.routers.webopsignapi.entrypoints=web
depends_on:
- database
networks:
vpcbr:
ipv4_address: 172.23.0.4
web:
image: ghcr.io/polangres/opsignfront:main
restart: unless-stopped
depends_on:
- webapi
environment:
HOSTNAME: ${HOSTNAME}
PORT: 80
${PROXY_ENV}
APP_TIMEZONE: ${TIMEZONE}
labels:
- traefik.enable=true
- traefik.http.routers.webopsign.rule=PathPrefix(\`/opsign\`)
- traefik.http.routers.webopsign.middlewares=strip-webopsign-prefix
- traefik.http.middlewares.strip-webopsign-prefix.stripprefix.prefixes=/opsign
- traefik.http.routers.webopsign.entrypoints=web
networks:
vpcbr:
ipv4_address: 172.23.0.5
networks:
vpcbr:
driver: bridge
ipam:
config:
- subnet: 172.23.0.0/16
gateway: 172.23.0.1
EOL
fi