diff --git a/Containerfile b/Containerfile index 239b61e..7770436 100644 --- a/Containerfile +++ b/Containerfile @@ -1,36 +1,26 @@ -# syntax=docker/dockerfile:1.7 - -########### -# BUILD STAGE -########### -FROM cgr.dev/chainguard/node:latest-dev AS build +# Multi-stage build for Astro static site +FROM node:22-alpine AS builder WORKDIR /app -# Copy dependency manifests +# Install deps COPY package*.json ./ +RUN npm ci || npm install -# Install all deps (inkl. dev) -RUN --mount=type=cache,target=/root/.npm npm ci - -# Copy app source and build +# Copy sources and build static output COPY . . RUN npm run build -########### -# RUNTIME STAGE -########### -FROM cgr.dev/chainguard/node:latest -ENV NODE_ENV=production +# ---- Runtime stage ---- +FROM node:22-alpine AS runtime WORKDIR /app - -# Copy only what’s needed to run -COPY --from=build /app/package*.json ./ -COPY --from=build /app/node_modules ./node_modules -COPY --from=build /app/dist ./dist -COPY --from=build /app/server.mjs ./server.mjs - -# Chainguard runs as nonroot by default (user `nonroot`) +ENV NODE_ENV=production +ENV PORT=3000 +ENV WEB_ROOT=/app/dist +ENV TZ=Europe/Berlin +ENV ASTRO_TELEMETRY_DISABLED=1 +COPY --from=builder /app/dist /app/dist +COPY server.mjs /app/server.mjs +# Drop root: use the pre-created node user USER node #EXPOSE 3000 - -CMD ["node", "./server.mjs"] \ No newline at end of file +CMD ["node", "/app/server.mjs"] diff --git a/Containerfile.notworking b/Containerfile.notworking new file mode 100644 index 0000000..239b61e --- /dev/null +++ b/Containerfile.notworking @@ -0,0 +1,36 @@ +# syntax=docker/dockerfile:1.7 + +########### +# BUILD STAGE +########### +FROM cgr.dev/chainguard/node:latest-dev AS build +WORKDIR /app + +# Copy dependency manifests +COPY package*.json ./ + +# Install all deps (inkl. dev) +RUN --mount=type=cache,target=/root/.npm npm ci + +# Copy app source and build +COPY . . +RUN npm run build + +########### +# RUNTIME STAGE +########### +FROM cgr.dev/chainguard/node:latest +ENV NODE_ENV=production +WORKDIR /app + +# Copy only what’s needed to run +COPY --from=build /app/package*.json ./ +COPY --from=build /app/node_modules ./node_modules +COPY --from=build /app/dist ./dist +COPY --from=build /app/server.mjs ./server.mjs + +# Chainguard runs as nonroot by default (user `nonroot`) +USER node +#EXPOSE 3000 + +CMD ["node", "./server.mjs"] \ No newline at end of file diff --git a/Containerfile.old b/Containerfile.old deleted file mode 100644 index 7770436..0000000 --- a/Containerfile.old +++ /dev/null @@ -1,26 +0,0 @@ -# Multi-stage build for Astro static site -FROM node:22-alpine AS builder -WORKDIR /app - -# Install deps -COPY package*.json ./ -RUN npm ci || npm install - -# Copy sources and build static output -COPY . . -RUN npm run build - -# ---- Runtime stage ---- -FROM node:22-alpine AS runtime -WORKDIR /app -ENV NODE_ENV=production -ENV PORT=3000 -ENV WEB_ROOT=/app/dist -ENV TZ=Europe/Berlin -ENV ASTRO_TELEMETRY_DISABLED=1 -COPY --from=builder /app/dist /app/dist -COPY server.mjs /app/server.mjs -# Drop root: use the pre-created node user -USER node -#EXPOSE 3000 -CMD ["node", "/app/server.mjs"]