49 lines
1.2 KiB
Docker
49 lines
1.2 KiB
Docker
# Stage 1: Dependencies install (cached if lockfile unchanged)
|
|
FROM node:22-alpine AS deps
|
|
|
|
WORKDIR /app
|
|
|
|
# Only copy dependency-related files to leverage cache
|
|
COPY package.json yarn.lock ./
|
|
|
|
# Install dependencies
|
|
RUN yarn install --frozen-lockfile
|
|
|
|
# Stage 2: Build the app
|
|
FROM node:22-alpine AS builder
|
|
|
|
ARG VITE_API_URL
|
|
ENV VITE_API_URL=$VITE_API_URL
|
|
|
|
WORKDIR /app
|
|
|
|
# Copy deps from previous stage to cache node_modules
|
|
COPY --from=deps /app/node_modules ./node_modules
|
|
COPY --from=deps /app/package.json ./package.json
|
|
COPY --from=deps /app/yarn.lock ./yarn.lock
|
|
|
|
# Copy rest of app
|
|
COPY src/ ./src
|
|
COPY public/ ./public
|
|
COPY .env.production ./.env.production
|
|
COPY index.html ./index.html
|
|
COPY tsconfig.json ./tsconfig.json
|
|
COPY tsconfig.app.json ./tsconfig.app.json
|
|
COPY tsconfig.node.json ./tsconfig.node.json
|
|
COPY vite.config.ts ./vite.config.ts
|
|
|
|
# Build the Vite app
|
|
RUN yarn build
|
|
|
|
# Stage 3: Serve with Caddy
|
|
FROM caddy:alpine
|
|
|
|
# Copy built app to the web root
|
|
COPY --from=builder /app/dist /usr/share/caddy
|
|
|
|
# Add Caddyfile (for routing support)
|
|
COPY Caddyfile /etc/caddy/Caddyfile
|
|
|
|
EXPOSE 80
|
|
|
|
CMD ["caddy", "run", "--config", "/etc/caddy/Caddyfile", "--adapter", "caddyfile"]
|