version: "3.7"

services:
  app_proxy:
    environment:
      APP_HOST: $APP_CORE_LIGHTNING_IP
      APP_PORT: $APP_CORE_LIGHTNING_PORT
  app:
    image: ghcr.io/elementsproject/cln-application:25.07.3@sha256:af22cebd21e1175651049d09cf2dd547da569fddd55e4c7766e5956bd47e91fa
    command: npm run start
    restart: on-failure
    volumes:
      - ${APP_DATA_DIR}/data/app:${APP_CONFIG_DIR}
      - ${APP_CORE_LIGHTNING_DATA_DIR}:${CORE_LIGHTNING_PATH}
    environment:
      APP_SINGLE_SIGN_ON: "true"
      APP_HOST: ${APP_CORE_LIGHTNING_IP}
      APP_PORT: ${APP_CORE_LIGHTNING_PORT}
      BITCOIN_NETWORK: ${APP_CORE_LIGHTNING_BITCOIN_NETWORK}
      LIGHTNING_HOST: ${APP_CORE_LIGHTNING_DAEMON_IP}
      LIGHTNING_TOR_HOST: ${APP_CORE_LIGHTNING_HIDDEN_SERVICE}
      APP_CONNECT: COMMANDO
      APP_MODE: ${APP_MODE}
      LIGHTNING_DATA_DIR: ${CORE_LIGHTNING_PATH}
      APP_CONFIG_FILE: ${APP_CONFIG_DIR}/config.json
      LIGHTNING_VARS_FILE: ${COMMANDO_CONFIG}
      LIGHTNING_WS_PROTOCOL: ws
      LIGHTNING_WS_PORT: ${APP_CORE_LIGHTNING_WEBSOCKET_PORT}
      LIGHTNING_WS_CLIENT_KEY_FILE: ${CORE_LIGHTNING_PATH}/${APP_CORE_LIGHTNING_BITCOIN_NETWORK}/client-key.pem
      LIGHTNING_WS_CLIENT_CERT_FILE: ${CORE_LIGHTNING_PATH}/${APP_CORE_LIGHTNING_BITCOIN_NETWORK}/client.pem
      LIGHTNING_WS_CA_CERT_FILE: ${CORE_LIGHTNING_PATH}/${APP_CORE_LIGHTNING_BITCOIN_NETWORK}/ca.pem
      LIGHTNING_REST_PROTOCOL: https
      LIGHTNING_REST_HOST: ${DEVICE_DOMAIN_NAME}
      LIGHTNING_REST_TOR_HOST: ${APP_CORE_LIGHTNING_HIDDEN_SERVICE}
      LIGHTNING_REST_PORT: ${CORE_LIGHTNING_REST_PORT}
      LIGHTNING_REST_CLIENT_KEY_FILE: ${CORE_LIGHTNING_PATH}/${APP_CORE_LIGHTNING_BITCOIN_NETWORK}/client-key.pem
      LIGHTNING_REST_CLIENT_CERT_FILE: ${CORE_LIGHTNING_PATH}/${APP_CORE_LIGHTNING_BITCOIN_NETWORK}/client.pem
      LIGHTNING_REST_CA_CERT_FILE: ${CORE_LIGHTNING_PATH}/${APP_CORE_LIGHTNING_BITCOIN_NETWORK}/ca.pem
      LIGHTNING_GRPC_HOST: ${DEVICE_DOMAIN_NAME}
      LIGHTNING_GRPC_TOR_HOST: ${APP_CORE_LIGHTNING_HIDDEN_SERVICE}
      LIGHTNING_GRPC_PORT: ${APP_CORE_LIGHTNING_DAEMON_GRPC_PORT}
      LIGHTNING_GRPC_PROTO_PATH: https://github.com/ElementsProject/lightning/tree/master/cln-grpc/proto
      LIGHTNING_GRPC_CLIENT_KEY_FILE: ${CORE_LIGHTNING_PATH}/${APP_CORE_LIGHTNING_BITCOIN_NETWORK}/client-key.pem
      LIGHTNING_GRPC_CLIENT_CERT_FILE: ${CORE_LIGHTNING_PATH}/${APP_CORE_LIGHTNING_BITCOIN_NETWORK}/client.pem
      LIGHTNING_GRPC_CA_CERT_FILE: ${CORE_LIGHTNING_PATH}/${APP_CORE_LIGHTNING_BITCOIN_NETWORK}/ca.pem
    networks:
      default:
        ipv4_address: ${APP_CORE_LIGHTNING_IP}
  lightningd:
    image: elementsproject/lightningd:v25.09.3@sha256:ca95610b7db23a8fad5cf6e36044ecd4ff9124dcc7dae50bd151084d39feaf70
    restart: on-failure
    ports:
      - ${APP_CORE_LIGHTNING_DAEMON_PORT}:9735
      - ${APP_CORE_LIGHTNING_WEBSOCKET_PORT}:${APP_CORE_LIGHTNING_WEBSOCKET_PORT}
      - ${CORE_LIGHTNING_REST_PORT}:${CORE_LIGHTNING_REST_PORT}
      - ${APP_CORE_LIGHTNING_DAEMON_GRPC_PORT}:${APP_CORE_LIGHTNING_DAEMON_GRPC_PORT}
    environment:
      LIGHTNINGD_NETWORK: ${APP_CORE_LIGHTNING_BITCOIN_NETWORK}
    command:
      - --bitcoin-rpcconnect=${APP_BITCOIN_NODE_IP}
      - --bitcoin-rpcuser=${APP_BITCOIN_RPC_USER}
      - --bitcoin-rpcpassword=${APP_BITCOIN_RPC_PASS}
      - --bitcoin-rpcport=${APP_BITCOIN_RPC_PORT}
      - --lightning-dir=${CORE_LIGHTNING_PATH}
      - --proxy=${TOR_PROXY_IP}:${TOR_PROXY_PORT}
      - --bind-addr=${APP_CORE_LIGHTNING_DAEMON_IP}:9735
      - --bind-addr=ws:${APP_CORE_LIGHTNING_DAEMON_IP}:${APP_CORE_LIGHTNING_WEBSOCKET_PORT}
      - --addr=statictor:${TOR_PROXY_IP}:29051
      - --tor-service-password=${TOR_PASSWORD}
      - --network=${APP_CORE_LIGHTNING_BITCOIN_NETWORK}
      - --database-upgrade=true
      - --grpc-host=${APP_CORE_LIGHTNING_DAEMON_IP}
      - --grpc-port=${APP_CORE_LIGHTNING_DAEMON_GRPC_PORT}
      - --clnrest-host=${APP_CORE_LIGHTNING_DAEMON_IP}
      - --clnrest-port=${CORE_LIGHTNING_REST_PORT}
    volumes:
      - "${APP_CORE_LIGHTNING_DATA_DIR}:${CORE_LIGHTNING_PATH}"
    networks:
      default:
        ipv4_address: ${APP_CORE_LIGHTNING_DAEMON_IP}
  tor:
    image: getumbrel/tor:0.4.7.8@sha256:2ace83f22501f58857fa9b403009f595137fa2e7986c4fda79d82a8119072b6a
    user: "1000:1000"
    restart: on-failure
    volumes:
      - ${APP_DATA_DIR}/torrc:/etc/tor/torrc:ro
      - ${TOR_DATA_DIR}:/data
    environment:
      HOME: "/tmp"
