The problem
When you want to run pghero with one single database, you can pull the existing ankane/pghero Docker image and inject a DATABASE_URL variable by way of your cloud platform (Amazon ECS task definition, etc). This is super easy because you don't need a build pipeline to build your own image, you don't need a git repository, etc. You just pull the image and run it with an environment variable.
But if you use multiple databases, then there's no support for the above pattern. You have to resort to one of the below two patterns, neither of which are very appealing:
- Build your own custom image with a custom config file, which usually means you need:
- a git repository to hold the config file and the custom Dockerfile
- a build pipeline to build the custom image
- an image repository (ECR, etc)
- multiple environment variables like
DATABASE_URL_1, DATABASE_URL_2, etc, to provide the actual connection strings referenced in the config file
- Use a janky workaround where you override the
ankane/pghero command and build the config file on the fly, then execute puma -C /app/config/puma.rb to start the service, like this:
echo 'databases:' > /app/config/pghero.yml && \
echo ' main:' >> /app/config/pghero.yml && \
echo ' url: <%= ENV["DATABASE_URL_1"] %>' >> /app/config/pghero.yml && \
echo ' secondary:' >> /app/config/pghero.yml && \
echo ' url: <%= ENV["DATABASE_URL_2"] %>' >> /app/config/pghero.yml && \
puma -C /app/config/puma.rb
Proposed solution
The app should look for environment variables named DATABASE_URL_1, DATABASE_URL_2, DATABASE_URL_N and use those without requiring any config file.
Thanks.
The problem
When you want to run pghero with one single database, you can pull the existing
ankane/pgheroDocker image and inject aDATABASE_URLvariable by way of your cloud platform (Amazon ECS task definition, etc). This is super easy because you don't need a build pipeline to build your own image, you don't need a git repository, etc. You just pull the image and run it with an environment variable.But if you use multiple databases, then there's no support for the above pattern. You have to resort to one of the below two patterns, neither of which are very appealing:
DATABASE_URL_1,DATABASE_URL_2, etc, to provide the actual connection strings referenced in the config fileankane/pgherocommand and build the config file on the fly, then executepuma -C /app/config/puma.rbto start the service, like this:Proposed solution
The app should look for environment variables named
DATABASE_URL_1,DATABASE_URL_2,DATABASE_URL_Nand use those without requiring any config file.Thanks.