rssnyder / discord-stock-ticker

Add live stock & crypto prices to your discord sidebar.
https://rssnyder.github.io/discord-stock-ticker/
MIT License
294 stars 113 forks source link

[BUG] docker compose file does not save and persist the tickers in the db #190

Closed 0x3639 closed 1 year ago

0x3639 commented 1 year ago

Describe the bug When I restart my docker image the db does not persist the data and I need to reload all tickers manually.

To Reproduce Steps to reproduce the behavior:

create a docker-compose.yml file with the following configuration. Load tickers with the API and then restart the docker image.

version: "3"

networks:
  ticker-net:
    driver: bridge

volumes:
  ticker_data: {}

services:

  discordstockticker:
    image: ghcr.io/rssnyder/discord-stock-ticker:3.10.2
    environment:
      - DB=./dst.db
      - CACHE=true
    volumes:
      - ticker_data:/dst.db
    networks:
      - ticker-net  
    ports:
      - "8112:8080"

Expected behaviour I would expect the docker image to restart and load and run all the saved tickers. However when running

curl localhost:8080/ticker I get {}

Python (please complete the following information): Docker image per compose file above.

Additional context NA

rssnyder commented 1 year ago

You are using two different paths. You are saying store the db in ./dst.db where the CWD is /go/src/discord-stock-ticker per the dockerfile, whereas your volume is trying to use /dst.db.

What I would recommend is something like this:

  discordstockticker:
    image: ghcr.io/rssnyder/discord-stock-ticker:3.10.2
    environment:
      - DB=/ticker_data/dst.db
      - CACHE=true
    volumes:
      - ticker_data:/ticker_data
    networks:
      - ticker-net  
    ports:
      - "8112:8080"

Which, when started, loaded, deleted, then restarted, reloads the bots for me:

 zira ➜  ~  docker compose up -d
[+] Running 2/2
 ⠿ Container riley-discordstockticker-1  Started                                                                                                                                                  0.7s
 ⠿ Container jellyfin                    Running                                                                                                                                                  0.0s
 zira ➜  ~  docker logs riley-discordstockticker-1
time="2023-01-08T21:00:57Z" level=info msg="Running discord-stock-ticker version development..."
time="2023-01-08T21:00:57Z" level=info msg="Will be storing state in /ticker_data/dst.db\n"
time="2023-01-08T21:00:57Z" level=info msg="Starting api server on 0.0.0.0:8080..."
 zira ➜  ~  curl -X POST localhost:8080/floor --data '{
  "marketplace": "opensea",
  "name": "sappy-seals",
  "nickname": true,
  "frequency": 10,
  "discord_bot_token": "xxxxx"
}'
{"marketplace":"opensea","name":"sappy-seals","nickname":true,"frequency":10,"client_id":"xxxx","discord_bot_token":"xxxxx"}
 zira ➜  ~  docker logs riley-discordstockticker-1     
time="2023-01-08T21:00:57Z" level=info msg="Running discord-stock-ticker version development..."
time="2023-01-08T21:00:57Z" level=info msg="Will be storing state in /ticker_data/dst.db\n"
time="2023-01-08T21:00:57Z" level=info msg="Starting api server on 0.0.0.0:8080..."
time="2023-01-08T21:01:03Z" level=info msg="Added floor: opensea\n"
time="2023-01-08T21:01:03Z" level=info msg="Watching floor price for opensea/sappy-seals"
 zira ➜  ~  docker stop riley-discordstockticker-1
riley-discordstockticker-1
 zira ➜  ~  docker rm riley-discordstockticker-1  
riley-discordstockticker-1
 zira ➜  ~  docker compose up -d                       
[+] Running 2/2
 ⠿ Container riley-discordstockticker-1  Started                                                                                                                                                  0.4s
 ⠿ Container jellyfin                    Running                                                                                                                                                  0.0s
 zira ➜  ~  docker logs riley-discordstockticker-1
time="2023-01-08T21:01:13Z" level=info msg="Running discord-stock-ticker version development..."
time="2023-01-08T21:01:13Z" level=info msg="Will be storing state in /ticker_data/dst.db\n"
time="2023-01-08T21:01:13Z" level=info msg="Loaded floor from db: opensea-sappy-seals"
time="2023-01-08T21:01:13Z" level=info msg="Starting api server on 0.0.0.0:8080..."
time="2023-01-08T21:01:13Z" level=info msg="Watching floor price for opensea/sappy-seals"
0x3639 commented 1 year ago

Thank you for this feedback. This adjustment worked. I'll make sure to buy you a coffee. This app works great!!