From 05b056c804754c6bbf1a6090748868e1f654db8b Mon Sep 17 00:00:00 2001 From: rizzOn Date: Wed, 3 Dec 2025 22:57:47 +0530 Subject: [PATCH] chore(postgres_db): Relocated database files to outside backend, init DockerFile, expand docker-compose This commit relocates the database files to outside the backend folder, to the root aurganize folder. - we initialise the backend Dockerfile.dev - we expand the docker-compose to migrate our backend to docker This improves developer experience and standardizes database operations for the entire backend team. Story: E1-004 - PostgreSQL Database Setup --- backend/DockerFile.dev | 33 ++++ .../migrations/000001_initial_schema.down.sql | 0 .../migrations/000001_initial_schema.up.sql | 0 .../scripts/backup_db.sh | 0 .../scripts/configure-postgres.sh | 0 .../database => database}/scripts/dev_seed.sh | 0 .../scripts/health_check.sh | 0 .../database => database}/scripts/migrate.sh | 0 .../scripts/restore_db.sh | 0 .../database => database}/scripts/test_ops.sh | 0 .../seeds/001_dev_data.sql | 0 .../tests/health_check.sql | 0 .../tests/test_operations.sql | 0 infrastructure/docker/docker-compose.yml | 148 +++++++++++++++++- 14 files changed, 180 insertions(+), 1 deletion(-) create mode 100644 backend/DockerFile.dev rename {backend/database => database}/migrations/000001_initial_schema.down.sql (100%) rename {backend/database => database}/migrations/000001_initial_schema.up.sql (100%) rename {backend/database => database}/scripts/backup_db.sh (100%) rename {backend/database => database}/scripts/configure-postgres.sh (100%) rename {backend/database => database}/scripts/dev_seed.sh (100%) rename {backend/database => database}/scripts/health_check.sh (100%) rename {backend/database => database}/scripts/migrate.sh (100%) rename {backend/database => database}/scripts/restore_db.sh (100%) rename {backend/database => database}/scripts/test_ops.sh (100%) rename {backend/database => database}/seeds/001_dev_data.sql (100%) rename {backend/database => database}/tests/health_check.sql (100%) rename {backend/database => database}/tests/test_operations.sql (100%) diff --git a/backend/DockerFile.dev b/backend/DockerFile.dev new file mode 100644 index 0000000..d0dcde2 --- /dev/null +++ b/backend/DockerFile.dev @@ -0,0 +1,33 @@ +# backend/Dockerfile.dev +# Development Dockerfile with hot reload support + +# Stage 1: Base image with Go tools +FROM golang:1.21-alpine AS base + +# Install developement tools +# - git: Required for go get +# - gcc, musl-dev: Required for CGO (some packages need C compiler) +# - air: Hot reload tool for GO +RUN apk add --no-cache \ + git \ + gcc \ + musl-dev && \ + go install github.com/air-verse/air@latest + + +# Set working directory +WORKDIR /app + +# Stage 2: Development environment +FROM base as development + +# Copy dependency files first (for layer caching) +COPY go.mod go.sum./ + +# Download dependencies +# This layer is cached unless go.mod or go.sum changes +RUN go mod download + +# Copy Air configuration + +COPY .air.t \ No newline at end of file diff --git a/backend/database/migrations/000001_initial_schema.down.sql b/database/migrations/000001_initial_schema.down.sql similarity index 100% rename from backend/database/migrations/000001_initial_schema.down.sql rename to database/migrations/000001_initial_schema.down.sql diff --git a/backend/database/migrations/000001_initial_schema.up.sql b/database/migrations/000001_initial_schema.up.sql similarity index 100% rename from backend/database/migrations/000001_initial_schema.up.sql rename to database/migrations/000001_initial_schema.up.sql diff --git a/backend/database/scripts/backup_db.sh b/database/scripts/backup_db.sh similarity index 100% rename from backend/database/scripts/backup_db.sh rename to database/scripts/backup_db.sh diff --git a/backend/database/scripts/configure-postgres.sh b/database/scripts/configure-postgres.sh similarity index 100% rename from backend/database/scripts/configure-postgres.sh rename to database/scripts/configure-postgres.sh diff --git a/backend/database/scripts/dev_seed.sh b/database/scripts/dev_seed.sh similarity index 100% rename from backend/database/scripts/dev_seed.sh rename to database/scripts/dev_seed.sh diff --git a/backend/database/scripts/health_check.sh b/database/scripts/health_check.sh similarity index 100% rename from backend/database/scripts/health_check.sh rename to database/scripts/health_check.sh diff --git a/backend/database/scripts/migrate.sh b/database/scripts/migrate.sh similarity index 100% rename from backend/database/scripts/migrate.sh rename to database/scripts/migrate.sh diff --git a/backend/database/scripts/restore_db.sh b/database/scripts/restore_db.sh similarity index 100% rename from backend/database/scripts/restore_db.sh rename to database/scripts/restore_db.sh diff --git a/backend/database/scripts/test_ops.sh b/database/scripts/test_ops.sh similarity index 100% rename from backend/database/scripts/test_ops.sh rename to database/scripts/test_ops.sh diff --git a/backend/database/seeds/001_dev_data.sql b/database/seeds/001_dev_data.sql similarity index 100% rename from backend/database/seeds/001_dev_data.sql rename to database/seeds/001_dev_data.sql diff --git a/backend/database/tests/health_check.sql b/database/tests/health_check.sql similarity index 100% rename from backend/database/tests/health_check.sql rename to database/tests/health_check.sql diff --git a/backend/database/tests/test_operations.sql b/database/tests/test_operations.sql similarity index 100% rename from backend/database/tests/test_operations.sql rename to database/tests/test_operations.sql diff --git a/infrastructure/docker/docker-compose.yml b/infrastructure/docker/docker-compose.yml index 8a1940f..9720c76 100644 --- a/infrastructure/docker/docker-compose.yml +++ b/infrastructure/docker/docker-compose.yml @@ -1,6 +1,10 @@ +# docker-compose.yml version: '3.8' +# Define all services that make up Aurganize services: + + # PostgreSQL 14 - Primary database postgres: image: postgres:14-alpine container_name: aurganize-postgres @@ -21,5 +25,147 @@ services: timeout: 5s retries: 5 + networks: + - aurganize-network + + # Redis 7 - Caching and session storage + redis: + image: redis:7-alpine + container_name: aurganize-redis + restart: unless-stopped + command: redis-server --appendonly yes + ports: + - "6379:6379" + volumes: + - redis_data:/data + healthcheck: + test: ["CMD", "redis-cli", "ping"] + interval: 10s + timeout: 5s + retries: 5 + networks: + - aurganize-network + + # NATS with JetStream - Event bus + nats: + image: nats:latest + container_name: aurganize-nats + restart: unless-stopped + command: ["-js", "-m", "8222"] + ports: + - "4222:4222" # Client connections + - "8222:8222" # HTTP monitoring + volumes: + - nats_data:/data + healthcheck: + test: ["CMD", "wget", "--spider", "-q", "http://localhost:8222/healthz"] + interval: 10s + timeout: 5s + retries: 5 + networks: + - aurganize-network + + # MinIO - S3-compatible object storage + minio: + image: minio/minio:latest + container_name: aurganize-minio + restart: unless-stopped + command: server /data --console-address ":9001" + environment: + MINIO_ROOT_USER: minioadmin + MINIO_ROOT_PASSWORD: minioadmin + ports: + - "9000:9000" # API + - "9001:9001" # Web Console + volumes: + - minio_data:/data + healthcheck: + test: ["CMD", "curl", "-f", "http://localhost:9000/minio/health/live"] + interval: 10s + timeout: 5s + retries: 5 + networks: + - aurganize-network + + # Backend - Go API server + backend: + build: + context: ./../../backend + dockerfile: Dockerfile.dev + container_name: aurganize-backend + restart: unless-stopped + environment: + # Application config + ENV: development + PORT: 8080 + + # Database connection + DB_HOST: postgres + DB_PORT: 5432 + DB_USER: aurganize + DB_PASSWORD: dev_password_change_in_prod + DB_NAME: aurganize + DB_SSL_MODE: disable + + # Redis connection + REDIS_HOST: redis + REDIS_PORT: 6379 + REDIS_PASSWORD: "" + + # NATS connection + NATS_URL: nats://nats:4222 + + # MinIO connection + MINIO_ENDPOINT: minio:9000 + MINIO_ACCESS_KEY: minioadmin + MINIO_SECRET_KEY: minioadmin + MINIO_USE_SSL: false + + # JWT secrets (development only) + JWT_SECRET: dev-secret-change-in-production + + # CORS settings + CORS_ORIGINS: http://localhost:3000 + ports: + - "8080:8080" + volumes: + # Mount source code for hot reload + - ./backend:/app + # Exclude node_modules and vendor + - /app/vendor + - /app/bin + depends_on: + postgres: + condition: service_healthy + redis: + condition: service_healthy + nats: + condition: service_healthy + minio: + condition: service_healthy + healthcheck: + test: ["CMD", "wget", "--spider", "-q", "http://localhost:8080/health"] + interval: 10s + timeout: 5s + retries: 5 + networks: + - aurganize-network + + # Frontend - React application + # TODO + +# Named volumes for data persistence volumes: - postgres_data: \ No newline at end of file + postgres_data: + driver: local + redis_data: + driver: local + nats_data: + driver: local + minio_data: + driver: local + +# Custom network for service isolation +networks: + aurganize-network: + driver: bridge \ No newline at end of file