version: '3.9'

services:
  # Uses base image from node and maps local needed files to the container
  backend:
    build:
      context: .
      dockerfile: Dockerfile
      target: development
    container_name: ${CONTAINER_BACK_NAME} # This is the name of the container
    image: multisig-back:latest # This is the name of the image that will be created
    restart: unless-stopped
    volumes:
      - .:/app
      # This ensures that the NestJS container manages the node_modules folder
      # rather than synchronizes it with the host machine
      - /app/node_modules
      - log:/var/lib/logs
    ports:
      - '${SERVER_PORT}:${SERVER_PORT}'
    networks:
      - default-network
    environment:
      - NODE_ENV=development
      - SERVER_HOST=${SERVER_HOST}
      - SERVER_PORT=${SERVER_PORT}
      - DB_HOST=${DB_HOST}
      - DB_PORT=${DB_PORT}
      - DB_USER=${DB_USER}
      - DB_PASSWORD=${DB_PASSWORD}
    depends_on:
      - ${CONTAINER_DB_NAME}
    command: npx nest start --watch

  db:
    image: postgres:14.11-alpine3.19
    container_name: ${CONTAINER_DB_NAME}
    restart: unless-stopped
    environment:
      - POSTGRES_USER=${DB_USER}
      - POSTGRES_PASSWORD=${DB_PASSWORD}
    ports:
      - '${DB_PORT}:${DB_PORT}'
    networks:
      - default-network
    volumes:
      - db:/var/lib/postgresql/data

volumes:
  db:
  log:
    driver: local

networks:
  default-network:
    name: ${DOCKER_NETWORK_NAME}
