GitHub Action
Postgres client with custom settings
v1
Latest version
- Written in yml and JavaScript.
- Based on Docker Postgres image, Node pg package.
- Establishes a connection with the Postgres database (sets up the client), populates the client with data, and retrieves data. It basically refactors code to create a service container (explained here) into a GitHub Action and adds possibility to define extra database parameters.
- To be used in GitHub Actions.
- Docker image must be present (see example)
- Docker image must have a POSTGRES_PASSWORD variable
- POSTGRES_USER (defaults to 'postgres')
- POSTGRES_PASSWORD (defaults to 'postgres')
- POSTGRES_DB (defaults to 'postgres')
- POSTGRES_HOST (defaults to 'localhost')
- POSTGRES_PORT (defaults to '5432')
- POSTGRES_USER (defaults to 'postgres')
- POSTGRES_PASSWORD (defaults to 'postgres')
- POSTGRES_DB (defaults to 'postgres')
name: PostgreSQL test
on: push
jobs:
myjob:
runs-on: ubuntu-latest
services:
postgres:
# Docker Hub image
image: postgres
env:
POSTGRES_PASSWORD: postgres
# Set health checks to wait until postgres has started
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
# Maps tcp port 5432 on service container to the host
- 5432:5432
steps:
- name: Check out repository code
# Downloads a copy of the code in your repository
uses: actions/checkout@v2
- name: Create, populate & query PostgreSQL
# Runs a script that creates a PostgreSQL client, populates
# the client with data, and retrieves data
uses: Oxfos/action-postgres-setup@v1
# Environment variables used by the `index.js` script to create
# a new PostgreSQL client: not necessary if using default values.
# whatever additional steps you may want to add here
- name: name of your step
...
name: PostgreSQL test
on: push
jobs:
myjob:
runs-on: ubuntu-latest
services:
postgres:
# Docker Hub image
image: postgres
env:
POSTGRES_PASSWORD: postgres
POSTGRES_USER: your_user
POSTGRES_PASSWORD: my_password
POSTGRES_DB: my_db
# Set health checks to wait until postgres has started
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
# Maps tcp port 5432 on service container to the host
- 5432:5432
steps:
- name: Check out repository code
# Downloads a copy of the code in your repository
uses: actions/checkout@v2
- name: Create, populate & query PostgreSQL
# Runs a script that creates a PostgreSQL client, populates
# the client with data, and retrieves data
uses: Oxfos/action-postgres-setup@v1
# Environment variables used by the `index.js` script to create
# a new PostgreSQL client.
with:
# The hostname used to communicate with the PostgreSQL service container
POSTGRES_HOST: your_host
# The default PostgreSQL port
POSTGRES_PORT: your_port
# Other parameters to access the database
POSTGRES_USER: your_user
POSTGRES_PASSWORD: my_password
POSTGRES_DB: my_db
# whatever additional steps you may want to add here
- name: name of your step
...