From f8a21f4c2396ac62ef097d1ad2fa12789298c0d2 Mon Sep 17 00:00:00 2001 From: Liam MacPherson Date: Fri, 8 Sep 2023 14:28:55 +0100 Subject: [PATCH] Add Docker static site containerisation This change adds Docker containerisation utilising a multi-stage build Dockerfile. This leads to the static site being generated and served through nginx. --- .github/dependabot.yml | 10 ++++++++- Dockerfile | 18 ++++++++++++++++ nginx/nginx.conf | 47 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 74 insertions(+), 1 deletion(-) create mode 100644 Dockerfile create mode 100644 nginx/nginx.conf diff --git a/.github/dependabot.yml b/.github/dependabot.yml index 1ca57a87..a6e14b61 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -1,9 +1,17 @@ version: 2 updates: + - package-ecosystem: "docker" + directory: "/" + schedule: + interval: "daily" + commit-message: + prefix: "docker" + labels: + - "dependencies" - package-ecosystem: "github-actions" directory: "/" schedule: - interval: "weekly" + interval: "daily" commit-message: prefix: "github-actions" labels: diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..37314b95 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,18 @@ +FROM node:18.18.0-alpine AS build + +COPY . . + +RUN apk update && apk upgrade && \ + apk add --no-cache git + +RUN npm ci --omit=dev +RUN npm run build + +FROM nginx:1.25.2-alpine + +COPY --from=build /_site /usr/share/nginx/html +COPY --from=build /nginx/nginx.conf /etc/nginx/nginx.conf + +USER 1000 + +CMD ["/usr/sbin/nginx", "-g", "daemon off;"] diff --git a/nginx/nginx.conf b/nginx/nginx.conf new file mode 100644 index 00000000..141488e2 --- /dev/null +++ b/nginx/nginx.conf @@ -0,0 +1,47 @@ +worker_processes 1; + +error_log /var/log/nginx/error.log warn; +pid /tmp/nginx.pid; + +events { + worker_connections 1024; +} + +http { + include /etc/nginx/mime.types; + default_type application/octet-stream; + + log_format main '$remote_addr - $remote_user [$time_local] "$request" ' + '$status $body_bytes_sent "$http_referer" ' + '"$http_user_agent" "$http_x_forwarded_for"'; + + access_log /var/log/nginx/access.log main; + + sendfile on; + + keepalive_timeout 10; + send_timeout 10; + server_tokens off; + client_body_timeout 10; + client_header_timeout 10; + client_max_body_size 100K; + + server { + listen 80; + root /usr/share/nginx/html; + + location / { + try_files $uri $uri/ $uri.html =404; + } + + error_page 404 /404.html; + error_page 500 502 503 504 /50x.html; + } + + client_body_temp_path /tmp/client_temp; + proxy_temp_path /tmp/proxy_temp_path; + fastcgi_temp_path /tmp/fastcgi_temp; + uwsgi_temp_path /tmp/uwsgi_temp; + scgi_temp_path /tmp/scgi_temp; + +}