version: "3.9"
services:
  postgres:
    image: postgres:latest
    container_name: twitter_postgres
    ports:
      - "5432:5432"
    environment:
      - POSTGRES_USER=sukhjinder_psql
      - POSTGRES_PASSWORD=password
      - POSTGRES_DB=twitterdb
      - PGDATA=/var/lib/postgresql/data/
    volumes:
      - pgdata:/var/lib/postgresql/data
    restart: unless-stopped

  pgadmin:
    image: dpage/pgadmin4
    container_name: pgadmin
    depends_on:
      - postgres
    ports:
      - "8080:80"
    environment:
      - PGADMIN_DEFAULT_EMAIL=pgadmin4@pgadmin.org
      - PGADMIN_DEFAULT_PASSWORD=admin
    volumes:
      - pgadmin-data:/var/lib/pgadmin
    restart: unless-stopped

  api:
    build:
      context: ./api
      dockerfile: Dockerfile
    container_name: twitter_clone_api
    entrypoint: ["/bin/bash", "./startup.sh"]
    volumes:
      - ./api:/home/node/app
      - ./api/prisma:/home/node/app/prisma
      - /home/node/app/node_modules
    depends_on:
      - postgres
    ports:
      - "5000:5000"
      - "5555:5555"
    command: npm run dev
    restart: always

  client:
    build:
      context: ./client
      dockerfile: Dockerfile
    container_name: twitter_clone_client
    volumes:
      - ./client:/home/node/app
      - /home/node/app/node_modules
    ports:
      - "3000:3000"
    stdin_open: true
    tty: true
    depends_on:
      - api

volumes:
  pgdata:
  pgadmin-data:
