refactor(docker): use templating to handle env variables (#8878)

Refs #8877
This commit is contained in:
Vladimír Gorej
2023-06-02 16:05:08 +02:00
committed by GitHub
parent b017858fe1
commit 1f7bb89217
4 changed files with 34 additions and 44 deletions

View File

@@ -1,20 +1,7 @@
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
types {
text/plain yaml;
text/plain yml;
}
sendfile on;
keepalive_timeout 65;
}
gzip on;
gzip_static on;
@@ -29,28 +16,27 @@ http {
server_tokens off; # Hide Nginx version
server {
listen 8080;
listen $PORT;
server_name localhost;
index index.html index.htm;
location / {
location $BASE_URL {
absolute_redirect off;
alias /usr/share/nginx/html/;
expires 1d;
location ~ swagger-initializer.js {
expires -1;
include cors.conf;
include templates/cors.conf;
}
location ~* \.(?:json|yml|yaml)$ {
#SWAGGER_ROOT
expires -1;
include cors.conf;
include templates/cors.conf;
}
include cors.conf;
include templates/cors.conf;
}
}
}

View File

@@ -1,18 +1,13 @@
#! /bin/sh
set -e
BASE_URL=${BASE_URL:-/}
NGINX_ROOT=/usr/share/nginx/html
INITIALIZER_SCRIPT=$NGINX_ROOT/swagger-initializer.js
NGINX_CONF=/etc/nginx/nginx.conf
NGINX_CONF=/etc/nginx/conf.d/default.conf
node /usr/share/nginx/configurator $INITIALIZER_SCRIPT
if [[ "${BASE_URL}" != "/" ]]; then
sed -i "s|location / {|location $BASE_URL {|g" $NGINX_CONF
fi
if [ "$SWAGGER_JSON_URL" ]; then
sed -i "s|https://petstore.swagger.io/v2/swagger.json|$SWAGGER_JSON_URL|g" $INITIALIZER_SCRIPT
sed -i "s|http://example.com/api|$SWAGGER_JSON_URL|g" $INITIALIZER_SCRIPT
@@ -41,12 +36,7 @@ fi
# enable/disable the address and port for IPv6 addresses that nginx listens on
if [[ -n "${PORT_IPV6}" ]]; then
sed -i "s|8080;|8080;\n listen [::]:${PORT_IPV6};|g" $NGINX_CONF
fi
# replace the PORT that nginx listens on if PORT is supplied
if [[ -n "${PORT}" ]]; then
sed -i "s|8080|${PORT}|g" $NGINX_CONF
sed -i "s|${PORT};|${PORT};\n listen [::]:${PORT_IPV6};|g" $NGINX_CONF
fi
find $NGINX_ROOT -type f -regex ".*\.\(html\|js\|css\)" -exec sh -c "gzip < {} > {}.gz" \;