From 79852df5df9f3aae3b773c974961c131528a2e08 Mon Sep 17 00:00:00 2001 From: Ayo Date: Thu, 7 Aug 2025 12:00:21 +0200 Subject: [PATCH] feat: initial docker build files --- .gitignore | 1 + Dockerfile | 51 +++++++++++++++++++++++++++++++++++++++++++++ docker-compose.yaml | 7 +++++++ 3 files changed, 59 insertions(+) create mode 100644 Dockerfile create mode 100644 docker-compose.yaml diff --git a/.gitignore b/.gitignore index 0c91ee6..fcbdf1b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ node_modules/ dist/ .astro/ +.output/ package-lock.json *~ diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..4f2ad21 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,51 @@ +FROM docker.io/library/node:lts-alpine AS base + +# Prepare work directory +WORKDIR /cozy + +FROM base AS builder + +# Prepare pnpm https://pnpm.io/installation#using-corepack +# workaround for npm registry key change +# ref. `pnpm@10.1.0` / `pnpm@9.15.4` cannot be installed due to key id mismatch · Issue #612 · nodejs/corepack +# - https://github.com/nodejs/corepack/issues/612#issuecomment-2629496091 +RUN npm i -g corepack@latest && corepack enable + +# Prepare deps +RUN apk update +RUN apk add git --no-cache + +# Copy all source files +COPY package.json ./ +COPY pnpm-lock.yaml ./ + +# Run full install +RUN pnpm i --frozen-lockfile --ignore-scripts + +# Copy source +COPY . ./ + +# Build +RUN pnpm build + +FROM base AS runner + +ARG UID=911 +ARG GID=911 + +# Create a dedicated user and group +RUN set -eux; \ + addgroup -g $GID cozy; \ + adduser -u $UID -D -G cozy cozy; + +USER cozy + +ENV NODE_ENV=production + +COPY --from=builder /cozy/ ./ + +EXPOSE 4321/tcp + +ENV PORT=4321 + +CMD ["node", "server.mjs"] diff --git a/docker-compose.yaml b/docker-compose.yaml new file mode 100644 index 0000000..c3595ff --- /dev/null +++ b/docker-compose.yaml @@ -0,0 +1,7 @@ +services: + cozy: + build: + context: . + dockerfile: Dockerfile + ports: + - 4321:4321