diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..d393d07 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +nppBackup diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..63c602d --- /dev/null +++ b/Dockerfile @@ -0,0 +1,16 @@ +FROM nginx + +ENV REST_API_READ_HOSTNAME=localhost +ENV REST_API_READ_PORT=8081 +ENV REST_API_WRITE_HOSTNAME=localhost +ENV REST_API_WRITE_PORT=8082 + +COPY upstream.location.template /etc/nginx/ + +RUN perl -0pe 's/root\s+\/usr\/share\/nginx\/html;\s+index\s+index\.html\s+index\.htm;/proxy_pass http:\/\/\$rest_api_host;/igs' /etc/nginx/conf.d/default.conf > /etc/nginx/conf.d/default.conf.part && \ + echo "include /etc/nginx/upstream.location;" | cat - /etc/nginx/conf.d/default.conf.part > /etc/nginx/conf.d/default.conf + +RUN echo "envsubst '\$REST_API_READ_HOSTNAME,\$REST_API_READ_PORT,\$REST_API_WRITE_HOSTNAME,\$REST_API_WRITE_PORT' < /etc/nginx/upstream.location.template > /etc/nginx/upstream.location && cat /etc/nginx/upstream.location" > /docker-entrypoint.d/40-envsubst-upstream-location.sh && \ + chmod a+x /docker-entrypoint.d/40-envsubst-upstream-location.sh + +CMD ["nginx", "-g", "daemon off;"] diff --git a/upstream.location.template b/upstream.location.template new file mode 100644 index 0000000..418ca7f --- /dev/null +++ b/upstream.location.template @@ -0,0 +1,4 @@ +map $request_method $rest_api_host { + GET $REST_API_READ_HOSTNAME:$REST_API_READ_PORT; + default $REST_API_WRITE_HOSTNAME:$REST_API_WRITE_PORT; +}