Reworked docker scripts for new nuxt infrastructure (#285)
* Reworked docker scripts for new nuxt infrastructure * Switched to log mailer for default docker config --------- Co-authored-by: Julien Nahum <julien@nahum.net>
This commit is contained in:
47
docker/generate-api-secret.sh
Normal file
47
docker/generate-api-secret.sh
Normal file
@@ -0,0 +1,47 @@
|
||||
#!/bin/bash
|
||||
|
||||
main() {
|
||||
( flock -n 100 || wait_for_other_instance; generate_api_secrets) 100> /var/lock/api_secret.lock
|
||||
}
|
||||
|
||||
generate_api_secrets() {
|
||||
if ! is_configured; then
|
||||
SECRET=$(random_string)
|
||||
add_secret_to_env_file /app/client/.env NUXT_API_SECRET $SECRET
|
||||
add_secret_to_env_file /app/.env FRONT_API_SECRET $SECRET
|
||||
fi
|
||||
}
|
||||
|
||||
random_string() {
|
||||
array=()
|
||||
for i in {a..z} {A..Z} {0..9};
|
||||
do
|
||||
array[$RANDOM]=$i
|
||||
done
|
||||
printf %s ${array[@]::8} $'\n'
|
||||
}
|
||||
|
||||
add_secret_to_env_file() {
|
||||
FILE=$1
|
||||
TEMP_FILE=/tmp/env.$$
|
||||
VAR=$2
|
||||
VAL=$3
|
||||
|
||||
grep "^$VAR=" $FILE || ( echo $VAR= >> $FILE )
|
||||
|
||||
cp $FILE $TEMP_FILE
|
||||
sed "s/^$VAR=.*$/$VAR=$VAL/" -i $TEMP_FILE
|
||||
cat $TEMP_FILE > $FILE
|
||||
}
|
||||
|
||||
wait_for_other_instance() {
|
||||
while ! is_configured; do
|
||||
sleep 1;
|
||||
done
|
||||
}
|
||||
|
||||
is_configured() {
|
||||
grep -q "FRONT_API_SECRET=.\+" /app/.env
|
||||
}
|
||||
|
||||
main
|
||||
@@ -1,3 +1,8 @@
|
||||
map $original_uri $api_uri {
|
||||
~^/api(/.*$) $1;
|
||||
default $original_uri;
|
||||
}
|
||||
|
||||
server {
|
||||
listen 80;
|
||||
server_name opnform;
|
||||
@@ -9,7 +14,15 @@ server {
|
||||
index index.html index.htm index.php;
|
||||
|
||||
location / {
|
||||
try_files $uri $uri/ /index.php$is_args$args;
|
||||
proxy_pass http://localhost:3000;
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
proxy_set_header X-Forwarded-Host $host;
|
||||
proxy_set_header X-Forwarded-Port $server_port;
|
||||
}
|
||||
|
||||
location /api/ {
|
||||
set $original_uri $uri;
|
||||
try_files $uri $uri/ /index.php$is_args$args;
|
||||
}
|
||||
|
||||
location ~ \.php$ {
|
||||
@@ -17,6 +30,7 @@ server {
|
||||
fastcgi_pass unix:/var/run/php-fpm-opnform-site.sock;
|
||||
fastcgi_index index.php;
|
||||
include fastcgi.conf;
|
||||
}
|
||||
fastcgi_param REQUEST_URI $api_uri;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
16
docker/nuxt-wrapper.sh
Normal file
16
docker/nuxt-wrapper.sh
Normal file
@@ -0,0 +1,16 @@
|
||||
#!/bin/bash
|
||||
|
||||
. /root/.nvm/nvm.sh
|
||||
nvm install 20
|
||||
nvm use 20
|
||||
|
||||
cd /app/nuxt/server/
|
||||
|
||||
. /app/client/.env
|
||||
[ "x$NUXT_API_SECRET" != "x" ] || generate-api-secret.sh
|
||||
|
||||
sed 's/^/export /' < /app/.nuxt.env > env.sh
|
||||
|
||||
. env.sh
|
||||
|
||||
node index.mjs
|
||||
@@ -30,6 +30,11 @@ ln -sf /persist/storage /app/storage
|
||||
. /app/.env
|
||||
}
|
||||
|
||||
[ "x$FRONT_API_SECRET" != "x" ] || {
|
||||
generate-api-secret.sh
|
||||
. /app/.env
|
||||
}
|
||||
|
||||
/usr/sbin/php-fpm8.1
|
||||
|
||||
tail -f /var/log/opnform.log
|
||||
|
||||
@@ -40,3 +40,10 @@ stderr_logfile=/dev/stderr
|
||||
stdout_logfile_maxbytes=0
|
||||
redirect_stderr=true
|
||||
|
||||
[program:nuxt-backend]
|
||||
command=/usr/local/bin/nuxt-wrapper.sh
|
||||
stdout_logfile=/dev/stdout
|
||||
stderr_logfile=/dev/stderr
|
||||
stdout_logfile_maxbytes=0
|
||||
redirect_stderr=true
|
||||
|
||||
|
||||
Reference in New Issue
Block a user