Skip to content

Commit

Permalink
Support compose watch
Browse files Browse the repository at this point in the history
  • Loading branch information
reckseba committed May 4, 2024
1 parent 9c058ef commit cd61ff5
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 10 deletions.
27 changes: 24 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
FROM node:21-alpine AS base

######################################################################################
# 1. Install dependencies only when needed
FROM base AS deps
# 1. Install prod dependencies only when needed
FROM base AS proddeps

# No Dev-Dependencies
ENV NODE_ENV=production
Expand All @@ -22,7 +22,7 @@ FROM base AS builder
WORKDIR /app
COPY components ./components
COPY lib ./lib
COPY --from=deps /app/node_modules ./node_modules
COPY --from=proddeps /app/node_modules ./node_modules
COPY pages ./pages
COPY public ./public
COPY styles ./styles
Expand Down Expand Up @@ -53,3 +53,24 @@ EXPOSE 3001
ENV PORT 3001

CMD ["node", "server.js"]

######################################################################################
# Development
FROM base AS dev

# Check https://github.com/nodejs/docker-node/tree/b4117f9333da4138b03a546ec926ef50a31506c3#nodealpine to understand why libc6-compat might be needed.
RUN apk add --no-cache libc6-compat

WORKDIR /app

RUN addgroup -g 1001 -S nodejs
RUN adduser -S nodejs -u 1001

COPY --chown=nodejs:nodejs components ./components
COPY --chown=nodejs:nodejs lib ./lib
COPY --chown=nodejs:nodejs pages ./pages
COPY --chown=nodejs:nodejs public ./public
COPY --chown=nodejs:nodejs styles ./styles
COPY --chown=nodejs:nodejs .eslintrc.json next.config.js package-lock.json package.json postcss.config.js tailwind.config.js tsconfig.json ./

RUN npm ci
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ cd 2a5-app
npm install
```

Run the nodejs development server:
Run the nodejs development server (It supports hot reload):
```bash
npm run dev
```
Expand All @@ -37,12 +37,12 @@ Stop it with CTRL+C

# Run with Docker

The container will join the existing 2a5 network
The container will join the existing 2a5 network (It supports hot reload):
```bash
docker compose up -d
docker compose up --build --watch
```

Stop it:
Stop it by ctrl+c or if detached:
```bash
docker compose down
```
Expand Down
24 changes: 21 additions & 3 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
version: "3"
services:

app:
build:
context: .
dockerfile: Dockerfile
target: runner
target: dev
hostname: 2a5-app-development
image: 2a5-app-development
ports:
- "3001:3001"
container_name: 2a5-app-development
Expand All @@ -16,6 +14,26 @@ services:
- DOCKER_API_PORT=3000
networks:
- 2a5-extern
command: npm run dev
develop:
watch:
- action: sync
path: ./components
target: /app/components
- action: sync
path: ./lib
target: /app/lib
- action: sync
path: ./pages
target: /app/pages
- action: sync
path: ./public
target: /app/public
- action: sync
path: ./styles
target: /app/styles
- action: rebuild
path: package.json

networks:
2a5-extern:
Expand Down

0 comments on commit cd61ff5

Please sign in to comment.