Skip to content

oxfos/action-postgres-setup

Use this GitHub action with your project
Add this Action to an existing workflow or create a new one
View on Marketplace

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

34 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Action to establish a connection with and test Docker Postgres database (customizable).

  • 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.

Prerequisites

Docker Postgres image

Needed:

  • Docker image must be present (see example)
  • Docker image must have a POSTGRES_PASSWORD variable

Optional environment variables:

  • POSTGRES_USER (defaults to 'postgres')
  • POSTGRES_PASSWORD (defaults to 'postgres')
  • POSTGRES_DB (defaults to 'postgres')

Action step variables

Optional action parameters (correspond to those set in Docker image):

  • 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')

Usage examples

Simplest usage:

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
        ...

Custom usage (no real need):

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
        ...