PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Sunday, October 9, 2022

[FIXED] How to add config args to postgres service container in Github Action?

 October 09, 2022     continuous-integration, docker, github, github-actions, postgresql     No comments   

Issue

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?


Solution

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:

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



Answered By - Edward Romero
Answer Checked By - Terry (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing