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

Feat: added docker file for dev environment with hot reloading #534

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
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
2 changes: 2 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules
.next
4 changes: 4 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
# Database
#
DATABASE_URL="postgres://postgres:password@localhost:5432/postgres"
#
# Use Below if you are using docker
# DATABASE_URL="postgresql://postgres:postgres@job-board-db:5432/job-board-db"
# POSTGRES_URL="postgresql://postgres:postgres@job-board-db:5432/job-board-db"
#
# AUTH
#
Expand Down
15 changes: 15 additions & 0 deletions Dockerfile.dev
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
FROM node:20-alpine AS base
WORKDIR /app
COPY package*.json ./

FROM base AS development-dependencies
RUN npm ci
COPY prisma ./prisma
RUN npx prisma generate

FROM base AS development
COPY --from=development-dependencies /app/node_modules ./node_modules
COPY . .

EXPOSE 3000
CMD ["npm", "run", "dev:docker"]
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ Follow these steps to set up the repository locally and run it.
# Database
#
DATABASE_URL="postgres://postgres:password@localhost:5432/postgres"

#
# Use Below if you are using docker
# DATABASE_URL="postgresql://postgres:postgres@job-board-db:5432/job-board-db"
#
# AUTH
#
Expand Down Expand Up @@ -86,7 +88,7 @@ Follow these steps to set up the repository locally and run it.
### Running the Project with Docker

```bash
docker compose up --build
docker compose up --watch
```

### Running the Project without Docker
Expand Down
23 changes: 16 additions & 7 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -1,17 +1,26 @@
services:
app:
build:
dockerfile: Dockerfile
dockerfile: Dockerfile.dev
target: development # Change this to production for prod builds (WIP)
container_name: job-board-app
environment:
- DATABASE_URL=$DATABASE_URL
- AUTH_SECRET=$AUTH_SECRET
- CHOKIDAR_USEPOLLING=true
env_file:
- ./.env
ports:
- "3000:3000"
volumes:
- .:/usr/src/app
- /usr/src/app/node_modules
develop:
watch:
- action: sync
path: ./src
target: /app/src
ignore:
- node_modules
- action: rebuild
path: ./package.json
depends_on:
db:
condition: service_healthy
Expand All @@ -29,7 +38,7 @@ services:
volumes:
- postgres-data:/var/lib/postgresql/data
healthcheck:
test: ["CMD-SHELL", "pg_isready -d $${POSTGRES_DB} -U $${POSTGRES_USER}"]
test: [ "CMD-SHELL", "pg_isready -d $${POSTGRES_DB} -U $${POSTGRES_USER}" ]
interval: 10s
timeout: 5s
retries: 5
Expand All @@ -39,11 +48,11 @@ services:
image: timothyjmiller/prisma-studio:latest
restart: unless-stopped
env_file:
- .env
- ./.env
depends_on:
- app
ports:
- 5555:5555

volumes:
postgres-data:
postgres-data:
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"build": "next build",
"start": "next start",
"lint": "next lint",
"dev:docker": "npm run db:seed & next dev",
"dev:docker": "npm run db:seed && next dev",
"db:seed": "npx prisma db push && node --loader ts-node/esm prisma/seed.ts",
"db:studio": "npx prisma studio",
"check": "prettier --check \"**/*.{ts,tsx,js,jsx,md,mdx,css}\"",
Expand Down
Loading