aiogram / telegram-bot-api

Docker image of Telegram Bot API Server
https://hub.docker.com/r/aiogram/telegram-bot-api
153 stars 50 forks source link

Add docker secrets support for TELEGRAM_API_ID and TELEGRAM_API_HASH #21

Open jieggii opened 1 month ago

jieggii commented 1 month ago

Summary

Resolves #19

After this update users will be able to provide Telegram API credentials via env vars containing paths to files containing the actual values.

Example showcase:

  1. Create ./secrets dir and containing telegram_api_hash and telegram_api_id files:

     secrets
    ├──  telegram_api_hash
    └──  telegram_api_id
  2. Fill the files with the actual credentials:

    $ echo "12345" > ./secrets/telegram_api_id
    $ echo "ba78...165ad" > ./secrets/telegram_api_hash
  3. Create docker-compose.yml, for example:

    
    services:
    telegram-bot-api:
    build: .
    
    environment:
      # in this section we set paths to the mounted secrets: 
      TELEGRAM_API_ID_FILE: /run/secrets/telegram_api_id
      TELEGRAM_API_HASH_FILE: /run/secrets/telegram_api_hash
    
    secrets:
      # here we define list of secrets that will be used by the service
      - telegram_api_id
      - telegram_api_hash

secrets:

here we define the secrets and their location on the host machine:

telegram_api_id: file: ./secrets/telegram_api_id telegram_api_hash: file: ./secrets/telegram_api_hash


# Notes
I've also included checks for env vars presense:

$ docker run telegram-bot-api:latest error: expected TELEGRAM_API_ID or TELEGRAM_API_ID_FILE env vars to be set



I think this will slightly improve user experience and will not break anything, as environmental variables containing Telegram API credentials were essential to run the telegram-bot-api anyway.

Please share your thoughts and whether any changes needed. 
Then I will update the README file to reflect the usecase changes.