services:
  webapi:
    build:
      context: .
      dockerfile: ./src/Imprink.WebApi/Dockerfile
    expose:
      - "8080"
    environment:
      - ASPNETCORE_ENVIRONMENT=${ASPNETCORE_ENVIRONMENT}
      - ConnectionStrings__DefaultConnection=Server=${SQL_SERVER};Database=${SQL_DATABASE};User Id=${SQL_USER_ID};Password=${SQL_PASSWORD};Encrypt=false;TrustServerCertificate=true;MultipleActiveResultSets=true;
      - HTTP_PORTS=${ASPNETCORE_HTTP_PORTS}
      - Auth0__Authority=${AUTH0_AUTHORITY}
      - Auth0__Audience=${AUTH0_AUDIENCE}
      - Serilog__SeqUrl=${ASPNETCORE_SEQ_URL}
      - Serilog__MinimumLevel__Default=${ASPNETCORE_LOGGING_LEVEL_DEFAULT}
      - Serilog__MinimumLevel__Override__Microsoft=${ASPNETCORE_LOGGING_LEVEL}
      - Serilog__MinimumLevel__Override__Microsoft.AspNetCore=${ASPNETCORE_LOGGING_LEVEL}
      - Serilog__MinimumLevel__Override__Microsoft.EntityFrameworkCore=${ASPNETCORE_LOGGING_LEVEL_EFCORE}
      - Serilog__MinimumLevel__Override__Imprink=${ASPNETCORE_LOGGING_LEVEL_IMPRINK}
      - Serilog__WriteTo__0__Name=Console
      - Serilog__WriteTo__1__Name=Seq
      - Serilog__WriteTo__1__Args__serverUrl=${ASPNETCORE_SEQ_URL}
      - Serilog__Enrich__0=FromLogContext
      - DatabaseOptions__ApplyMigrationsAtStartup=${ASPNETCORE_APPLY_MIGRATIONS_AT_STARTUP}
    depends_on:
      - mssql
    networks:
      - app-network

  seq:
    image: datalust/seq
    expose:
      - "80"
      - "5341"
    environment:
      - ACCEPT_EULA=Y
      - SEQ_CACHE_SYSTEMRAMTARGET=0.9
      - BASE_URI=${SEQ_BASE_URI}
      - SEQ_FIRSTRUN_NOAUTHENTICATION=true
    networks:
      - app-network

  ui:
    image: node:18-alpine
    working_dir: /app
    volumes:
      - ./ui:/app
      - /app/node_modules
    ports:
      - "3000"
    environment:
      - NODE_ENV=${NODE_ENV}
      - AUTH0_SECRET=${AUTH0_SECRET}
      - APP_BASE_URL=${APP_BASE_URL}
      - AUTH0_DOMAIN=${AUTH0_ISSUER_BASE_URL}
      - AUTH0_CLIENT_ID=${AUTH0_CLIENT_ID}
      - AUTH0_CLIENT_SECRET=${AUTH0_CLIENT_SECRET}
      - AUTH0_AUDIENCE=${AUTH0_AUDIENCE}
      - AUTH0_SCOPE=${AUTH0_SCOPE}
      - COOKIE_DOMAIN=${COOKIE_DOMAIN}
      - NEXT_PUBLIC_API_URL=${NEXT_PUBLIC_API_URL}
      - NEXT_PUBLIC_AUTH0_CLIENT_ID=${NEXT_PUBLIC_AUTH0_CLIENT_ID}
      - NEXT_PUBLIC_AUTH0_DOMAIN=${NEXT_PUBLIC_AUTH0_DOMAIN}
    command: sh -c "npm install && npm run dev"
    networks:
      - app-network

  mssql:
    image: mcr.microsoft.com/mssql/server:2022-latest
    container_name: sqlserver
    tty: false
    stdin_open: false
    ports:
      - "1433:1433"
    environment:
      - SA_PASSWORD=${SQL_PASSWORD}
      - ACCEPT_EULA=Y
      - MSSQL_AGENT_ENABLED=false
    restart: unless-stopped
    networks:
      - app-network
    logging:
      driver: "none"

  nginx:
    image: nginx:latest
    ports:
      - "80:80"
      - "443:443"
    volumes:
      - ./nginx/nginx.conf:/etc/nginx/nginx.conf:ro
      - ./ssl/impr.ink-chain.pem:/etc/ssl/certs/impr.ink.crt:ro
      - ./ssl/impr.ink-key.pem:/etc/ssl/private/impr.ink.key:ro
    depends_on:
      - webapi
      - ui
      - seq
      - upload-server
    networks:
      - app-network

  upload-server:
    build: .
    ports:
      - "3000:3000"
    environment:
      - BASE_URL=${UPLOAD_BASE_URL}
      - HASH_FILENAME=${UPLOAD_HASH_FILENAME}
      - UPLOAD_DIR=${UPLOAD_DIRECTORY}
    volumes:
      - ./uploads:/app/uploads
    networks:
      - app-network

networks:
  app-network:
    driver: bridge

volumes:
  upload_data: