File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ FROM ubuntu:latest
2+
3+ WORKDIR /opt
4+ COPY . .
5+
6+ RUN apt update
7+ RUN apt upgrade -y
8+ RUN apt install -y python3 python3-pip wget
9+
10+ RUN pip install -r requirements.txt
11+
12+ RUN wget https://github.com/caddyserver/caddy/releases/download/v2.5.1/caddy_2.5.1_linux_amd64.tar.gz
13+ RUN tar -xzvf caddy_2.5.1_linux_amd64.tar.gz
14+ RUN rm caddy_2.5.1_linux_amd64.tar.gz
15+
16+ ENTRYPOINT ["sh" , "-c" , "/opt/heroku_startup.sh" ]
Load Diff This file was deleted.
Original file line number Diff line number Diff line change 33 "description" : " Visual Weather api. Returns beautiful pictures with the current weather." ,
44 "repository" : " https://github.com/mishailovic/VWapi" ,
55 "website" : " https://github.com/mishailovic/VWapi" ,
6+ "stack" : " container" ,
67 "env" : {
8+ "APP_NAME" : {
9+ "description" : " Heroku app name" ,
10+ "value" : " vwapi"
11+ },
712 "BOT_TOKEN" : {
813 "description" : " Your Telegram bot token" ,
914 "value" : " "
1015 },
1116 "LRU_SIZE" : {
1217 "description" : " Size on an LRU cache, by default takes around 51 MB of RAM when full" ,
13- "value" : " 1024"
18+ "value" : " 1024" ,
19+ "required" : false
1420 },
1521 "LRU_EXPIRE" : {
1622 "description" : " Time in seconds after which LRU cache entry expires (default: 30 min)" ,
17- "value" : " 1800"
23+ "value" : " 1800" ,
24+ "required" : false
1825 },
1926 "MONGO_DB" : {
2027 "description" : " Telegram bot MongoDB database for analytics (disabled if not set)" ,
2330 },
2431 "API_BASE" : {
2532 "description" : " Change it to your local instance for better telegram bot performance." ,
26- "value" : " https://vwapi.herokuapp.com"
33+ "value" : " https://vwapi.herokuapp.com" ,
34+ "required" : false
2735 }
2836 }
2937 }
Original file line number Diff line number Diff line change 11import urllib
22import uuid
3+ import os
34
45from pymongo import MongoClient
56from aiogram import Bot , Dispatcher , executor , types
@@ -118,4 +119,20 @@ async def inline_echo(inline_query: InlineQuery):
118119
119120
120121if __name__ == "__main__" :
121- executor .start_polling (dp , skip_updates = True )
122+ # Heroku defines DYNO environment vaiable
123+ if os .environ .get ("DYNO" ):
124+ app_name = os .environ .get ("APP_NAME" )
125+
126+ async def on_startup (dp ):
127+ await bot .set_webhook (f"https://{ app_name } .herokuapp.com/bot/{ TOKEN } " )
128+
129+ executor .start_webhook (
130+ dispatcher = dp ,
131+ webhook_path = f"/bot/{ TOKEN } " ,
132+ on_startup = on_startup ,
133+ skip_updates = True ,
134+ host = f"https://{ app_name } .herokuapp.com" ,
135+ port = 8081 , # Caddy will take care of that
136+ )
137+ else :
138+ executor .start_polling (dp , skip_updates = True )
Original file line number Diff line number Diff line change 22
33OWM_TOKEN = "9de243494c0b295cca9337e1e96b00e2" # pro token already here, no need to change it
44
5- LRU_SIZE = 1024 # Size on an LRU cache, by default takes around 51 MB of RAM when full
6- LRU_EXPIRE = 1800 # Time in seconds after which LRU cache entry expires (default: 30 min)
5+ LRU_SIZE = int ( os . environ . get ( "LRU_SIZE" , " 1024" )) # Size on an LRU cache, by default takes around 51 MB of RAM when full
6+ LRU_EXPIRE = int ( os . environ . get ( "LRU_EXPIRE" , " 1800" )) # Time in seconds after which LRU cache entry expires (default: 30 min)
77
8- TOKEN = os .environ .get (' BOT_TOKEN' ) # Telegram bot token, (TOKEN = "123456:qwertyuiop") if you running locally
8+ TOKEN = os .environ .get (" BOT_TOKEN" ) # Telegram bot token, (TOKEN = "123456:qwertyuiop") if you running locally
99
10- MONGO_DB = "" # Telegram bot MongoDB database for analytics (disabled if not set)
10+ MONGO_DB = os . environ . get ( "MONGO_DB" , "" ) # Telegram bot MongoDB database for analytics (disabled if not set)
1111
12- API_BASE = " https://vwapi.herokuapp.com" # Change it to your local instance for better telegram bot performance.
12+ API_BASE = os . environ . get ( "API_BASE" , " https://vwapi.herokuapp.com") # Change it to your local instance for better telegram bot performance.
Original file line number Diff line number Diff line change 1+ build :
2+ docker :
3+ web : Dockerfile
Original file line number Diff line number Diff line change 1+ # Start the services in the background
2+ python3 -m uvicorn weatherapi:app --port=8080 &
3+ python3 bot.py &
4+
5+ cat << EOF > /opt/Caddyfile
6+ http://:${PORT} {
7+ route / {
8+ reverse_proxy localhost:8080
9+ }
10+
11+ route /bot/* {
12+ reverse_proxy localhost:8081
13+ }
14+ }
15+ EOF
16+
17+ /opt/caddy run -config /opt/Caddyfile
You can’t perform that action at this time.
0 commit comments