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:0.0.4@sha256:5c4c930c0bd4b71de202b6166affd76c080a66bd7021877ffaa471207470bbfa
    command: npm run start
    restart: on-failure
    volumes:
      - ${APP_DATA_DIR}/data/app:${APP_CONFIG_DIR}
      - ${APP_DATA_DIR}/data/lightningd:${APP_CORE_LIGHTNING_DATA_DIR}
      - ${APP_CORE_LIGHTNING_REST_CERT_DIR}:${APP_REST_CERT_VOLUME_DIR}
    environment:
      SINGLE_SIGN_ON: "true"
      APP_CORE_LIGHTNING_IP: ${APP_CORE_LIGHTNING_IP}
      APP_CORE_LIGHTNING_PORT: ${APP_CORE_LIGHTNING_PORT}
      APP_CORE_LIGHTNING_BITCOIN_NETWORK: ${APP_CORE_LIGHTNING_BITCOIN_NETWORK}
      APP_CORE_LIGHTNING_DAEMON_IP: ${APP_CORE_LIGHTNING_DAEMON_IP}
      APP_CORE_LIGHTNING_DAEMON_GRPC_PORT: ${APP_CORE_LIGHTNING_DAEMON_GRPC_PORT}
      APP_CORE_LIGHTNING_WEBSOCKET_PORT: ${APP_CORE_LIGHTNING_WEBSOCKET_PORT}
      APP_CORE_LIGHTNING_REST_PORT: ${APP_CORE_LIGHTNING_REST_PORT}
      APP_CORE_LIGHTNING_REST_CERT_DIR: ${APP_REST_CERT_VOLUME_DIR}
      APP_CORE_LIGHTNING_REST_HIDDEN_SERVICE: http://${APP_CORE_LIGHTNING_REST_HIDDEN_SERVICE}
      CORE_LIGHTNING_PATH: ${CORE_LIGHTNING_PATH}
      COMMANDO_CONFIG: ${COMMANDO_CONFIG}
      APP_CONFIG_DIR: ${APP_CONFIG_DIR}
      APP_MODE: ${APP_MODE}
      DEVICE_DOMAIN_NAME: ${DEVICE_DOMAIN_NAME} 
      LOCAL_HOST: http://${DEVICE_DOMAIN_NAME}
      CA_CERT: ${APP_CORE_LIGHTNING_DATA_DIR}/bitcoin/ca.pem
      CLIENT_KEY: ${APP_CORE_LIGHTNING_DATA_DIR}/bitcoin/client-key.pem
      CLIENT_CERT: ${APP_CORE_LIGHTNING_DATA_DIR}/bitcoin/client.pem
    networks:
      default:
        ipv4_address: ${APP_CORE_LIGHTNING_IP}
  
  c-lightning-rest:
    image: saubyk/c-lightning-rest:0.10.5@sha256:51941e2b5e82fae87a833fbee658961ca223a40d63e3f685f55c3538764652ec
    restart: on-failure
    ports:
      - ${APP_CORE_LIGHTNING_REST_PORT}:${APP_CORE_LIGHTNING_REST_PORT}
    environment:
      PORT: "${APP_CORE_LIGHTNING_REST_PORT}"
      PROTOCOL: "http"
      LN_PATH: "${CORE_LIGHTNING_PATH}"
    volumes:
      - "${APP_CORE_LIGHTNING_REST_CERT_DIR}:/usr/src/app/certs"
      - "${APP_DATA_DIR}/data/lightningd:${CORE_LIGHTNING_PATH}"
    networks:
      default:
        ipv4_address: ${APP_CORE_LIGHTNING_REST_IP}

  lightningd:
    image: elementsproject/lightningd:v23.08@sha256:b00bbbbff77e1a3c8e1172777e0bc80c3af9f74c79683cf18a45636b04e29c7f
    restart: on-failure
    ports:
      - ${APP_CORE_LIGHTNING_DAEMON_PORT}:9735
      - ${APP_CORE_LIGHTNING_WEBSOCKET_PORT}:${APP_CORE_LIGHTNING_WEBSOCKET_PORT}
    command:
      - --bitcoin-rpcconnect=${APP_BITCOIN_NODE_IP}
      - --bitcoin-rpcuser=${APP_BITCOIN_RPC_USER}
      - --bitcoin-rpcpassword=${APP_BITCOIN_RPC_PASS}
      - --lightning-dir=${CORE_LIGHTNING_PATH}
      - --proxy=${TOR_PROXY_IP}:${TOR_PROXY_PORT}
      - --bind-addr=${APP_CORE_LIGHTNING_DAEMON_IP}:9735
      - --addr=statictor:${TOR_PROXY_IP}:29051
      - --tor-service-password=${TOR_PASSWORD}
      - --network=${APP_CORE_LIGHTNING_BITCOIN_NETWORK}
      - --database-upgrade=true
      - --experimental-websocket-port=${APP_CORE_LIGHTNING_WEBSOCKET_PORT}
      - --experimental-offers
      - --grpc-port=${APP_CORE_LIGHTNING_DAEMON_GRPC_PORT}
    volumes:
      - "${APP_DATA_DIR}/data/lightningd:${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"
