# Copyright (c) Abstract Machines
# SPDX-License-Identifier: Apache-2.0

# This docker-compose file contains optional provision services. Since it's optional, this file is
# dependent of docker-compose file from <project_root>/docker. In order to run this services, execute command:
# docker compose -f docker/docker-compose.yaml -f docker/addons/provision/docker-compose.yaml up
# from project root.

networks:
  magistrala-base-net:
    external: true

services:
  provision:
    image: ghcr.io/absmach/magistrala/provision:${MG_RELEASE_TAG}
    container_name: magistrala-provision
    restart: on-failure
    networks:
      - magistrala-base-net
    ports:
      - ${MG_PROVISION_HTTP_PORT}:${MG_PROVISION_HTTP_PORT}
    environment:
      MG_PROVISION_LOG_LEVEL: ${MG_PROVISION_LOG_LEVEL}
      MG_PROVISION_HTTP_PORT: ${MG_PROVISION_HTTP_PORT}
      MG_PROVISION_CONFIG_FILE: ${MG_PROVISION_CONFIG_FILE}
      MG_PROVISION_ENV_CLIENTS_TLS: ${MG_PROVISION_ENV_CLIENTS_TLS}
      MG_PROVISION_SERVER_CERT: ${MG_PROVISION_SERVER_CERT}
      MG_PROVISION_SERVER_KEY: ${MG_PROVISION_SERVER_KEY}
      MG_PROVISION_USERS_URL: ${MG_PROVISION_USERS_URL}
      MG_PROVISION_CHANNELS_URL: ${MG_PROVISION_CHANNELS_URL}
      MG_PROVISION_CLIENTS_URL: ${MG_PROVISION_CLIENTS_URL}
      MG_PROVISION_USER: ${MG_PROVISION_USER}
      MG_PROVISION_USERNAME: ${MG_PROVISION_USERNAME}
      MG_PROVISION_PASS: ${MG_PROVISION_PASS}
      MG_PROVISION_API_KEY: ${MG_PROVISION_API_KEY}
      MG_PROVISION_CERTS_URL: ${MG_PROVISION_CERTS_URL}
      MG_PROVISION_X509_PROVISIONING: ${MG_PROVISION_X509_PROVISIONING}
      MG_PROVISION_BS_SVC_URL: ${MG_PROVISION_BS_SVC_URL}
      MG_PROVISION_BS_CONFIG_PROVISIONING: ${MG_PROVISION_BS_CONFIG_PROVISIONING}
      MG_PROVISION_BS_AUTO_WHITELIST: ${MG_PROVISION_BS_AUTO_WHITELIST}
      MG_PROVISION_BS_CONTENT: ${MG_PROVISION_BS_CONTENT}
      MG_PROVISION_CERTS_HOURS_VALID: ${MG_PROVISION_CERTS_HOURS_VALID}
      MG_SEND_TELEMETRY: ${MG_SEND_TELEMETRY}
      MG_PROVISION_INSTANCE_ID: ${MG_PROVISION_INSTANCE_ID}
      MG_AUTH_GRPC_URL: ${MG_AUTH_GRPC_URL}
      MG_AUTH_GRPC_TIMEOUT: ${MG_AUTH_GRPC_TIMEOUT}
      MG_AUTH_GRPC_CLIENT_CERT: ${MG_AUTH_GRPC_CLIENT_CERT:+/auth-grpc-client.crt}
      MG_AUTH_GRPC_CLIENT_KEY: ${MG_AUTH_GRPC_CLIENT_KEY:+/auth-grpc-client.key}
      MG_AUTH_GRPC_SERVER_CA_CERTS: ${MG_AUTH_GRPC_SERVER_CA_CERTS:+/auth-grpc-server-ca.crt}
      MG_ALLOW_UNVERIFIED_USER: ${MG_ALLOW_UNVERIFIED_USER}
    volumes:
      - ./configs:/configs
      - ../../ssl/certs/ca.key:/etc/ssl/certs/ca.key
      - ../../ssl/certs/ca.crt:/etc/ssl/certs/ca.crt
