networks:
  default:
    name: penpot_shared
    external: true

volumes:
  postgres_data_pg16:
    name: ${PENPOT_POSTGRES_DATA_VOLUME}
  minio_data:
    name: ${PENPOT_MINIO_DATA_VOLUME}
  valkey_data:
    name: penpotdev_valkey_data

services:
  minio:
    image: "minio/minio:RELEASE.2025-04-03T14-56-28Z"
    command: minio server /mnt/data --console-address ":9001"

    volumes:
      - "minio_data:/mnt/data"

    environment:
      - MINIO_ROOT_USER=minioadmin
      - MINIO_ROOT_PASSWORD=minioadmin

    networks:
      default:
        aliases:
          - minio

  minio-setup:
    image: "minio/mc:latest"
    depends_on:
      - minio
    entrypoint: ["/bin/sh", "-c"]
    command:
      - |
        attempts=0
        until mc alias set penpot-s3 http://minio:9000 minioadmin minioadmin -q; do
          attempts=$$((attempts + 1))
          if [ "$$attempts" -ge 30 ]; then
            echo "minio-setup: gave up waiting for MinIO after $$attempts attempts" >&2
            exit 1
          fi
          sleep 1
        done
        mc admin user info penpot-s3 penpot-devenv >/dev/null 2>&1 || mc admin user add penpot-s3 penpot-devenv penpot-devenv -q
        mc admin policy attach penpot-s3 readwrite --user=penpot-devenv -q
    networks:
      default:

  postgres:
    image: postgres:16.8
    command: postgres -c config_file=/etc/postgresql.conf
    restart: always
    stop_signal: SIGINT
    environment:
      - POSTGRES_INITDB_ARGS=--data-checksums
      - POSTGRES_DB=penpot
      - POSTGRES_USER=penpot
      - POSTGRES_PASSWORD=penpot
    volumes:
      - ./files/postgresql.conf:/etc/postgresql.conf:z
      - ./files/postgresql_init.sql:/docker-entrypoint-initdb.d/init.sql:z
      - postgres_data_pg16:/var/lib/postgresql/data
    networks:
      default:
        aliases:
          - postgres

  valkey:
    image: valkey/valkey:8.1
    restart: always
    command: valkey-server --save 120 1 --loglevel warning
    volumes:
      - "valkey_data:/data"
    networks:
      default:
        aliases:
          - valkey

  mailer:
    image: sj26/mailcatcher:latest
    restart: always
    expose:
      - '1025'
    ports:
      - "1080:1080"

    networks:
      default:
        aliases:
          - mailer

  # https://github.com/rroemhild/docker-test-openldap
  ldap:
    image: rroemhild/test-openldap:2.1
    expose:
      - '10389'
      - '10636'
    ports:
      - "10389:10389"
      - "10636:10636"
    ulimits:
      nofile:
        soft: 1024
        hard: 1024

    networks:
      default:
        aliases:
          - ldap
