From 3db87453b52d533b3706f2510b2d4043df8b0879 Mon Sep 17 00:00:00 2001 From: Dillion Verma Date: Mon, 18 Mar 2024 12:57:22 -0400 Subject: [PATCH] feat: add local docker compose --- dev.Dockerfile | 32 ++++++++++++++++++++++++++++++++ docker-compose.yml | 40 ++++++++++++++++++++++++++++++++-------- 2 files changed, 64 insertions(+), 8 deletions(-) create mode 100644 dev.Dockerfile diff --git a/dev.Dockerfile b/dev.Dockerfile new file mode 100644 index 000000000..16eabcbf3 --- /dev/null +++ b/dev.Dockerfile @@ -0,0 +1,32 @@ +FROM node:20-alpine + +WORKDIR /app + +# Install dependencies based on the preferred package manager +COPY package.json yarn.lock* package-lock.json* pnpm-lock.yaml* ./ +RUN \ + if [ -f yarn.lock ]; then yarn --frozen-lockfile; \ + elif [ -f package-lock.json ]; then npm ci; \ + elif [ -f pnpm-lock.yaml ]; then corepack enable pnpm && pnpm i; \ + # Allow install without lockfile, so example works even without Node.js installed locally + else echo "Warning: Lockfile not found. It is recommended to commit lockfiles to version control." && yarn install; \ + fi + +COPY src ./src +COPY public ./public +COPY next.config.js . +COPY tsconfig.json . + +# Next.js collects completely anonymous telemetry data about general usage. Learn more here: https://nextjs.org/telemetry +# Uncomment the following line to disable telemetry at run time +# ENV NEXT_TELEMETRY_DISABLED 1 + +# Note: Don't expose ports here, Compose will handle that for us + +# Start Next.js in development mode based on the preferred package manager +CMD \ + if [ -f yarn.lock ]; then yarn dev; \ + elif [ -f package-lock.json ]; then npm run dev; \ + elif [ -f pnpm-lock.yaml ]; then pnpm dev; \ + else npm run dev; \ + fi \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index 5fa38ad7d..a69b672f7 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -5,20 +5,44 @@ version: "3.7" # docker-compose up -d # +# https://github.com/vercel/next.js/blob/canary/examples/with-docker-compose/docker-compose.dev.yml + services: - default_database: + web: + build: + context: . + dockerfile: dev.Dockerfile + volumes: + - ./src:/app/src + - ./public:/app/public + ports: + - "3000:3000" + environment: + - DATABASE_URL=postgres://postgres:postgres@localhost:5432/postgres + env_file: + - .env.local + restart: always + + + database: restart: unless-stopped image: postgres:latest volumes: - - default_database_data:/var/lib/postgresql/data + - database_data:/var/lib/postgresql/data environment: - - POSTGRES_DB=${DEFAULT_DATABASE_DB} - - POSTGRES_USER=${DEFAULT_DATABASE_USER} - - POSTGRES_PASSWORD=${DEFAULT_DATABASE_PASSWORD} + - POSTGRES_DB=postgres + - POSTGRES_USER=postgres + - POSTGRES_PASSWORD=postgres env_file: - - .env + - .env.local ports: - - "${DEFAULT_DATABASE_PORT}:5432" + - "5432:5432" + networks: + - my_network volumes: - default_database_data: + database_data: + +networks: + my_network: + external: true \ No newline at end of file