如何在 Github 操作中将配置参数添加到 postgres 服务容器?
How to add config args to postgres service container in Github Action?
我正在使用 Github Actions Service Container 来启动一个 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
...
这可行,但我想通过禁用 fsync 来加速 postgres 实例,如下所述:https://dev.to/thejessleigh/speed-up-your-postgresql-unit-tests-with-one-weird-trick-364p
当 运行在本地 docker 容器中使用 postgres 时,这会大大加快我的 运行 速度,我希望在 Github 操作中做同样的事情,但我正在努力看看我是如何配置图像的。似乎将 -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'.
有什么想法吗?
目前似乎没有办法将命令注入服务,以便您可以关闭 rsync 功能。 Github 操作使用不支持 -c
属性的创建命令。
但是您可以使用与 https://github.com/bitnami/bitnami-docker-postgresql
不同的图像,这样您就可以通过环境变量将其关闭。这是一个例子:
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
旁注,他们的自述文件中没有记录此环境,但您可以在他们的源代码中找到它
https://github.com/bitnami/bitnami-docker-postgresql/blob/b2b1c1410293fc9a8b58a52b56f2ceabdac59bb1/9.6/debian-10/rootfs/opt/bitnami/scripts/libpostgresql.sh#L433-L445
如果您愿意创建自己的 docker 文件,您可以 运行 一个 bash 脚本来进行任何您喜欢的配置更改。您也可以以相同的方式执行 sql 个命令。
Docker 文件:
FROM postgres
COPY docker-entrypoint-initdb.d/ /docker-entrypoint-initdb.d/
RUN ["chmod", "-R", "+x", "/docker-entrypoint-initdb.d/"]
docker-entrypoint-initdb.d/
中的示例文件
#!/bin/bash
echo -e '\nfsync = off' >> /var/lib/postgresql/data/postgresql.conf
在您的 docker 撰写中,只需将 image: postgres
替换为指向此 docker 文件的 build:
。
我正在使用 Github Actions Service Container 来启动一个 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
...
这可行,但我想通过禁用 fsync 来加速 postgres 实例,如下所述:https://dev.to/thejessleigh/speed-up-your-postgresql-unit-tests-with-one-weird-trick-364p
当 运行在本地 docker 容器中使用 postgres 时,这会大大加快我的 运行 速度,我希望在 Github 操作中做同样的事情,但我正在努力看看我是如何配置图像的。似乎将 -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'.
有什么想法吗?
目前似乎没有办法将命令注入服务,以便您可以关闭 rsync 功能。 Github 操作使用不支持 -c
属性的创建命令。
但是您可以使用与 https://github.com/bitnami/bitnami-docker-postgresql
不同的图像,这样您就可以通过环境变量将其关闭。这是一个例子:
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
旁注,他们的自述文件中没有记录此环境,但您可以在他们的源代码中找到它 https://github.com/bitnami/bitnami-docker-postgresql/blob/b2b1c1410293fc9a8b58a52b56f2ceabdac59bb1/9.6/debian-10/rootfs/opt/bitnami/scripts/libpostgresql.sh#L433-L445
如果您愿意创建自己的 docker 文件,您可以 运行 一个 bash 脚本来进行任何您喜欢的配置更改。您也可以以相同的方式执行 sql 个命令。
Docker 文件:
FROM postgres
COPY docker-entrypoint-initdb.d/ /docker-entrypoint-initdb.d/
RUN ["chmod", "-R", "+x", "/docker-entrypoint-initdb.d/"]
docker-entrypoint-initdb.d/
#!/bin/bash
echo -e '\nfsync = off' >> /var/lib/postgresql/data/postgresql.conf
在您的 docker 撰写中,只需将 image: postgres
替换为指向此 docker 文件的 build:
。