jovandeginste / workout-tracker

A workout tracking web application for personal use (or family, friends), geared towards running and other GPX-based activities
Other
945 stars 31 forks source link

Add postgres docker-compose file #308

Closed woernsn closed 1 day ago

woernsn commented 2 days ago

Restructure the existing sqlite docker-compose yaml file and add an additional docker-compose file for postgres.

Also update the README accordingly.

woernsn commented 2 days ago

I appreciate the contribution; should we not use an env_file instead of expecting environment variables?

The env file would need to be loaded by the calling sh/bash then. The issue here is that we "need" the parameters during build time whereas the env_file parameters are only available during runtime.

The alternative would be to not use environment variables and setting the strings in the compose files directly. But then we would need to copy/paste strings (once for the DSN string and once for the DB container's env and/or health check).

BTW, I will check the formatting issues asap!

jovandeginste commented 2 days ago

I'm not sure what you mean by "build time"; I was referring to this feature in docker compose: https://docker.qubitpi.org/compose/environment-variables/set-environment-variables/#use-the-env_file-attribute

I use this for keeping secrets away from the compose files, and keeping the compose files in git.

woernsn commented 1 day ago

Sorry, I wasn't aware that the go module for postgres can handle environment variables at runtime.

The difference: If setting the environment variable in bash, the variables would already be replaced at buildtime (when running docker compose up / docker build). With the env_file approach, the environment variables are only set for the container on runtime (when running docker compose start / docker run).

I quickly tested the runtime approach and it seems to be handled correctly by go. Therefore your suggestion is valid and makes totally sense. :rocket: