From 493d45ff6d91213855cac931c4034878c9cd3530 Mon Sep 17 00:00:00 2001 From: Dylan F Date: Tue, 21 Oct 2025 18:25:29 +0700 Subject: [PATCH 01/10] WIP add dockerfile (7/7 but missing files) --- Dockerfile | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 Dockerfile diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 000000000..83a4b7841 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,60 @@ +# Stage 1: builder +FROM node:22-alpine AS builder + +WORKDIR /app + +# install pnpm & git +RUN npm install -g pnpm +RUN apk update && \ + apk upgrade && \ + apk add --no-cache git + +RUN git init + + +# copy lock, package files and configs +COPY package.json pnpm-lock.yaml ./ +COPY run-jiti.js ./ +COPY src/features/build-info/script-to-generate-json.ts src/features/build-info/build-info.gen.json ./src/features/build-info/ +COPY prisma/schema.prisma ./prisma/ +RUN pnpm install --frozen-lockfile --prod=false + +# copy source +COPY . . + +# build .output +ENV NODE_OPTIONS=--max-old-space-size=4096 +RUN pnpm build + + +# Stage 2: runtime +FROM node:22-alpine AS runtime + + +WORKDIR /app + +# install pnpm +RUN npm install -g pnpm +RUN npm install -g npm-run-all + + +## copy output build and package.json from builder +COPY --from=builder /app/.output ./.output +COPY --from=builder /app/package.json ./package.json +COPY --from=builder /app/src/features/build-info/build-info.gen.json ./src/features/build-info/build-info.gen.json +COPY --from=builder /app/src/features/build-info/script-to-generate-json.ts ./src/features/build-info/script-to-generate-json.ts + +# install only production dependencies + + +RUN pnpm install --prod + +ENV NODE_ENV=production + +ENV HOST=0.0.0.0 +ENV PORT=3000 + +EXPOSE 3000 + +# start +CMD ["pnpm", "start"] From f9063450faf4ff2e0a3e8ad01045df27bc80430a Mon Sep 17 00:00:00 2001 From: Dylan F Date: Wed, 22 Oct 2025 13:08:18 +0700 Subject: [PATCH 02/10] WIP building working --- Dockerfile | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/Dockerfile b/Dockerfile index 83a4b7841..4cc2bc758 100644 --- a/Dockerfile +++ b/Dockerfile @@ -17,7 +17,7 @@ COPY package.json pnpm-lock.yaml ./ COPY run-jiti.js ./ COPY src/features/build-info/script-to-generate-json.ts src/features/build-info/build-info.gen.json ./src/features/build-info/ COPY prisma/schema.prisma ./prisma/ -RUN pnpm install --frozen-lockfile --prod=false +RUN pnpm install --frozen-lockfile # copy source COPY . . @@ -34,20 +34,17 @@ FROM node:22-alpine AS runtime WORKDIR /app # install pnpm -RUN npm install -g pnpm -RUN npm install -g npm-run-all +RUN npm install -g pnpm npm-run-all + +COPY .env ./ + ## copy output build and package.json from builder COPY --from=builder /app/.output ./.output COPY --from=builder /app/package.json ./package.json -COPY --from=builder /app/src/features/build-info/build-info.gen.json ./src/features/build-info/build-info.gen.json -COPY --from=builder /app/src/features/build-info/script-to-generate-json.ts ./src/features/build-info/script-to-generate-json.ts - -# install only production dependencies - - -RUN pnpm install --prod +COPY --from=builder /app/pnpm-lock.yaml ./pnpm-lock.yaml +COPY --from=builder /app/node_modules ./node_modules ENV NODE_ENV=production From 39b5d55ceb269eb69439cc5141371237c49a6bdc Mon Sep 17 00:00:00 2001 From: Dylan F Date: Thu, 23 Oct 2025 14:57:15 +0800 Subject: [PATCH 03/10] set config for database --- .env.example | 3 +++ Dockerfile | 14 ++++++++------ package.json | 1 + 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/.env.example b/.env.example index 6337b9aed..8b9b5e3ca 100644 --- a/.env.example +++ b/.env.example @@ -19,6 +19,9 @@ VITE_IS_DEMO="false" # DATABASE DATABASE_URL="postgres://${DOCKER_DATABASE_USERNAME}:${DOCKER_DATABASE_PASSWORD}@localhost:${DOCKER_DATABASE_PORT}/${DOCKER_DATABASE_NAME}" +# for docker build use: +# DATABASE_URL="postgres://${DOCKER_DATABASE_USERNAME}:${DOCKER_DATABASE_PASSWORD}start-ui-web-postgres-1/${DOCKER_DATABASE_NAME}" + # AUTH AUTH_SECRET="REPLACE ME" # You can use `npx @better-auth/cli@latest secret` to a generated secret AUTH_SESSION_EXPIRATION_IN_SECONDS=2592000 # 30 days diff --git a/Dockerfile b/Dockerfile index 4cc2bc758..38ed917db 100644 --- a/Dockerfile +++ b/Dockerfile @@ -17,13 +17,15 @@ COPY package.json pnpm-lock.yaml ./ COPY run-jiti.js ./ COPY src/features/build-info/script-to-generate-json.ts src/features/build-info/build-info.gen.json ./src/features/build-info/ COPY prisma/schema.prisma ./prisma/ + RUN pnpm install --frozen-lockfile # copy source COPY . . -# build .output ENV NODE_OPTIONS=--max-old-space-size=4096 + +# build app RUN pnpm build @@ -33,6 +35,11 @@ FROM node:22-alpine AS runtime WORKDIR /app +# ENV +ENV NODE_ENV=production +ENV HOST=0.0.0.0 +ENV PORT=3000 + # install pnpm RUN npm install -g pnpm npm-run-all @@ -46,11 +53,6 @@ COPY --from=builder /app/package.json ./package.json COPY --from=builder /app/pnpm-lock.yaml ./pnpm-lock.yaml COPY --from=builder /app/node_modules ./node_modules -ENV NODE_ENV=production - -ENV HOST=0.0.0.0 -ENV PORT=3000 - EXPOSE 3000 # start diff --git a/package.json b/package.json index 19302c0a7..01217ecd2 100644 --- a/package.json +++ b/package.json @@ -36,6 +36,7 @@ "dk:start": "docker compose start", "dk:stop": "docker compose stop", "dk:clear": "docker compose down --volumes", + "dk:build": "docker build -t start-ui-web . && docker run -d --network start-ui-web_default -p 3000:3000 --name start-ui-web-container start-ui-web", "db:init": "pnpm db:push && pnpm db:seed", "db:push": "prisma db push", "db:ui": "prisma studio", From 16a2e4b208d817366a01afb014238987d4ea4159 Mon Sep 17 00:00:00 2001 From: Dylan F Date: Thu, 23 Oct 2025 18:03:54 +0800 Subject: [PATCH 04/10] WIP feedback --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 38ed917db..15fe6492e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -51,7 +51,7 @@ COPY .env ./ COPY --from=builder /app/.output ./.output COPY --from=builder /app/package.json ./package.json COPY --from=builder /app/pnpm-lock.yaml ./pnpm-lock.yaml -COPY --from=builder /app/node_modules ./node_modules +RUN pnpm install --frozen-lockfile EXPOSE 3000 From a0ab4c7f9a499df4f4abdddfb886813ab1832e00 Mon Sep 17 00:00:00 2001 From: Dylan F Date: Fri, 24 Oct 2025 18:18:09 +0800 Subject: [PATCH 05/10] fix: remove command in package.json and update readme.md --- README.md | 13 +++++++++++++ package.json | 1 - 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 43c523cb0..a4bab5738 100644 --- a/README.md +++ b/README.md @@ -54,7 +54,20 @@ pnpm dev > > Setup a PostgreSQL database (locally or online) and replace the **DATABASE_URL** environment variable. Then you can run `pnpm db:push` to update your database schema and then run `pnpm db:seed` to seed your database. +## Dockerfile +Build the image using the following command + +```bash +docker build -t start-ui-web . +``` +Then, you can run it with this example command: + +```bash +And now you can use this command example to run it `docker run -d --network start-ui-web_default -p 3000:3000 --name start-ui-web-container start-ui-web` +``` + +During the build process, it automatically uses your project’s .env file. ### Emails in development diff --git a/package.json b/package.json index 01217ecd2..19302c0a7 100644 --- a/package.json +++ b/package.json @@ -36,7 +36,6 @@ "dk:start": "docker compose start", "dk:stop": "docker compose stop", "dk:clear": "docker compose down --volumes", - "dk:build": "docker build -t start-ui-web . && docker run -d --network start-ui-web_default -p 3000:3000 --name start-ui-web-container start-ui-web", "db:init": "pnpm db:push && pnpm db:seed", "db:push": "prisma db push", "db:ui": "prisma studio", From 83127739aa7f072b9741b33ece52fae985cbc09f Mon Sep 17 00:00:00 2001 From: Dylan F Date: Fri, 24 Oct 2025 18:27:20 +0800 Subject: [PATCH 06/10] fix readme dockerfile syntax on example --- README.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index a4bab5738..d71a4e7e5 100644 --- a/README.md +++ b/README.md @@ -62,11 +62,13 @@ Build the image using the following command docker build -t start-ui-web . ``` Then, you can run it with this example command: - ```bash -And now you can use this command example to run it `docker run -d --network start-ui-web_default -p 3000:3000 --name start-ui-web-container start-ui-web` +docker run -d --network start-ui-web_default -p 3000:3000 --name start-ui-web-container start-ui-web ``` +> [!NOTE] +> The network name `start-ui-web_default` is created by Docker Compose when you run `pnpm dk:start`. If you're running Docker without Docker Compose, use `--network bridge` or omit the `--network` flag. + During the build process, it automatically uses your project’s .env file. From 1e9c8a31d072fa99fd8b11f74a654b187f2ad60d Mon Sep 17 00:00:00 2001 From: Dylan F Date: Wed, 29 Oct 2025 14:50:51 +0100 Subject: [PATCH 07/10] clear and add comments --- Dockerfile | 69 +++++++++++++++++++++++++++++------------------------- 1 file changed, 37 insertions(+), 32 deletions(-) diff --git a/Dockerfile b/Dockerfile index 15fe6492e..445c0d707 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,59 +1,64 @@ -# Stage 1: builder + +# Builder Stage FROM node:22-alpine AS builder WORKDIR /app -# install pnpm & git -RUN npm install -g pnpm -RUN apk update && \ - apk upgrade && \ - apk add --no-cache git - -RUN git init - +# install tools +RUN npm install -g pnpm && \ + apk add --no-cache git && \ + git init -# copy lock, package files and configs +# copy files needed for installing dependencies COPY package.json pnpm-lock.yaml ./ -COPY run-jiti.js ./ -COPY src/features/build-info/script-to-generate-json.ts src/features/build-info/build-info.gen.json ./src/features/build-info/ COPY prisma/schema.prisma ./prisma/ +COPY run-jiti.js ./ +COPY src/features/build-info/script-to-generate-json.ts ./src/features/build-info/ +# install dependencies RUN pnpm install --frozen-lockfile -# copy source +# copy source code COPY . . +# build the application ENV NODE_OPTIONS=--max-old-space-size=4096 - -# build app RUN pnpm build -# Stage 2: runtime -FROM node:22-alpine AS runtime - +# Runtime Stage +FROM node:22-alpine WORKDIR /app -# ENV -ENV NODE_ENV=production -ENV HOST=0.0.0.0 -ENV PORT=3000 - -# install pnpm -RUN npm install -g pnpm npm-run-all - +# Environnement variables +ENV NODE_ENV=production \ + HOST=0.0.0.0 \ + PORT=3000 + +# install tools +RUN npm install -g pnpm npm-run-all && \ + apk add --no-cache git && \ + git init + +# copy files needed for installing dependencies +COPY --from=builder /app/package.json ./ +COPY --from=builder /app/pnpm-lock.yaml ./ +COPY --from=builder /app/run-jiti.js ./ +COPY --from=builder /app/prisma ./prisma +COPY --from=builder /app/src/features/build-info ./src/features/build-info + +# copy environment configuration +# TODO: Replace with environment variables or secrets in production COPY .env ./ +# install production dependencies (this will run prisma generate) +RUN pnpm install --frozen-lockfile - -## copy output build and package.json from builder +# copy build artifacts after installation COPY --from=builder /app/.output ./.output -COPY --from=builder /app/package.json ./package.json -COPY --from=builder /app/pnpm-lock.yaml ./pnpm-lock.yaml -RUN pnpm install --frozen-lockfile EXPOSE 3000 -# start +# start the application CMD ["pnpm", "start"] From 7e075660519bb1b4dacf8a7d14d6bc3ec07d7c67 Mon Sep 17 00:00:00 2001 From: Dylan F Date: Wed, 29 Oct 2025 15:36:44 +0100 Subject: [PATCH 08/10] copying node_modules instead of reinstalling them --- Dockerfile | 30 +++++++++--------------------- 1 file changed, 9 insertions(+), 21 deletions(-) diff --git a/Dockerfile b/Dockerfile index 445c0d707..e647aedce 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,3 @@ - # Builder Stage FROM node:22-alpine AS builder @@ -31,32 +30,21 @@ FROM node:22-alpine WORKDIR /app -# Environnement variables +# Environment variables ENV NODE_ENV=production \ HOST=0.0.0.0 \ - PORT=3000 - -# install tools -RUN npm install -g pnpm npm-run-all && \ - apk add --no-cache git && \ - git init + PORT=3000 \ + VITE_PORT=3000 -# copy files needed for installing dependencies -COPY --from=builder /app/package.json ./ -COPY --from=builder /app/pnpm-lock.yaml ./ -COPY --from=builder /app/run-jiti.js ./ -COPY --from=builder /app/prisma ./prisma -COPY --from=builder /app/src/features/build-info ./src/features/build-info - -# copy environment configuration -# TODO: Replace with environment variables or secrets in production +# install pnpm +RUN npm install -g pnpm npm-run-all COPY .env ./ -# install production dependencies (this will run prisma generate) -RUN pnpm install --frozen-lockfile - -# copy build artifacts after installation +## copy output build and package.json from builder COPY --from=builder /app/.output ./.output +COPY --from=builder /app/package.json ./package.json +COPY --from=builder /app/pnpm-lock.yaml ./pnpm-lock.yaml +COPY --from=builder /app/node_modules ./node_modules EXPOSE 3000 From 11550febd3f40656c1d4040a6fc568a886ec057e Mon Sep 17 00:00:00 2001 From: Dylan F Date: Wed, 29 Oct 2025 18:09:36 +0100 Subject: [PATCH 09/10] Use var env instead of .env file --- Dockerfile | 58 ++++++++++++++++++++++++++++++++++++++++++++++-------- README.md | 14 ++++++++++++- 2 files changed, 63 insertions(+), 9 deletions(-) diff --git a/Dockerfile b/Dockerfile index e647aedce..34db02904 100644 --- a/Dockerfile +++ b/Dockerfile @@ -15,7 +15,31 @@ COPY run-jiti.js ./ COPY src/features/build-info/script-to-generate-json.ts ./src/features/build-info/ # install dependencies -RUN pnpm install --frozen-lockfile +RUN pnpm install --frozen-lockfil + +ARG VITE_BASE_URL +ARG VITE_ENV_NAME +ARG VITE_ENV_EMOJI +ARG VITE_ENV_COLOR +ARG VITE_IS_DEMO +ARG DATABASE_URL +ARG AUTH_SECRET +ARG GITHUB_CLIENT_ID +ARG GITHUB_CLIENT_SECRET +ARG EMAIL_SERVER +ARG EMAIL_FROM + +ENV VITE_BASE_URL=${VITE_BASE_URL} \ + VITE_ENV_NAME=${VITE_ENV_NAME} \ + VITE_ENV_EMOJI=${VITE_ENV_EMOJI} \ + VITE_ENV_COLOR=${VITE_ENV_COLOR} \ + VITE_IS_DEMO=${VITE_IS_DEMO} \ + DATABASE_URL=${DATABASE_URL} \ + AUTH_SECRET=${AUTH_SECRET} \ + GITHUB_CLIENT_ID=${GITHUB_CLIENT_ID} \ + GITHUB_CLIENT_SECRET=${GITHUB_CLIENT_SECRET} \ + EMAIL_SERVER=${EMAIL_SERVER} \ + EMAIL_FROM=${EMAIL_FROM} # copy source code COPY . . @@ -30,15 +54,33 @@ FROM node:22-alpine WORKDIR /app -# Environment variables -ENV NODE_ENV=production \ - HOST=0.0.0.0 \ - PORT=3000 \ - VITE_PORT=3000 - # install pnpm RUN npm install -g pnpm npm-run-all -COPY .env ./ + + +ARG VITE_BASE_URL +ARG VITE_ENV_NAME +ARG VITE_ENV_EMOJI +ARG VITE_ENV_COLOR +ARG VITE_IS_DEMO +ARG DATABASE_URL +ARG AUTH_SECRET +ARG GITHUB_CLIENT_ID +ARG GITHUB_CLIENT_SECRET +ARG EMAIL_SERVER +ARG EMAIL_FROM + +ENV VITE_BASE_URL=${VITE_BASE_URL} \ + VITE_ENV_NAME=${VITE_ENV_NAME} \ + VITE_ENV_EMOJI=${VITE_ENV_EMOJI} \ + VITE_ENV_COLOR=${VITE_ENV_COLOR} \ + VITE_IS_DEMO=${VITE_IS_DEMO} \ + DATABASE_URL=${DATABASE_URL} \ + AUTH_SECRET=${AUTH_SECRET} \ + GITHUB_CLIENT_ID=${GITHUB_CLIENT_ID} \ + GITHUB_CLIENT_SECRET=${GITHUB_CLIENT_SECRET} \ + EMAIL_SERVER=${EMAIL_SERVER} \ + EMAIL_FROM=${EMAIL_FROM} ## copy output build and package.json from builder COPY --from=builder /app/.output ./.output diff --git a/README.md b/README.md index d71a4e7e5..f295d8c9d 100644 --- a/README.md +++ b/README.md @@ -59,7 +59,19 @@ pnpm dev Build the image using the following command ```bash -docker build -t start-ui-web . +docker build -t start-ui-web \ + --build-arg VITE_BASE_URL="http://localhost:3000" \ + --build-arg VITE_ENV_NAME="DOCKER" \ + --build-arg VITE_ENV_EMOJI="🐋" \ + --build-arg VITE_ENV_COLOR="blue" \ + --build-arg VITE_IS_DEMO="true" \ + --build-arg DATABASE_URL="postgres://user:pass@host:5432/db" \ + --build-arg AUTH_SECRET="change-me" \ + --build-arg GITHUB_CLIENT_ID="" \ + --build-arg GITHUB_CLIENT_SECRET="" \ + --build-arg EMAIL_SERVER="smtp://user:pass@0.0.0.0:1025" \ + --build-arg EMAIL_FROM="Start UI " \ + . ``` Then, you can run it with this example command: ```bash From a1b0ad277c23cdb5710677096f0c73762d11dc1a Mon Sep 17 00:00:00 2001 From: Dylan F Date: Thu, 30 Oct 2025 10:55:22 +0100 Subject: [PATCH 10/10] missing letter in installation dependencies --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 34db02904..e06baa885 100644 --- a/Dockerfile +++ b/Dockerfile @@ -15,7 +15,7 @@ COPY run-jiti.js ./ COPY src/features/build-info/script-to-generate-json.ts ./src/features/build-info/ # install dependencies -RUN pnpm install --frozen-lockfil +RUN pnpm install --frozen-lockfile ARG VITE_BASE_URL ARG VITE_ENV_NAME