version: '3.8'
services:

  nginx:
    image: nginx:latest
    container_name: "nginx"
    volumes:
      -  /tmp/uploads:/data
      - ./nginx.conf:/etc/nginx/conf.d/default.conf
    ports:
      - '80:80'
    depends_on:
      - dev

  postgres:
    container_name: "postgres"
    image: postgres:13
    healthcheck:
      test: [ "CMD-SHELL", "pg_isready -U postgres" ]
      interval: 10s
      timeout: 5s
      retries: 5
    ports:
      - "5432:${DB_PORT}"
    env_file:
      - .env
    environment:
      - POSTGRES_USER=$DB_USER
      - POSTGRES_PASSWORD=$DB_PASSWORD
      - POSTGRES_DB=$DB_NAME
    volumes:
      - postgres:/var/lib/postgresql/data

  dev:
    container_name: "csm-brand-portal-back"
    build:
      dockerfile: Dockerfile.dev
      context: .
    env_file:
      - .env
    restart: always
    environment:
      HOST: '0.0.0.0'
      DB_HOST: "postgres"
    depends_on:
      postgres:
        condition: service_healthy
    volumes:
      - '/app/node_modules'
      - .:/app
      - /tmp:/tmp
    ports:
      - '4000:4000'
    expose:
      - "4000"
    command: "sh -c 'bin/wait-for.sh postgres:5432 -- npm run clean-db:static && npm run dev'"

volumes:
  postgres:
    name: csm-portal-back
