Skip to content

Commit

Permalink
Configure resolver, move scripts from Dockerfile to standalone files
Browse files Browse the repository at this point in the history
  • Loading branch information
Dove6 committed Nov 14, 2021
1 parent 5c237ef commit 6b4d13e
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
8 changes: 3 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
FROM nginx

ENV REST_API_READ_HOSTNAME=localhost
ENV REST_API_READ_HOSTNAME=host.docker.internal
ENV REST_API_READ_PORT=8081
ENV REST_API_WRITE_HOSTNAME=localhost
ENV REST_API_WRITE_HOSTNAME=host.docker.internal
ENV REST_API_WRITE_PORT=8082

COPY upstream.location.template /etc/nginx/
COPY --chmod=0777 entrypoint/*.sh /docker-entrypoint.d/

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;"]
2 changes: 2 additions & 0 deletions entrypoint/40-envsubst-upstream-location.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
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
1 change: 1 addition & 0 deletions entrypoint/41-resolver-configuration.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
echo resolver $(awk 'BEGIN{ORS=" "} $1=="nameserver" {print $2}' /etc/resolv.conf) ";" > /etc/nginx/conf.d/resolver.conf

0 comments on commit 6b4d13e

Please sign in to comment.