Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dockerize app #79

Merged
merged 8 commits into from
May 26, 2023
Merged
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
27 changes: 27 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
FROM node:18-alpine AS builder

WORKDIR /app

COPY package*.json /app/

RUN npm ci

COPY . .

kareemmahlees marked this conversation as resolved.
Show resolved Hide resolved
ENV NODE_BUILD=true

RUN npm run build

EXPOSE 3000

CMD node build

FROM node:18-alpine as production
Copy link
Member

Choose a reason for hiding this comment

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

Is there a reason to split the build and run into separate containers?

Copy link
Collaborator

Choose a reason for hiding this comment

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

To limit the image size?

Copy link
Member

Choose a reason for hiding this comment

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

Ok seems fine then, but does there need to be an EXPOSE and CMD for the first stage? Isn't it needed for only the second container?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yeah, @kareemmahlees just remove the EXPOSE and CMD node build from the build stage.


COPY --from=builder ./build .

ENV NODE_ENV=production

EXPOSE 3000

CMD node ./build
19 changes: 19 additions & 0 deletions docker-compose.prod.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
version: '3.1'
services:
app:
build:
dockerfile: Dockerfile
target: production
restart: always
ports:
- 5173:5173
environment:
- AUTH_SECRET=${AUTH_SECRET}
- GOOGLE_CLIENT_ID=${GOOGLE_CLIENT_ID}
- GOOGLE_CLIENT_SECRET=${GOOGLE_CLIENT_SECRET}
- DB_HOST=${DB_HOST}
- DB_USER=${DB_USER}
- DB_PASSWORD=${DB_PASSWORD}
- DB_NAME=${DB_NAME}
- DB_PORT=${DB_PORT}
- DATABASE_URL=${DATABASE_URL}