From afef1de4ead6ab7a0e15e4f048d17cbc45a1113f Mon Sep 17 00:00:00 2001 From: NteinPrecious Date: Tue, 16 Jun 2026 15:40:55 +0100 Subject: [PATCH] feat(docker): add Docker Compose for local development with PostGIS Closes #91 --- Backend/Dockerfile.dev | 7 ++++ docker-compose.yml | 45 ++++++++++++++++++++++++ infrastructure/docker/docker-compose.yml | 17 +++++---- infrastructure/docker/postgres-init.sql | 2 ++ 4 files changed, 64 insertions(+), 7 deletions(-) create mode 100644 Backend/Dockerfile.dev create mode 100644 docker-compose.yml diff --git a/Backend/Dockerfile.dev b/Backend/Dockerfile.dev new file mode 100644 index 00000000..cfe3c233 --- /dev/null +++ b/Backend/Dockerfile.dev @@ -0,0 +1,7 @@ +FROM node:20-alpine +WORKDIR /app +COPY package*.json ./ +RUN npm install +COPY . . +EXPOSE 3000 +CMD ["npm", "run", "start:dev"] diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 00000000..8e5b0e2f --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,45 @@ +version: "3.9" + +services: + postgres: + image: postgis/postgis:16-3.4-alpine + environment: + POSTGRES_USER: gistpin + POSTGRES_PASSWORD: gistpin + POSTGRES_DB: gistpin + ports: + - "5432:5432" + volumes: + - postgres_data:/var/lib/postgresql/data + - ./infrastructure/docker/postgres-init.sql:/docker-entrypoint-initdb.d/01-init.sql:ro + healthcheck: + test: ["CMD-SHELL", "pg_isready -U gistpin -d gistpin"] + interval: 10s + timeout: 5s + retries: 5 + start_period: 20s + + backend: + build: + context: ./Backend + dockerfile: Dockerfile.dev + ports: + - "3000:3000" + env_file: + - ./Backend/.env + environment: + NODE_ENV: development + DATABASE_HOST: postgres + DATABASE_PORT: "5432" + DATABASE_USER: gistpin + DATABASE_PASSWORD: gistpin + DATABASE_NAME: gistpin + volumes: + - ./Backend:/app + - /app/node_modules + depends_on: + postgres: + condition: service_healthy + +volumes: + postgres_data: diff --git a/infrastructure/docker/docker-compose.yml b/infrastructure/docker/docker-compose.yml index 0ffd438e..9ef2a2da 100644 --- a/infrastructure/docker/docker-compose.yml +++ b/infrastructure/docker/docker-compose.yml @@ -7,14 +7,15 @@ services: dockerfile: ../infrastructure/docker/backend.Dockerfile ports: ["3000:3000"] environment: - NODE_ENV: development - DATABASE_URL: postgresql://gistpin:gistpin@postgres:5432/gistpin + NODE_ENV: production + DATABASE_HOST: postgres + DATABASE_PORT: "5432" + DATABASE_USER: gistpin + DATABASE_PASSWORD: gistpin + DATABASE_NAME: gistpin depends_on: postgres: condition: service_healthy - volumes: - - ../../Backend:/app - - /app/node_modules frontend: build: @@ -24,19 +25,21 @@ services: depends_on: [backend] postgres: - image: postgres:16-alpine + image: postgis/postgis:16-3.4-alpine environment: POSTGRES_USER: gistpin POSTGRES_PASSWORD: gistpin POSTGRES_DB: gistpin ports: ["5432:5432"] healthcheck: - test: ["CMD-SHELL", "pg_isready -U gistpin"] + test: ["CMD-SHELL", "pg_isready -U gistpin -d gistpin"] interval: 10s timeout: 5s retries: 5 + start_period: 20s volumes: - postgres_data:/var/lib/postgresql/data + - ./postgres-init.sql:/docker-entrypoint-initdb.d/01-init.sql:ro volumes: postgres_data: diff --git a/infrastructure/docker/postgres-init.sql b/infrastructure/docker/postgres-init.sql index ddb70606..068d4cfd 100644 --- a/infrastructure/docker/postgres-init.sql +++ b/infrastructure/docker/postgres-init.sql @@ -1,3 +1,5 @@ -- GistPin database bootstrap +CREATE EXTENSION IF NOT EXISTS postgis; +CREATE EXTENSION IF NOT EXISTS postgis_topology; CREATE EXTENSION IF NOT EXISTS "uuid-ossp"; CREATE EXTENSION IF NOT EXISTS "pg_stat_statements";