version: "3"

networks:
  default:
    driver: bridge
    ipam:
      config:
        - subnet: 172.177.9.0/24

volumes:
  postgres_data_pg15:
  user_data:
  minio_data:
  redis_data:

services:
  main:
    privileged: true
    image: "penpotapp/devenv:latest"
    build:
      context: "."
    container_name: "penpot-devenv-main"
    stop_signal: SIGINT

    depends_on:
      - postgres
      - redis
      # - keycloak

    volumes:
      - "user_data:/home/penpot/"
      - "${PWD}:/home/penpot/penpot:z"

    ports:
      - 3447:3447
      - 3448:3448
      - 3449:3449
      - 6006:6006
      - 6060:6060
      - 6061:6061
      - 6062:6062
      - 6063:6063
      - 6064:6064
      - 9090:9090

    environment:
      - EXTERNAL_UID=${CURRENT_USER_ID}
      - PENPOT_SECRET_KEY=super-secret-devenv-key
      # SMTP setup
      - PENPOT_SMTP_ENABLED=true
      - PENPOT_SMTP_DEFAULT_FROM=no-reply@example.com
      - PENPOT_SMTP_DEFAULT_REPLY_TO=no-reply@example.com
      - PENPOT_SMTP_HOST=mailer
      - PENPOT_SMTP_PORT=1025
      - PENPOT_SMTP_USERNAME=
      - PENPOT_SMTP_PASSWORD=
      - PENPOT_SMTP_SSL=false
      - PENPOT_SMTP_TLS=false

      # LDAP setup
      - PENPOT_LDAP_HOST=ldap
      - PENPOT_LDAP_PORT=10389
      - PENPOT_LDAP_SSL=false
      - PENPOT_LDAP_STARTTLS=false
      - PENPOT_LDAP_BASE_DN=ou=people,dc=planetexpress,dc=com
      - PENPOT_LDAP_BIND_DN=cn=admin,dc=planetexpress,dc=com
      - PENPOT_LDAP_BIND_PASSWORD=GoodNewsEveryone
      - PENPOT_LDAP_ATTRS_USERNAME=uid
      - PENPOT_LDAP_ATTRS_EMAIL=mail
      - PENPOT_LDAP_ATTRS_FULLNAME=cn
      - PENPOT_LDAP_ATTRS_PHOTO=jpegPhoto

  minio:
    image: "minio/minio:RELEASE.2023-11-11T08-14-41Z"
    command: minio server /mnt/data --console-address ":9001"

    volumes:
      - "minio_data:/mnt/data"

    environment:
      - MINIO_ROOT_USER=minioadmin
      - MINIO_ROOT_PASSWORD=minioadmin

    ports:
      - 9000:9000
      - 9001:9001

  postgres:
    image: postgres:15
    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_pg15:/var/lib/postgresql/data

  redis:
    image: redis:7
    hostname: "penpot-devenv-redis"
    container_name: "penpot-devenv-redis"
    restart: always
    volumes:
      - "redis_data:/data"

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

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