From f1cba60825fa3c29aa08f1b544908e6204c2a63f Mon Sep 17 00:00:00 2001 From: Lukas Date: Fri, 25 Feb 2022 20:32:10 +0100 Subject: [PATCH] base front production image on official nginx image --- docker-compose.e2e.yml | 11 +--------- front/Dockerfile | 19 ++++++----------- front/nginx.conf | 48 ++++++++++++++++++++++++++++++++++++++++++ front/templater.sh | 8 +++---- 4 files changed, 59 insertions(+), 27 deletions(-) create mode 100644 front/nginx.conf diff --git a/docker-compose.e2e.yml b/docker-compose.e2e.yml index 3330202a..52e312b5 100644 --- a/docker-compose.e2e.yml +++ b/docker-compose.e2e.yml @@ -9,10 +9,7 @@ services: build: context: ./ dockerfile: front/Dockerfile - environment: - STARTUP_COMMAND_1: 'envsubst < dist/env-config.template.js > dist/env-config.js' - STARTUP_COMMAND_2: '' - command: apache2-foreground + command: /bin/sh -c "/templater.sh && envsubst < /usr/share/nginx/html/env-config.template.js > /usr/share/nginx/html/env-config.js && exec nginx -g 'daemon off;'" volumes: [] labels: - "traefik.enable=true" @@ -29,9 +26,6 @@ services: build: context: ./ dockerfile: pusher/Dockerfile - environment: - STARTUP_COMMAND_1: '' - STARTUP_COMMAND_2: '' command: yarn run runprod volumes: [] @@ -40,8 +34,5 @@ services: build: context: ./ dockerfile: back/Dockerfile - environment: - STARTUP_COMMAND_1: '' - STARTUP_COMMAND_2: '' command: yarn run runprod volumes: [] diff --git a/front/Dockerfile b/front/Dockerfile index fb91edbd..bc437e64 100644 --- a/front/Dockerfile +++ b/front/Dockerfile @@ -18,18 +18,11 @@ COPY --from=builder /usr/src/JsonMessages src/Messages/JsonMessages RUN yarn run typesafe-i18n && yarn run build-iframe-api && yarn build # final production image -FROM thecodingmachine/nodejs:14-apache +FROM nginx:1.21.6-alpine -USER root -RUN DEBIAN_FRONTEND=noninteractive apt-get update \ - && apt-get install -y \ - gettext-base \ - && rm -rf /var/lib/apt/lists/* -USER docker +COPY front/nginx.conf /etc/nginx/conf.d/default.conf +COPY front/templater.sh / +COPY --from=builder2 /usr/src/dist /usr/share/nginx/html -COPY --from=builder2 --chown=docker:docker /usr/src/dist dist -COPY front/templater.sh . - -ENV STARTUP_COMMAND_0="./templater.sh" -ENV STARTUP_COMMAND_1="envsubst < dist/env-config.template.js > dist/env-config.js" -ENV APACHE_DOCUMENT_ROOT=dist/ +EXPOSE 80 +CMD ["/bin/sh", "-c", "/templater.sh && envsubst < /usr/share/nginx/html/env-config.template.js > /usr/share/nginx/html/env-config.js && exec nginx -g 'daemon off;'"] diff --git a/front/nginx.conf b/front/nginx.conf new file mode 100644 index 00000000..34fbd01a --- /dev/null +++ b/front/nginx.conf @@ -0,0 +1,48 @@ +server { + listen 80; + listen [::]:80; + server_name localhost; + access_log off; + + gzip on; + gzip_comp_level 6; + gzip_min_length 1000; + gzip_proxied any; + gzip_disable "msie6"; + gzip_types + application/atom+xml + application/geo+json + application/javascript + application/x-javascript + application/json + application/ld+json + application/manifest+json + application/rdf+xml + application/rss+xml + application/xhtml+xml + application/xml + font/eot + font/otf + font/ttf + image/svg+xml + text/css + text/javascript + text/plain + text/xml; + + # serve static assets (that have a cache busting hash) with an efficient cache policy + location /assets { + root /usr/share/nginx/html; + expires 1y; + add_header Cache-Control "public"; + } + + location / { + root /usr/share/nginx/html; + index index.html; + } + + location ~ ^/[@_]/ { + try_files $uri $uri/ /index.html; + } +} diff --git a/front/templater.sh b/front/templater.sh index e6a78e08..d601ea66 100755 --- a/front/templater.sh +++ b/front/templater.sh @@ -1,7 +1,7 @@ -#!/usr/bin/env bash +#!/usr/bin/env sh set -x set -o nounset errexit -index_file=dist/index.html +index_file=/usr/share/nginx/html/index.html tmp_trackcodefile=/tmp/trackcode # To inject tracking code, you have two choices: @@ -10,12 +10,12 @@ tmp_trackcodefile=/tmp/trackcode # The ANALYTICS_CODE_PATH is the location of a file inside the container ANALYTICS_CODE_PATH="${ANALYTICS_CODE_PATH:-dist/ga.html.tmpl}" -if [[ "${INSERT_ANALYTICS:-NO}" == "NO" ]]; then +if [ "${INSERT_ANALYTICS:-NO}" = "NO" ]; then echo "" > "${tmp_trackcodefile}" fi # Automatically insert analytics if GA_TRACKING_ID is set -if [[ "${GA_TRACKING_ID:-}" != "" || "${INSERT_ANALYTICS:-NO}" != "NO" ]]; then +if [ "${GA_TRACKING_ID:-}" != "" ] || [ "${INSERT_ANALYTICS:-NO}" != "NO" ]; then echo "Templating code from ${ANALYTICS_CODE_PATH}" sed "s##${GA_TRACKING_ID:-}#g" "${ANALYTICS_CODE_PATH}" > "$tmp_trackcodefile" fi