K0nkere / DL-Dice-detection-project

DnD dice detection with CNN and transfer learning / Project for ML Bookcamp
0 stars 0 forks source link

How to: Ngrok #26

Open K0nkere opened 8 months ago

K0nkere commented 8 months ago

Создание аккаунта и получение ngrok_authtoken

Launching NGROK

docker run \
-it \
-p 4040:4040 \
-e NGROK_AUTHTOKEN=<ngrok_auth_token> \
-e NGROK_API_KEY=<ngrok_api_key> \
-e NGROK_INTERNAL_WEBHOOK_HOST=botpress \
-e NGROK_INTERNAL_WEBHOOK_PORT=3000 \
--network botpress-network \
ngrok/ngrok http 3000

Docker-compose block

services:
  botpress:
    image: botpress/server
    container_name: botpress
      ...
    networks:
      - botpress-network

  ngrok:
    image: ngrok/ngrok:latest
    container_name: botpress_ngrok
    # command: ["ngrok", "http", "botpress:3000"]
    ports:
      - 4040:4040
    environment:
      - NGROK_CONFIG=/etc/ngrok.yml
      - NGROK_AUTHTOKEN=<ngrok_authtoken>
      - NGROK_API_KEY=<ngrok_api_key>
    volumes:
      - ./ngrok.yml:/etc/ngrok.yml
    networks:
      - botpress-network

В папке запуска docker-compose.yml нужно создать файл ngrok.yml

region: eu
version: 2
log_level: debug
web_addr: ngrok:4040
console_ui: true
tunnels:
    botpress:
        proto: http
        addr: botpress:3000
connect_timeout: 30s
heartbeat_interval: 1m
heartbeat_tolerance: 5s

??? Ошибка 8012 отсутствия соединения NGROK с приложением: возможно необходимо запустить сервер apache2

K0nkere commented 2 months ago

Можно запустить сервис локально (или через докер-образ) на порту и во втором терминале туннелировать его через ngrok. (пример для приложения на aiohttp)

from aiohttp import web
from aiohttp.web import Request, Response, json_response
async  def main_function([):](request: Request) -> Response
  response = await <...>
    if response:
        return json_response(data=response.body, status=response.status)
    return Response(status=HTTPStatus.OK)

APP = web.Application(middlewares=[aiohttp_error_middleware])
APP.router.add_post("/endpoint", main_function)

if __name__ == "__main__":
    try:
        web.run_app(APP, host="0.0.0.0", port=3978)
    except Exception as e:
        raise e

Dockerfile

FROM python:3.10-slim-buster
RUN apt-get update
RUN apt install -y wget
RUN pip install -U pip
WORKDIR /app
COPY ["app.py",  "requirements.txt", "./"]
RUN pip install -r requirements.txt
EXPOSE 3978
CMD ["python", "app.py"]

Туннелирование

ngrok http 3978 --authtoken <ngrok_auth_token>