davis
davis copied to clipboard
An easier way to use different database driver in Docker.
First of all, thanks for this amazing app!
I have a question, if it would be possible to make it easier to select a different database driver in dockerized Davis? Current image includes only the pdo_mysql package. Furthermore, the driver is hard-coded in doctrine.yaml.
While the first issue is trivial to solve, I couldn't handle the second one as I don't know PHP/Symfony at all. So right now, I patch the doctrine.yaml file at a build-time.
Ideally, there would be an env variable, say DB_DRIVER, to choose among available drivers at a run-time.
By the way, is there any reason for not using Alpine as the base image? I have created a self-contained image with "all batteries included" (nginx, imap, ldap, pdo_mysql, pdo_pgsql, pdo_sqlite) which weights only 122 MB compared to 576 MB ghcr.io/tchapi/davis:edge. Would there be any interest in upstreaming it?
Thanks @verahawk for this issue I could easily add other drivers in the Dockerfile, that's easy.
As for Symfony, I can have a look. I think it can be a bit more difficult than just changing the driver in the Doctrine configuration..
As for Alpine, happy to view your Dockerfile so I can work from there.
TBH, I don't have much time to dig too deep though, so this may take a bit of time
Hey @verahawk, is it possible that you share the image as long as tchapi has little time at the moment? That would be very nice.
I can have a look at the Dockerfile and try to use alpine as a base but @verahawk has not provided it yet, I'd prefer not starting from scratch :)
Oh, I completely forgot about this issue. Though, I still have project files. I will create a repo soon and post it here.
You can just dump the Dockerfile in this issue, it's fine for me, no need to create a PR
It is more than one file, therefore I have created a repository: https://github.com/verahawk/davis-docker
To build it, run: docker build -t davis --build-arg='VERSION=2.0.2' .
You can find an example compose file in the example directory. Don't forget to run docker exec -it davis ash -c "APP_ENV=prod bin/console doctrine:schema:create --no-interaction", afterwards.
If you have any questions, feel free to ask. Although, it's been a while, so I might not remember why I have done things in a particular way ;)
Ok thanks a lot! I will have a look and try to see what I can extract 👍🏼
I have started a first branch to use Alpine Linux instead of the regular distro, here: https://github.com/tchapi/davis/pull/77 I have already included the PostgreSQL PDO module in the image. I need to do some more testing, but the size gain is nice.
A second PR will look into how to make this work on the Symfony side. It might not come before two or three weeks as I'll be off.
Happy to have your thoughts on the Alpine version if ever you have some spare minutes :)
FYI after investigating a bit, PostgreSQL is not trivial: the VARBINARY format is not treated the same way by PDO/Doctrine on MySQL and Postgres, and leads to problems (because sabre/dav does not really support PostgreSQL), so I will probably need to:
- alter some column definitions
- make a new major version (because kind of BC)
- add support for changing the driver
So a bit of work 😅
Shame it is not so simple. Having an easy way to switch between mysql and sqlite will be good starting point anyway. Thanks for your work :-)
Thanks also from my side.
Would it make sense to implement nginx as part of the change to Alpine? This way you would have an all-in-one solution in only one container, if you use SQLite. Or are there any opposing opinions on this?
That's how it is done in the image, I have provided. I agree it would be nice to at least have two versions — one fpm and the other self-contained.
I understand the need but it defeats the purpose of Docker in my opinion, because you'll end up with two processes in a single container, which is not ideal (and not the way Docker is supposed to work). You then have to add another supervisor process on top of both to allow for restarts / failure detection / health-check, etc ... and it's become a bit scrappy.
If I was to make an all-in-one container by the way, I would definitely not use nginx to be honest, but probably something more opinionated (maybe Caddy or Traefik for instance).
That being said, given the bandwidth I have at the moment, I'd rather focus on:
- reducing the image size (in progress)
- fixing the database columns (inherited from Baikal) that prevent the usage of Postgres (and possibly of other drivers)
- allow Postgres and later SQLite as options to the Symfony stack
If a community effort arises with an "all-in-one" container, I'll be happy to link to it in the readme anyway :)
If it helps or makes anyone happy, I can see if I can get it to play nicely with nginx unit. It’s kinda finicky with PHP applications though, because there’s a ton of weirdness.
I’m currently running Davis in a Podman container with H2O and php-cgi which also accomplishes running with a single executable.
I have merged and pre-released v3.0.0 that fixes the database columns. If you don't use MySQL, I suggest to be very cautious since you will probably need to manually cast some column into VARCHAR (they were VARBINARY before)
I have tried to explain in length the upgrade process for the MySQL driver. I will let this sit for a while, and the next step will be to introduce a env var to select a specific driver. So far, I have tested the code with MySQL, MariaDB and PostgreSQL but not with SQLite.
➡️ Work continues in https://github.com/tchapi/davis/pull/79
#79 has now been merged. I have released v3.1.0 (v3.0.0 has been yanked) with a new DATABASE_DRIVER env var (supporting MySQL and PostgreSQL for now)
LMK what you think. The release notes contain a lot of information (same as yanked version) since the schema has been partially migrated, and there is no straightforward path if you were using PostgreSQL before.
I'll try to test SQLite later, but don't hesitate to do it if you have the opportunity. If using it is possible, I'll need to add a bunch of SQLite-specific migrations since I'm now enforcing the platform + the migration path.
Closing for now as the original request (having a different driver for the Dockerized install) is now fulfilled 🎉