[英]How to add config args to postgres service container in Github Action?
I am using Github Actions Service Container to start a postgres instance like so:我正在使用 Github 操作服务容器来启动 postgres 实例,如下所示:
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这可行,但我想通过禁用 fsync 来加速 postgres 实例,如下所述: 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.当在 docker 容器中本地运行 postgres 时,这会大大加快我的运行速度,我希望在 Github 操作中做同样的事情,但我很难看到我如何配置图像。 It appears that passing -c fsync=off
into the options block above causes an error:似乎将-c fsync=off
传递到上面的选项块会导致错误:
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?有任何想法吗?
There does not seem to be a way to inject commands into services currently so that you can turn off the rsync feature.目前似乎没有办法将命令注入服务,以便您可以关闭 rsync 功能。 Github actions uses create command which does not support the -c
attribute. Github 操作使用不支持-c
属性的 create 命令。
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.但是您可以使用与https://github.com/bitnami/bitnami-docker-postgresql
不同的图像,它允许您通过 env 变量将其关闭。 Here is an example:这是一个例子:
name: Postgress test
on:
push:
jobs:
test:
runs-on: ubuntu-latest
services:
postgres:
image: 'bitnami/postgresql:latest'
env:
POSTGRESQL_DATABASE: test_postgress
POSTGRESQL_USERNAME: test_user
POSTGRESQL_PASSWORD: test_password
POSTGRESQL_FSYNC: "off"
options: >-
--health-cmd "pg_isready -d test_postgress -U test_user -p 5432"
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- 5432:5432
steps:
- run: echo test
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旁注,此环境未在其自述文件中记录,但您可以在其源代码https://github.com/bitnami/bitnami-docker-postgresql/blob/b2b1c1410293fc9a8b58a52b56f2ceabdac59bb1/9.6/debian-10/rootfs中找到它/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.如果您愿意创建自己的 dockerfile,您可以运行 bash 脚本来进行任何您喜欢的配置更改。 You can also execute sql commands in the same manner.您也可以以相同的方式执行 sql 命令。
Dockerfile: Dockerfile:
FROM postgres
COPY docker-entrypoint-initdb.d/ /docker-entrypoint-initdb.d/
RUN ["chmod", "-R", "+x", "/docker-entrypoint-initdb.d/"]
Example file in docker-entrypoint-initdb.d/
docker-entrypoint-initdb.d/
中的示例文件
#!/bin/bash
echo -e '\nfsync = off' >> /var/lib/postgresql/data/postgresql.conf
In your docker compose, simply replace image: postgres
with build:
pointing to this dockerfile.在您的 docker 组合中,只需将image: postgres
替换为build:
指向此 dockerfile。
I'm not sure when this was added, but you can use POSTGRES_INITDB_ARGS to supply any args allowed for initdb :我不确定何时添加,但您可以使用 POSTGRES_INITDB_ARGS 提供initdb 允许的任何参数:
services:
postgres:
image: postgres
env:
POSTGRES_PASSWORD: postgres
POSTGRES_INITDB_ARGS: --no-sync
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- 5432:5432
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.