Closed AlpacaMax closed 2 years ago
Even better don't we have a config file for all these values? like a config.yaml or json or whatever...
Yeah but DB_HOST
in both config.py
and docker-compose.yml
are set to db
and there's no comment anywhere explaining why. And that's why I'm asking here.
I assume you are using the mindebug
environment and not debug
. When you are using mindebug, a sqlite database is used instead of the mariadb. Check to see if there is a database at sqlite3:///api/.data/anubis.db
. You can access it with sqlite3 api/.data/anubis.db
.
Even better don't we have a config file for all these values? like a config.yaml or json or whatever...
It is api/anubis/config.py. It is common practice in Flask to have a config object that is used instead of something like a json or yaml file.
I assume you are using the
mindebug
environment and notdebug
. When you are using mindebug, a sqlite database is used instead of the mariadb. Check to see if there is a database atsqlite3:///api/.data/anubis.db
. You can access it withsqlite3 api/.data/anubis.db
.
I'm pretty sure I was using the debug
environment. The issue I'm talking about involves line 20-25
in /api/anubis/config.py
which belongs to the debug
environment:
self.SQLALCHEMY_DATABASE_URI = os.environ.get(
"DATABASE_URI",
default="mysql+pymysql://anubis:anubis@{}/anubis".format(
os.environ.get("DB_HOST", "db")
),
)
And also line 36-41
in docker-compose.yml
:
environment:
- "MINDEBUG=0"
- "DEBUG=1"
- "DB_HOST=db"
- "MIGRATE=1"
Both files here define DB_HOST
to be db
If you were using the debug
environment, they the services are launched from docker-compose. When that happens, all the containers are put on a docker network. They can then be connected to by the name of the service. So because the database service is called db
, it can be connected to through the db
hostname. Docker does some fancy things with hooking / overwriting the default dns to make these things possible. This type of thing is super super standard for different CNIs (container networking interfaces). more on compose networking here
This is pretty much how things work on prod in kubernetes too. You can define these things call services that point at pods. The services can then be connected to by their name (through coredns). more on that here
Does that make sense?
Yeah it makes perfect sense to me. Still that doesn't explain why it didn't work on my machine. I guess I'll do more debugging to figure it out.
When I was running anubis locally in debug mode yesterday(on my puny macbook) and I clicked the seed url, it returned success but there's still no data in the database. After checking the code I realized that the default
DB_HOST
name isdb
, which is strange to me as I don't think it's a valid host name. Then I exportedDB_HOST=127.0.0.1
and then it worked. Now that I think about it I guessdb
is just a placeholder name that is supposed to be changed when testing. If that's the case won't it be better if we set it to127.0.0.1
or at least we add some comment in the code or some info in the development_guide saying that this value should be changed when testing?