From 522231c6c6ef6fce5c145e94ef2bc3ca9f30e166 Mon Sep 17 00:00:00 2001 From: Frederik Ring Date: Fri, 4 Oct 2019 18:51:24 +0200 Subject: [PATCH 1/6] use go app to serve static assets --- .gitignore | 2 +- build/proxy/Dockerfile | 45 ------------------------------------------ build/proxy/nginx.conf | 16 +++++++++++---- docker-compose.yml | 1 + 4 files changed, 14 insertions(+), 50 deletions(-) diff --git a/.gitignore b/.gitignore index bcc7233..75e3c50 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,7 @@ .vscode .serverless node_modules/ -# mkcert certificates +public/ *.pem venv/ diff --git a/build/proxy/Dockerfile b/build/proxy/Dockerfile index ee23061..4cb199c 100644 --- a/build/proxy/Dockerfile +++ b/build/proxy/Dockerfile @@ -1,45 +1,3 @@ -FROM node:10 as auditorium - -COPY ./auditorium/package.json ./auditorium/package-lock.json /code/deps/ -COPY ./packages /code/packages -WORKDIR /code/deps -ENV PUPPETEER_SKIP_CHROMIUM_DOWNLOAD true -RUN npm ci -COPY ./auditorium /code/auditorium -COPY ./banner.txt /code/banner.txt -WORKDIR /code/auditorium -RUN cp -a /code/deps/node_modules /code/auditorium/ -ENV NODE_ENV production -RUN npm run build - -FROM node:10 as script - -COPY ./script/package.json ./script/package-lock.json /code/deps/ -COPY ./packages /code/packages -WORKDIR /code/deps -ENV PUPPETEER_SKIP_CHROMIUM_DOWNLOAD true -RUN npm ci -COPY ./script /code/script -COPY ./banner.txt /code/banner.txt -WORKDIR /code/script -RUN cp -a /code/deps/node_modules /code/script/ -ENV NODE_ENV production -RUN npm run build - -FROM node:10 as vault - -COPY ./vault/package.json ./vault/package-lock.json /code/deps/ -COPY ./packages /code/packages -WORKDIR /code/deps -ENV PUPPETEER_SKIP_CHROMIUM_DOWNLOAD true -RUN npm ci -COPY ./vault /code/vault -COPY ./banner.txt /code/banner.txt -WORKDIR /code/vault -RUN cp -a /code/deps/node_modules /code/vault/ -ENV NODE_ENV production -RUN npm run build - FROM nikolaik/python-nodejs:python3.7-nodejs10 as homepage ARG siteurl @@ -64,9 +22,6 @@ ARG robots ENV ROBOTS_FILE=$robots COPY --from=homepage /code/homepage/output /www/data -COPY --from=script /code/script/dist /www/data -COPY --from=auditorium /code/auditorium/dist /www/data/auditorium -COPY --from=vault /code/vault/dist /www/data/vault COPY ./build/proxy/$ROBOTS_FILE /www/data/robots.txt COPY ./build/proxy/nginx.conf /etc/nginx/nginx.conf diff --git a/build/proxy/nginx.conf b/build/proxy/nginx.conf index afd2555..4208da1 100644 --- a/build/proxy/nginx.conf +++ b/build/proxy/nginx.conf @@ -37,13 +37,21 @@ http { location /api/ { proxy_pass http://server; proxy_redirect off; - rewrite ^/api(.*)$ $1 break; - proxy_hide_header Content-Type; - add_header Content-Type "application/json"; + } + + location /vault/ { + proxy_pass http://server; + proxy_redirect off; } location /auditorium/ { - try_files $uri $uri/ /auditorium/index.html; + proxy_pass http://server; + proxy_redirect off; + } + + location /script.js { + proxy_pass http://server; + proxy_redirect off; } error_page 404 /404.html; diff --git a/docker-compose.yml b/docker-compose.yml index fe8b059..cb6cbf2 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -22,6 +22,7 @@ services: volumes: - .:/offen - ./bootstrap.yml:/offen/server/bootstrap.yml + - ./public:/offen/server/public - serverdeps:/go/pkg/mod environment: POSTGRES_CONNECTION_STRING: postgres://postgres:develop@server_database:5432/postgres?sslmode=disable From 48eaaec35f359d5c30d6e6b61597758dc52c258d Mon Sep 17 00:00:00 2001 From: Frederik Ring Date: Fri, 4 Oct 2019 19:49:19 +0200 Subject: [PATCH 2/6] fix double handling of api requests --- build/proxy/nginx.conf | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/build/proxy/nginx.conf b/build/proxy/nginx.conf index 4208da1..f3b21b0 100644 --- a/build/proxy/nginx.conf +++ b/build/proxy/nginx.conf @@ -54,6 +54,11 @@ http { proxy_redirect off; } + location /healthz { + proxy_pass http://server; + proxy_redirect off; + } + error_page 404 /404.html; location = /404.html { internal; From 9e3e0681426d01d87455dea7851397f48b9df10d Mon Sep 17 00:00:00 2001 From: Frederik Ring Date: Fri, 4 Oct 2019 21:34:27 +0200 Subject: [PATCH 3/6] inline static assets into binary --- docker-compose.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/docker-compose.yml b/docker-compose.yml index cb6cbf2..fe8b059 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -22,7 +22,6 @@ services: volumes: - .:/offen - ./bootstrap.yml:/offen/server/bootstrap.yml - - ./public:/offen/server/public - serverdeps:/go/pkg/mod environment: POSTGRES_CONNECTION_STRING: postgres://postgres:develop@server_database:5432/postgres?sslmode=disable From af1df38a56c8a8c1a2259372bf25c3d2932777e9 Mon Sep 17 00:00:00 2001 From: Frederik Ring Date: Sun, 6 Oct 2019 13:27:36 +0200 Subject: [PATCH 4/6] use single filesystem for serving static assets --- docker-compose.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docker-compose.yml b/docker-compose.yml index fe8b059..a845eb4 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -34,6 +34,8 @@ services: command: refresh run links: - server_database + ports: + - 8081:8080 server_database: image: postgres:11.2 From e137363d61a65cbfb5f53be9712a4e3667837731 Mon Sep 17 00:00:00 2001 From: Frederik Ring Date: Sun, 6 Oct 2019 13:52:45 +0200 Subject: [PATCH 5/6] further clean up routing logic --- .gitignore | 1 - build/proxy/nginx.conf | 4 ++++ homepage/content/pages/404.md | 1 + homepage/theme/templates/base.html | 2 +- 4 files changed, 6 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 75e3c50..e86e3a3 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,6 @@ .vscode .serverless node_modules/ -public/ *.pem venv/ diff --git a/build/proxy/nginx.conf b/build/proxy/nginx.conf index f3b21b0..9363c38 100644 --- a/build/proxy/nginx.conf +++ b/build/proxy/nginx.conf @@ -59,6 +59,10 @@ http { proxy_redirect off; } + location /favicon.ico { + root /www/data/theme/images; + } + error_page 404 /404.html; location = /404.html { internal; diff --git a/homepage/content/pages/404.md b/homepage/content/pages/404.md index 6f478be..db7f3d3 100644 --- a/homepage/content/pages/404.md +++ b/homepage/content/pages/404.md @@ -2,6 +2,7 @@ Title: Page not found | offen description: offen is a free and open source analytics software for websites and web applications that allows respectful handling of data. save_as: 404.html href: /404.html +no_stats: true ![Page not Found](/theme/images/content-404.webp){:class="image-text-560-315"} diff --git a/homepage/theme/templates/base.html b/homepage/theme/templates/base.html index 18854a4..7b64464 100644 --- a/homepage/theme/templates/base.html +++ b/homepage/theme/templates/base.html @@ -22,7 +22,7 @@ {% assets filters="cssmin", output="css/style.min.css", "css/normalize.css", "css/fonts.css", "css/style.css" %} {% endassets %} - {% if OFFEN_ACCOUNT_ID %} + {% if OFFEN_ACCOUNT_ID and not page.no_stats %} {% endif %} From 5c63b39e8ce9d4f1b54d045db724b371380b652a Mon Sep 17 00:00:00 2001 From: Frederik Ring Date: Sun, 6 Oct 2019 21:09:53 +0200 Subject: [PATCH 6/6] use single gitignore file --- .gitignore | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index e86e3a3..0503146 100644 --- a/.gitignore +++ b/.gitignore @@ -1,8 +1,12 @@ .vscode -.serverless -node_modules/ *.pem -venv/ bootstrap-alpha.yml Dockerrun.aws.json + +node_modules/ +dist/ +*.log + +bin/ +statik.go