I am using Github Actions Service Container to start a postgres instance like so:
name: Pull Request
on:
pull_request:
branches:
- main
- staging
jobs:
test-and-build:
runs-on: ubuntu-latest
services:
redis:
image: redis
ports:
- 6379:6379
postgres:
image: postgres
env:
POSTGRES_PASSWORD: postgres
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- 5432:5432
...
This works but I would like to speedup the postgres instance by disabling fsync as described here: https://dev.to/thejessleigh/speed-up-your-postgresql-unit-tests-with-one-weird-trick-364p
When running postgres locally in a docker container this speeds up my run massively, im hoping to do the same in Github Actions but am struggling to see how I configure the image. It appears that passing -c fsync=off
into the options block above causes an error:
Exit code 125 returned from process: file name '/usr/bin/docker', arguments 'create --name 04a7236d2e964fccb8a7d95684b3cf05_postgres_0249b3 --label cc4956 --network github_network_3023184aafab424896b4e553d7ad9c38 --network-alias postgres -p 5432:5432 --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5 -c fsync=off -e "POSTGRES_PASSWORD=postgres" -e GITHUB_ACTIONS=true -e CI=true postgres'.
Any ideas?
3
Answers
There does not seem to be a way to inject commands into services currently so that you can turn off the rsync feature. Github actions uses create command which does not support the
-c
attribute.But you could use a different image from
https://github.com/bitnami/bitnami-docker-postgresql
which allows you to turn it off through an env variable. Here is an example:Side note, this env is not documented in their readme, but you can find it in their source code
https://github.com/bitnami/bitnami-docker-postgresql/blob/b2b1c1410293fc9a8b58a52b56f2ceabdac59bb1/9.6/debian-10/rootfs/opt/bitnami/scripts/libpostgresql.sh#L433-L445
If you are willing to create your own dockerfile you can run a bash script to make any config changes you like. You can also execute sql commands in the same manner.
Dockerfile:
Example file in
docker-entrypoint-initdb.d/
In your docker compose, simply replace
image: postgres
withbuild:
pointing to this dockerfile.I’m not sure when this was added, but you can use POSTGRES_INITDB_ARGS to supply any args allowed for initdb: