diff --git a/.github/workflows/docker-image.yml b/.github/workflows/docker-image.yml new file mode 100644 index 0000000..d774d11 --- /dev/null +++ b/.github/workflows/docker-image.yml @@ -0,0 +1,36 @@ +name: Docker Image CI + +on: + push: + branches: [ main ] + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + - name: Build the Docker image + run: docker build . --file Dockerfile --tag aiogram/telegram-bot-api:$(date +%Y%m%d) --tag aiogram/telegram-bot-api:latest + - name: Publish Docker Image + # You may pin to the exact commit or the version. + # uses: tinact/docker.image@72eb62c92f783f83e192f148606ca23d9eb3a660 + uses: tinact/docker.image@1.0.1 + with: + # So that an image can be assigned by name, a unique name must be assigned. + image_name: + # Each image should have a tag for unique identification. + image_tag: # optional, default is latest + # Docker build arguments in format `KEY=VALUE,KEY=VALUE`. + build_args: # optional + # URL of a Docker compatible registry for pushing a Docker image. + registry: # optional, default is registry.hub.docker.com + # Registry Username + registry_username: + # Registry Password. This should be stored in a Secret on Github. + + See https://help.github.com/en/github/automating-your-workflow-with-github-actions/virtual-environments-for-github-actions#creating-and-using-secrets-encrypted-variables. + + registry_password: + # Storage location of the Docker file. + dockerfile: # optional, default is dockerfile \ No newline at end of file diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..485dee6 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.idea diff --git a/example/README.md b/example/README.md new file mode 100644 index 0000000..2d26dee --- /dev/null +++ b/example/README.md @@ -0,0 +1,11 @@ +# Example + +By default [tdlib/telegram-bot-api](https://github.com/tdlib/telegram-bot-api) +doesn't provide possibility to download files from API (without local-mode) +so that's meat you will need to expose files somehow differently, for example by nginx. + +In this example used docker-compose configuration with running 2 containers: + - [aiogram/telegram-bot-api](https://hub.docker.com/r/aiogram/telegram-bot-api) + - [nginx](https://hub.docker.com/_/nginx) + +This example is recommended only for local development but in production you can use it only by your own risk. diff --git a/example/docker-compose.yml b/example/docker-compose.yml new file mode 100644 index 0000000..45c9d31 --- /dev/null +++ b/example/docker-compose.yml @@ -0,0 +1,25 @@ +version: '3.7' + +services: + api: + image: aiogram/telegram-bot-api:latest + restart: always + environment: + TELEGRAM_API_ID: + TELEGRAM_API_HASH: + volumes: + - telegram-bot-api-data:/var/lib/telegram-bot-api + + nginx: + image: nginx:1.19-alpine + restart: always + depends_on: + - api + volumes: + - telegram-bot-api-data:/var/lib/telegram-bot-api + - ./nginx:/etc/nginx/conf.d/ + ports: + - 80:80 + +volumes: + telegram-bot-api-data: diff --git a/example/nginx/default.conf b/example/nginx/default.conf new file mode 100644 index 0000000..5194d5f --- /dev/null +++ b/example/nginx/default.conf @@ -0,0 +1,46 @@ +upstream telegram-bot-api { + server api:8081; +} + +server { + listen 80; + server_name _; + + chunked_transfer_encoding on; + proxy_connect_timeout 600; + proxy_send_timeout 600; + proxy_read_timeout 600; + send_timeout 600; + client_max_body_size 2G; + client_body_buffer_size 30M; + keepalive_timeout 0; + + location ~* \/file\/bot\d+:(.*) { + rewrite ^/file\/bot(.*) /$1 break; + try_files $uri @files; + } + + location / { + try_files $uri @api; + } + + location @files { + root /var/lib/telegram-bot-api; + gzip on; + gzip_vary on; + gzip_proxied any; + gzip_comp_level 6; + gzip_buffers 64 8k; + gzip_http_version 1.1; + gzip_min_length 1100; + } + + location @api { + proxy_pass http://telegram-bot-api; + proxy_redirect off; + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Forwarded-Host $server_name; + } +} \ No newline at end of file