diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..7e35565 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,7 @@ +node_modules +dist +.git +.gitignore +.vscode +*.md +.DS_Store diff --git a/Caddyfile b/Caddyfile index cad94d6..79d57b5 100644 --- a/Caddyfile +++ b/Caddyfile @@ -1,4 +1,4 @@ -http://spritesheetgenerator.online:1337 { +:1337 { root * ./dist encode zstd gzip @@ -19,7 +19,7 @@ http://spritesheetgenerator.online:1337 { } log { - output file /var/log/caddy/spritesheetgenerator.online.log + output file /var/log/caddy/app.log } } diff --git a/Caddyfile.docker b/Caddyfile.docker new file mode 100644 index 0000000..f5fa181 --- /dev/null +++ b/Caddyfile.docker @@ -0,0 +1,24 @@ +:1337 { + root * /srv/dist + encode zstd gzip + + # Aggressive caching for static assets + @static path *.js *.css *.png *.jpg *.jpeg *.gif *.webp *.svg *.woff *.woff2 *.ico + header @static Cache-Control "public, max-age=31536000, immutable" + + # Short cache for HTML (for SPA updates) + @html path *.html / + header @html Cache-Control "no-cache, must-revalidate" + + # Default cache for everything else + header ?Cache-Control "max-age=1800" + + try_files {path} /index.html + file_server { + precompressed zstd gzip + } + + log { + output stdout + } +} \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..2e35825 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,32 @@ +# Build stage +FROM node:22-alpine AS builder + +WORKDIR /app + +# Copy package files +COPY package.json package-lock.json* ./ + +# Install dependencies +RUN npm ci + +# Copy source files +COPY . . + +# Build the app +RUN npm run build + +# Production stage +FROM caddy:2-alpine + +# Create log directory +RUN mkdir -p /var/log/caddy + +# Copy built files +COPY --from=builder /app/dist /srv/dist + +# Copy Caddy configuration +COPY Caddyfile.docker /etc/caddy/Caddyfile + +EXPOSE 1337 + +CMD ["caddy", "run", "--config", "/etc/caddy/Caddyfile"] \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..ed37403 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,11 @@ +services: + app: + build: . + ports: + - "${PORT:-1337}:1337" + restart: unless-stopped + volumes: + - caddy_logs:/var/log/caddy + +volumes: + caddy_logs: \ No newline at end of file