diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 00000000..1380c2e7 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,2 @@ +node_modules +.next \ No newline at end of file diff --git a/.env.example b/.env.example index 03efbc11..017e845c 100644 --- a/.env.example +++ b/.env.example @@ -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 # diff --git a/Dockerfile.dev b/Dockerfile.dev new file mode 100644 index 00000000..a159aac7 --- /dev/null +++ b/Dockerfile.dev @@ -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"] \ No newline at end of file diff --git a/README.md b/README.md index d64fa79f..7507d75c 100644 --- a/README.md +++ b/README.md @@ -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 # @@ -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 diff --git a/docker-compose.yaml b/docker-compose.yaml index 7d0f3826..63194e15 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -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 @@ -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 @@ -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: \ No newline at end of file + postgres-data: diff --git a/package.json b/package.json index b4e4a018..0a3800e0 100644 --- a/package.json +++ b/package.json @@ -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}\"",