Skip to content

Commit 215f936

Browse files
committed
feat: containerize application using docker and docker compose
1 parent 54579d4 commit 215f936

File tree

3 files changed

+115
-0
lines changed

3 files changed

+115
-0
lines changed

Diff for: .dockerignore

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
node_modules
2+
Dockerfile
3+
compose.yaml

Diff for: Dockerfile

+68
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
ARG NODE_VERSION=22.12.0
2+
ARG PNPM_VERSION=9.15.2
3+
ARG ALPINE_VERSION=3.21
4+
5+
# STAGE: Base
6+
FROM node:${NODE_VERSION}-alpine${ALPINE_VERSION} AS base
7+
WORKDIR /usr/local/app
8+
RUN --mount=type=cache,target=/root/.npm \
9+
npm install -g pnpm@${PNPM_VERSION}
10+
11+
12+
######## CLIENT STAGES #########
13+
14+
# STAGE: CLIENT BASE
15+
FROM base AS client-base
16+
COPY web/package.json web/pnpm-lock.yaml web/favicon.ico web/index.html web/tsconfig.json web/tsconfig.node.json web/vercel.json web/vite.config.ts web/tailwind.config.js web/postcss.config.js ./
17+
RUN --mount=type=cache,id=pnpm,target=/usr/local/share/.cache/pnpm \
18+
pnpm install
19+
COPY web/public ./public
20+
COPY web/src ./src
21+
22+
23+
# STAGE: Client/Web Dev
24+
FROM client-base AS client-dev
25+
CMD ["pnpm", "dev"]
26+
27+
28+
# STAGE: Client production build
29+
FROM client-base AS client-build
30+
RUN pnpm build
31+
32+
33+
######## BACKEND STAGES #########
34+
35+
# STAGE: Backend base
36+
FROM base AS backend-base
37+
COPY api/package.json api/pnpm-lock.yaml ./
38+
RUN --mount=type=cache,id=pnpm,target=/usr/local/share/.cache/pnpm \
39+
pnpm install
40+
COPY api/node_modules ./node_modules
41+
COPY api/ .
42+
43+
44+
# STAGE: Backend Dev
45+
FROM backend-base AS backend-dev
46+
CMD ["pnpm", "dev"]
47+
48+
49+
# STAGE: Backend Test
50+
FROM backend-base AS backend-test
51+
CMD ["pnpm", "test"]
52+
53+
54+
# STAGE: Backend Build
55+
FROM backend-base AS backend-build
56+
RUN pnpm build
57+
58+
59+
# STAGE: Production
60+
FROM base AS production
61+
ENV NODE_ENV=production
62+
COPY --from=backend-build /usr/local/app/package.json /usr/local/app/pnpm-lock.yaml ./
63+
RUN --mount=type=cache,id=pnpm,target=/usr/local/share/.cache/pnpm \
64+
pnpm install --prod
65+
COPY --from=backend-build /usr/local/app/dist ./dist/api
66+
COPY --from=client-build /usr/local/app/dist ./dist/client
67+
EXPOSE 8000
68+
CMD ["node", "dist/api/app.js"]

Diff for: compose.yaml

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
services:
2+
proxy:
3+
image: traefik:v2.12.1
4+
command: --providers.docker
5+
ports:
6+
- 80:80
7+
volumes:
8+
- /var/run/docker.sock:/var/run/docker.sock
9+
10+
backend:
11+
container_name: reo-backend-v${TAG}
12+
build:
13+
context: ./
14+
target: backend-dev
15+
env_file:
16+
- .env
17+
develop:
18+
watch:
19+
- path: ./api/
20+
action: sync
21+
target: /usr/local/app/api
22+
- path: ./api/package.json
23+
action: rebuild
24+
labels:
25+
traefik.http.routers.backend.rule: Host(`localhost`) && PathPrefix(`/api`)
26+
traefik.http.services.backend.loadbalancer.server.port: 8000
27+
28+
client:
29+
container_name: reo-client-v${TAG}
30+
build:
31+
context: ./
32+
target: client-dev
33+
env_file:
34+
- .env
35+
develop:
36+
watch:
37+
- path: ./web/src
38+
action: sync
39+
target: /usr/local/app/src
40+
- path: ./web/package.json
41+
action: rebuild
42+
labels:
43+
traefik.http.routers.client.rule: Host(`localhost`)
44+
traefik.http.services.client.loadbalancer.server.port: 5050

0 commit comments

Comments
 (0)