diff --git a/Caddyfile b/Caddyfile new file mode 100644 index 0000000..c6dd4c3 --- /dev/null +++ b/Caddyfile @@ -0,0 +1,31 @@ +{ + # Disable automatic HTTPS + auto_https off +} + +:8080 { + root * {$DIST_PATH:/usr/share/caddy} + + file_server + + encode gzip zstd + + try_files {path} {path}/ /index.html + + # Cache favicons aggressively + @favicons path /favicons/* + header @favicons Cache-Control "public, max-age=31536000, immutable" + + # Cache static assets based on MIME type + @static { + header Content-Type application/javascript* + header Content-Type text/css* + header Content-Type image/* + header Content-Type font/* + header Content-Type application/font-* + header Content-Type application/woff* + header Content-Type application/json* + } + + header @static Cache-Control "public, max-age=2592000, immutable" +} diff --git a/Dockerfile b/Dockerfile index 3187dbd..65c2d1e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -23,21 +23,16 @@ ENV VITE_ELASTIC_API_KEY=$ELASTIC_API_KEY RUN yarn build -FROM nginx:1.29.5 +FROM caddy:2.11-alpine + +COPY Caddyfile /etc/caddy/Caddyfile + +# Copy static files +COPY public /usr/share/caddy # Copy the static build from the previous stage -COPY index.html /usr/share/nginx/html -COPY public/ /usr/share/nginx/html -COPY --from=build /app/dist /usr/share/nginx/html +COPY --from=build /app/dist /usr/share/caddy -# Copy nginx config file -COPY nginx.conf /etc/nginx/conf.d/default.conf.template - -# Manual entrypoint after nginx substring -COPY docker-entrypoint.sh /docker-entrypoint.d/05-docker-entrypoint.sh - -RUN chmod +x /docker-entrypoint.d/05-docker-entrypoint.sh - -EXPOSE 5000 +EXPOSE 8080 LABEL org.opencontainers.image.source https://github.com/kevinmidboe/seasoned diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh deleted file mode 100644 index 24e7b29..0000000 --- a/docker-entrypoint.sh +++ /dev/null @@ -1,9 +0,0 @@ -#!/bin/sh -set -eu - -export SEASONED_API=${SEASONED_API:-http://localhost:31459} -export SEASONED_DOMAIN=${SEASONED_DOMAIN:-localhost} - -envsubst '$SEASONED_API,$SEASONED_DOMAIN' < /etc/nginx/conf.d/default.conf.template > /etc/nginx/conf.d/default.conf - -exec "$@" diff --git a/nginx.conf b/nginx.conf deleted file mode 100644 index 968ecaf..0000000 --- a/nginx.conf +++ /dev/null @@ -1,30 +0,0 @@ -server { - listen 5000 default_server; - listen [::]:5000 default_server; - - server_name _; - root /usr/share/nginx/html; - - gzip on; - gzip_types application/javascript; - gzip_min_length 1000; - gzip_static on; - - location /favicons { - autoindex on; - } - - location /dist { - add_header Content-Type application/javascript; - try_files $uri =404; - } - - location /api { - proxy_pass $SEASONED_API; - } - - location / { - try_files $uri $uri/ /index.html; - index index.html; - } -}