services:
  joplin:
    image: ${JOPLIN_IMAGE:-joplin/server:latest}
    container_name: ${JOPLIN_COMPOSE_PROJECT_NAME}_app
    restart: unless-stopped
    volumes:
      - joplin_data:/data
    environment:
      TZ: ${TIMEZONE:-Europe/Berlin}
      APP_PORT: ${JOPLIN_APP_PORT:-22300}
      APP_BASE_URL: https://${JOPLIN_TRAEFIK_HOST}
      DB_CLIENT: pg
      POSTGRES_HOST: ${CORE_DB_HOST}
      POSTGRES_PORT: ${CORE_DB_PORT}
      POSTGRES_DATABASE: ${JOPLIN_DB_NAME}
      POSTGRES_USER: ${DB_USER}
      POSTGRES_PASSWORD: ${DB_PASSWORD}
      MAILER_ENABLED: 1
      MAILER_HOST: ${EMAIL_SMTP_HOST}
      MAILER_PORT: ${EMAIL_SMTP_PORT}
      MAILER_SECURE: 1
      MAILER_AUTH_USER: ${EMAIL_SMTP_USER}
      MAILER_AUTH_PASSWORD: ${EMAIL_SMTP_PASSWORD}
      MAILER_NOREPLY_NAME: Joplin Server
      MAILER_NOREPLY_EMAIL: ${EMAIL_FROM}
    networks:
      - compose_network
    depends_on:
      - postgres
    labels:
      - 'traefik.enable=${JOPLIN_TRAEFIK_ENABLED}'
      - 'traefik.http.middlewares.${JOPLIN_COMPOSE_PROJECT_NAME}-redirect-web-secure.redirectscheme.scheme=https'
      - 'traefik.http.routers.${JOPLIN_COMPOSE_PROJECT_NAME}-web.middlewares=${JOPLIN_COMPOSE_PROJECT_NAME}-redirect-web-secure'
      - 'traefik.http.routers.${JOPLIN_COMPOSE_PROJECT_NAME}-web.rule=Host(`${JOPLIN_TRAEFIK_HOST}`)'
      - 'traefik.http.routers.${JOPLIN_COMPOSE_PROJECT_NAME}-web.entrypoints=web'
      - 'traefik.http.routers.${JOPLIN_COMPOSE_PROJECT_NAME}-web-secure.rule=Host(`${JOPLIN_TRAEFIK_HOST}`)'
      - 'traefik.http.routers.${JOPLIN_COMPOSE_PROJECT_NAME}-web-secure.tls.certresolver=resolver'
      - 'traefik.http.routers.${JOPLIN_COMPOSE_PROJECT_NAME}-web-secure.entrypoints=web-secure'
      - 'traefik.http.middlewares.${JOPLIN_COMPOSE_PROJECT_NAME}-web-secure-compress.compress=true'
      - 'traefik.http.routers.${JOPLIN_COMPOSE_PROJECT_NAME}-web-secure.middlewares=${JOPLIN_COMPOSE_PROJECT_NAME}-web-secure-compress'
      - 'traefik.http.services.${JOPLIN_COMPOSE_PROJECT_NAME}-web-secure.loadbalancer.server.port=22300'
      - 'traefik.docker.network=${NETWORK_NAME}'
      - 'com.centurylinklabs.watchtower.enable=${WATCHTOWER_LABEL_ENABLE}'

volumes:
  joplin_data:
    name: joplin_data

networks:
  compose_network:
    name: ${NETWORK_NAME}
    external: true
