This commit is contained in:
2025-10-23 19:08:19 +07:00
parent f1cc5cab98
commit 43292348f6
4 changed files with 61 additions and 3 deletions

18
docker-compose.yml Normal file
View File

@@ -0,0 +1,18 @@
version: "3.8"
services:
web:
build:
context: ./web
dockerfile: Dockerfile
image: my-svelte-web:latest
container_name: web_static
ports:
- "10210:80"
volumes:
- caddy_data:/data
- caddy_config:/config
restart: unless-stopped
volumes:
caddy_data:
caddy_config:

8
web/Caddyfile Normal file
View File

@@ -0,0 +1,8 @@
:80 {
root * /srv/web_build
try_files {path} /200.html
file_server
@health path /health
respond @health "ok" 200
}

26
web/Dockerfile Normal file
View File

@@ -0,0 +1,26 @@
# Builder: build the SvelteKit static site (adapter-static -> /app/build)
FROM node:20-alpine AS builder
WORKDIR /app
# cache package install
COPY package.json package-lock.json* ./
RUN npm ci --production=false
# copy source and build
COPY . .
RUN npm run build
# Final: lightweight Caddy image to serve the built static files
FROM caddy:2-alpine AS runtime
# copy built static output
COPY --from=builder /app/build /srv/web_build
# copy Caddyfile from build context (provide Caddyfile at ./web/Caddyfile)
COPY Caddyfile /etc/caddy/Caddyfile
# # ensure permissions (caddy runs as non-root)
# RUN chown -R caddy:caddy /srv/web_build /etc/caddy/Caddyfile
CMD ["caddy", "run", "--config", "/etc/caddy/Caddyfile"]
# expose standard HTTP/HTTPS (optional in compose)
EXPOSE 80
# container runs Caddy by default (CMD provided by base image)

View File

@@ -1,6 +1,12 @@
import adapter from '@sveltejs/adapter-static';
/** @type {import('@sveltejs/kit').Config} */
const config = { kit: { adapter: adapter() } };
const config = {
kit: {
adapter: adapter({
pages: 'build',
assets: 'build',
fallback: '200.html' // SPA fallback for all unknown paths
})
}
};
export default config;