Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
node_modules
pnpm-lock.yaml
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

pnpm-lock.yaml must NOT be ignored – build will break.

The Dockerfile explicitly copies the lock-file:

COPY package.json pnpm-lock.yaml ./

With the current ignore rule Docker won’t send pnpm-lock.yaml to the build context, so the COPY step fails.

-node_modules
-pnpm-lock.yaml
+node_modules
 # keep the lock-file for reproducible builds
🤖 Prompt for AI Agents
In the .dockerignore file at line 2, remove the entry "pnpm-lock.yaml" to ensure
this lock file is included in the Docker build context. This is necessary
because the Dockerfile explicitly copies pnpm-lock.yaml, and ignoring it causes
the build to fail. Simply delete or comment out this line to fix the issue.

Dockerfile
.git
.gitignore
.env
*.log
2 changes: 2 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
POLAR_API_BASE_URL=https://api.polar.sh/v1
DB_PORT=5432
PORT=3000
31 changes: 31 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Use official Node.js LTS image
FROM node:20-alpine AS base

WORKDIR /app

# Install dependencies only when needed
COPY package.json pnpm-lock.yaml ./
RUN npm install -g pnpm && pnpm install --frozen-lockfile

# Copy Prisma schema and generate client
COPY prisma ./prisma
RUN pnpm exec prisma generate

# Copy rest of the app
COPY . .

# Build Next.js app
RUN pnpm build

# Production image
FROM node:20-alpine AS prod

WORKDIR /app

ENV NODE_ENV=production

COPY --from=base /app ./

Comment on lines +25 to +28
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Prune dev-dependencies to slim the production image.

The current flow copies node_modules containing dev deps.
After copying, run pnpm prune --prod (or pnpm install --prod) before the final image is cut.

🤖 Prompt for AI Agents
In Dockerfile around lines 25 to 28, the production image includes dev
dependencies because node_modules is copied as-is. To fix this, after copying
the application files from the base image, run `pnpm prune --prod` or `pnpm
install --prod` to remove dev dependencies and slim down the final production
image.

EXPOSE 3000

CMD ["pnpm", "start"]
Comment on lines +21 to +31
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

pnpm is missing in the final image – container will not start.

pnpm is installed globally in the base stage, but only /app is copied to prod.
/usr/local/bin/pnpm (and its global store) stay behind, so CMD ["pnpm", "start"] fails.

 FROM node:20-alpine AS prod
 WORKDIR /app
 ENV NODE_ENV=production
-COPY --from=base /app ./
+# Install pnpm again (tiny) or switch to `npm start`
+RUN npm install -g pnpm
+COPY --from=base /app ./

Alternatively change CMD to ["npm", "start"] after adding a --production install step.

🤖 Prompt for AI Agents
In Dockerfile lines 21 to 31, the final prod image lacks the globally installed
pnpm binary because only the /app directory is copied from the base stage,
causing the CMD ["pnpm", "start"] to fail. To fix this, either copy the pnpm
binary and its global store from the base stage into the prod image or replace
the CMD with ["npm", "start"] and add a step to run npm install with the
--production flag in the prod stage to ensure dependencies are installed without
relying on pnpm.

29 changes: 29 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
version: '3.8'

services:
db:
image: postgres:16-alpine
restart: always
environment:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: laminarflow
Comment on lines +7 to +10
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Avoid hard-coding database credentials in version-controlled compose files.

Expose them via an external .env or Docker secrets to reduce accidental leaks and make prod/dev variance easier.

🤖 Prompt for AI Agents
In docker-compose.yml lines 7 to 10, the database credentials are hard-coded
under environment variables. To fix this, remove the hard-coded values and
instead reference environment variables defined in an external .env file or use
Docker secrets. Update the compose file to use variable substitution like
${POSTGRES_USER}, ${POSTGRES_PASSWORD}, and ${POSTGRES_DB} so credentials are
not stored directly in version control and can vary by environment.

volumes:
- db_data:/var/lib/postgresql/data
ports:
- "${DB_PORT:-5432}:5432"

app:
build: .
depends_on:
- db
environment:
DATABASE_URL: postgres://postgres:postgres@db:${DB_PORT:-5432}/laminarflow
NODE_ENV: production
Comment on lines +21 to +22
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Quote the DATABASE_URL to ensure correct variable expansion and YAML parsing.

Colons in unquoted scalars and the ${VAR:-default} expression can lead to subtle parse/expansion issues.

-      DATABASE_URL: postgres://postgres:postgres@db:${DB_PORT:-5432}/laminarflow
+      DATABASE_URL: "postgres://postgres:postgres@db:${DB_PORT:-5432}/laminarflow"
🧰 Tools
🪛 Checkov (3.2.334)

[MEDIUM] 21-22: Basic Auth Credentials

(CKV_SECRET_4)

🤖 Prompt for AI Agents
In docker-compose.yml around lines 21 to 22, the DATABASE_URL value contains
colons and a variable expansion expression that can cause YAML parsing issues.
To fix this, enclose the entire DATABASE_URL string in double quotes to ensure
correct variable expansion and proper YAML parsing.

ports:
- "${PORT:-3000}:3000"
env_file:
- .env

volumes:
db_data:
Loading