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
42 changes: 37 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,13 +1,45 @@
FROM node:18-alpine
# syntax=docker/dockerfile:1

WORKDIR /usr/src/app
ARG NODE_VERSION=18
ARG NODE_ENV=development
Comment on lines +3 to +4
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

As you mentioned, you're not a docker person, I will note these are defaults and can be overridden. Thus why when NODE_EVN is production on your production server it'll switch to that.

I assumed that is how production works given the code has a section banking on NODE_ENV via env for URL to be either d2jam or localhost.


# --- Base Stage ---
FROM node:${NODE_VERSION}-alpine as base
WORKDIR /usr/src/app
# Install common dependencies (e.g. PostgreSQL client)
RUN apk add --no-cache postgresql-client
EXPOSE 3005

COPY package*.json ./
RUN npm install
# --- Dependencies Stage ---
FROM base as deps
# Copy package files first to leverage caching
COPY package.json package-lock.json ./

# Use cache mount for npm downloads; conditionally install based on NODE_ENV
RUN --mount=type=cache,target=/root/.npm \
if [ "$NODE_ENV" = "production" ]; then \
npm ci --omit=dev; \
else \
npm ci --include=dev; \
fi

# --- Builder Stage ---
FROM deps as builder
# Copy the rest of the application code
COPY . .
# Generate Prisma client (or other build steps)
RUN npx prisma generate

EXPOSE 3005
# --- Development Final Stage ---
FROM base as dev

COPY --from=builder /usr/src/app ./

CMD ["npm", "run", "dev"]

# --- Production Final Stage ---
FROM base as production

COPY --from=builder /usr/src/app ./

CMD ["node", "index.js"]
5 changes: 4 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ services:
- postgres_data:/var/lib/postgresql/data/

jamcore:
build: .
build:
context: .
dockerfile: Dockerfile
target: ${NODE_ENV:-dev}
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

This is default behavior. Use NODE_ENV if it is defined, else use dev

environment:
DATABASE_URL: "postgresql://${POSTGRES_USER}:${POSTGRES_PASSWORD}@postgres:5432/${POSTGRES_DB}"
ports:
Expand Down