From 84b794cac9882cb17a74d53492d648430ad95e62 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Thu, 1 Sep 2022 16:57:39 -0500 Subject: [PATCH 1/5] Add preliminary Dockerfile --- .dockerignore | 32 ++++++++++++++++++++++++++++++ Dockerfile | 12 +++++++++++ installation/docker.conf | 43 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 87 insertions(+) create mode 100644 .dockerignore create mode 100644 Dockerfile create mode 100644 installation/docker.conf diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 000000000..92e9362d8 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,32 @@ +/node_modules/ +/tmp/ +/build/ +/coverage/ +/.coverage/ +/.eslintcache +/.env +/deploy.sh +/.vs/ +yarn-error.log* +/junit.xml + +/static/ +/static-test/ +/public/ +/dist/ + +.idea +.DS_Store + +# Custom build files +/custom/**/* +!/custom/* +/custom/*.* +!/custom/.gitkeep +!/custom/**/.gitkeep + +# surge.sh +/CNAME +/AUTH +/CORS +/ROUTER diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 000000000..f93c5fdbe --- /dev/null +++ b/Dockerfile @@ -0,0 +1,12 @@ +FROM node:18 as build +WORKDIR /app +COPY package.json . +COPY yarn.lock . +RUN yarn +COPY . . +ARG NODE_ENV=production +RUN yarn build + +FROM nginx:stable-alpine +COPY installation/docker.conf /etc/nginx/conf.d/default.conf +COPY --from=build /app/static /usr/share/nginx/html diff --git a/installation/docker.conf b/installation/docker.conf new file mode 100644 index 000000000..cdd5699ae --- /dev/null +++ b/installation/docker.conf @@ -0,0 +1,43 @@ +# Soapbox Nginx for Docker. +server { + keepalive_timeout 70; + sendfile on; + client_max_body_size 80m; + + root /usr/share/nginx/html; + + gzip on; + gzip_vary on; + gzip_proxied any; + gzip_comp_level 6; + gzip_buffers 16 8k; + gzip_http_version 1.1; + gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript image/svg+xml image/x-icon; + + add_header Strict-Transport-Security "max-age=31536000" always; + + # SPA. + # Try static files, then fall back to index.html. + location / { + try_files $uri /index.html; + } + + # Build files. + # New builds produce hashed filenames, so these should be cached heavily. + location /packs { + add_header Cache-Control "public, max-age=31536000, immutable"; + add_header Strict-Transport-Security "max-age=31536000" always; + } + + # Return 404 on API routes so Soapbox knows what to do. + location /api { + add_header Content-Type "application/json"; + return 404 '{"error": "Not implemented"}'; + } + + # ServiceWorker: don't cache. + location = /sw.js { + add_header Cache-Control "public, max-age=0"; + add_header Strict-Transport-Security "max-age=31536000" always; + } +} From ce397ba7aa8794154c9b84fb8cce3caace29cf85 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Thu, 1 Sep 2022 16:59:44 -0500 Subject: [PATCH 2/5] Add app.json --- app.json | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 app.json diff --git a/app.json b/app.json new file mode 100644 index 000000000..bd168fb5a --- /dev/null +++ b/app.json @@ -0,0 +1,7 @@ +{ + "name": "Soapbox", + "description": "Software for the next generation of social media.", + "keywords": ["fediverse"], + "website": "https://soapbox.pub", + "stack": "container" +} From 5aa9db26853b308da16b49005b6d5be7085c2a4a Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Thu, 1 Sep 2022 17:21:05 -0500 Subject: [PATCH 3/5] Add heroku.yml so it uses the Dockerfile --- heroku.yml | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 heroku.yml diff --git a/heroku.yml b/heroku.yml new file mode 100644 index 000000000..8eec25b9c --- /dev/null +++ b/heroku.yml @@ -0,0 +1,3 @@ +build: + docker: + web: Dockerfile From a50a760f52653f3d0d0c469331d76f80b4f14fb6 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Thu, 1 Sep 2022 18:10:41 -0500 Subject: [PATCH 4/5] Dockerfile: support the PORT variable, expose 5000 by default --- Dockerfile | 4 +++- installation/docker.conf | 2 ++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index f93c5fdbe..a15e8aad9 100644 --- a/Dockerfile +++ b/Dockerfile @@ -8,5 +8,7 @@ ARG NODE_ENV=production RUN yarn build FROM nginx:stable-alpine -COPY installation/docker.conf /etc/nginx/conf.d/default.conf +EXPOSE 5000 +ENV PORT=5000 +COPY installation/docker.conf /etc/nginx/templates/default.conf.template COPY --from=build /app/static /usr/share/nginx/html diff --git a/installation/docker.conf b/installation/docker.conf index cdd5699ae..072283fc7 100644 --- a/installation/docker.conf +++ b/installation/docker.conf @@ -1,5 +1,7 @@ # Soapbox Nginx for Docker. server { + listen ${PORT}; + keepalive_timeout 70; sendfile on; client_max_body_size 80m; From bb680be366934d13c0aadaf7e536f8542825635c Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Thu, 1 Sep 2022 19:49:21 -0500 Subject: [PATCH 5/5] docker.conf --> docker.conf.template --- Dockerfile | 2 +- installation/{docker.conf => docker.conf.template} | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) rename installation/{docker.conf => docker.conf.template} (89%) diff --git a/Dockerfile b/Dockerfile index a15e8aad9..efe959b6d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -10,5 +10,5 @@ RUN yarn build FROM nginx:stable-alpine EXPOSE 5000 ENV PORT=5000 -COPY installation/docker.conf /etc/nginx/templates/default.conf.template +COPY installation/docker.conf.template /etc/nginx/templates/default.conf.template COPY --from=build /app/static /usr/share/nginx/html diff --git a/installation/docker.conf b/installation/docker.conf.template similarity index 89% rename from installation/docker.conf rename to installation/docker.conf.template index 072283fc7..d4393ad35 100644 --- a/installation/docker.conf +++ b/installation/docker.conf.template @@ -1,4 +1,7 @@ # Soapbox Nginx for Docker. +# It's intended to be used by the official nginx image, which has templating functionality. +# Mount at: `/etc/nginx/templates/default.conf.template` + server { listen ${PORT};