From ba3e895ebc6a43199f96f1f90be83a1a6186aa92 Mon Sep 17 00:00:00 2001 From: Mike Kalinin <45598572+sprymiker@users.noreply.github.com> Date: Mon, 26 Jul 2021 21:12:27 +0300 Subject: [PATCH] SC-4608: Adding the possibility to set DNS resolver IP via environment variables (#134) * SC-4608: Adding the possibility to set DNS resolver IP via environment variables * Remove predefined resolver IP value * Update entrypoint.sh.twig * Update Dockerfile * SC-4608: Forced DNS resolver set Co-authored-by: Bogdan Co-authored-by: v.strelchenko Co-authored-by: Aleksandr Myrnyi --- context/nginx/conf.d/resolver.conf.tmpl | 1 + generator/src/templates/nginx/entrypoint.sh.twig | 2 +- .../src/templates/nginx/http/application.server.conf.twig | 8 ++++++-- generator/src/templates/nginx/http/build.conf.twig | 4 +++- images/common/frontend/Dockerfile | 4 ++++ 5 files changed, 15 insertions(+), 4 deletions(-) create mode 100644 context/nginx/conf.d/resolver.conf.tmpl diff --git a/context/nginx/conf.d/resolver.conf.tmpl b/context/nginx/conf.d/resolver.conf.tmpl new file mode 100644 index 000000000..607b2ff82 --- /dev/null +++ b/context/nginx/conf.d/resolver.conf.tmpl @@ -0,0 +1 @@ +resolver ${SPRYKER_DNS_RESOLVER_IP} ${SPRYKER_DNS_RESOLVER_FLAGS}; diff --git a/generator/src/templates/nginx/entrypoint.sh.twig b/generator/src/templates/nginx/entrypoint.sh.twig index 37d4fa784..508d7111d 100644 --- a/generator/src/templates/nginx/entrypoint.sh.twig +++ b/generator/src/templates/nginx/entrypoint.sh.twig @@ -11,6 +11,6 @@ export SPRYKER_NGINX_CGI_{{ applicationName | upper}}=${SPRYKER_NGINX_CGI_{{ (ap envsubst '{{ envVariables | join(' ') }}' < /etc/nginx/template/default.conf.tmpl > /etc/nginx/conf.d/default.conf -cat /etc/nginx/conf.d/default.conf +envsubst '$SPRYKER_DNS_RESOLVER_IP ${SPRYKER_DNS_RESOLVER_FLAGS} {{ envVariables | join(' ') }}' < /etc/nginx/template/resolver.conf.tmpl > /etc/nginx/conf.d/00-resolver.conf exec "$@" diff --git a/generator/src/templates/nginx/http/application.server.conf.twig b/generator/src/templates/nginx/http/application.server.conf.twig index cddc8ed71..ee4be8205 100644 --- a/generator/src/templates/nginx/http/application.server.conf.twig +++ b/generator/src/templates/nginx/http/application.server.conf.twig @@ -17,7 +17,9 @@ location ~ \.php$ { include fastcgi.conf; - fastcgi_pass {{ upstream }}; +{# Variable is necessary for https://www.nginx.com/blog/dns-service-discovery-nginx-plus/#domain-name-upstream-group #} + set $upstream "{{ upstream }}"; + fastcgi_pass "$upstream"; fastcgi_intercept_errors off; try_files $fastcgi_script_name @proxy; } @@ -25,7 +27,9 @@ location @proxy { {% block location %} include fastcgi.conf; - fastcgi_pass "{{ upstream }}"; +{# Variable is necessary for https://www.nginx.com/blog/dns-service-discovery-nginx-plus/#domain-name-upstream-group #} + set $upstream "{{ upstream }}"; + fastcgi_pass "$upstream"; {% include "nginx/http/default.location.conf.twig" with _context %} diff --git a/generator/src/templates/nginx/http/build.conf.twig b/generator/src/templates/nginx/http/build.conf.twig index 305e88ef7..edbd91ea6 100644 --- a/generator/src/templates/nginx/http/build.conf.twig +++ b/generator/src/templates/nginx/http/build.conf.twig @@ -6,6 +6,8 @@ location =/build.php { root /home/spryker; include fastcgi.conf; - fastcgi_pass {{ upstream }}; +{# Variable is necessary for https://www.nginx.com/blog/dns-service-discovery-nginx-plus/#domain-name-upstream-group #} + set $upstream "{{ upstream }}"; + fastcgi_pass "$upstream"; fastcgi_intercept_errors off; } diff --git a/images/common/frontend/Dockerfile b/images/common/frontend/Dockerfile index eedbf7d84..be13bf861 100644 --- a/images/common/frontend/Dockerfile +++ b/images/common/frontend/Dockerfile @@ -7,10 +7,14 @@ FROM ${SPRYKER_FRONTEND_IMAGE} as frontend-basic RUN mkdir -p /etc/nginx/template/ && chmod 0777 /etc/nginx/template/ COPY --chown=root:root nginx/nginx.original.conf /etc/nginx/nginx.conf COPY --chown=root:root nginx/conf.d/frontend.default.conf.tmpl /etc/nginx/template/default.conf.tmpl +COPY --chown=root:root nginx/conf.d/resolver.conf.tmpl /etc/nginx/template/resolver.conf.tmpl COPY --chown=root:root nginx/auth /etc/nginx/auth COPY --chown=root:root nginx/entrypoint.sh / RUN chmod +x /entrypoint.sh +ENV SPRYKER_DNS_RESOLVER_FLAGS="valid=10s ipv6=off" +ENV SPRYKER_DNS_RESOLVER_IP="127.0.0.11" + # Build info ARG SPRYKER_BUILD_HASH='current' ENV SPRYKER_BUILD_HASH=${SPRYKER_BUILD_HASH}