Skip to content

Repository files navigation

setup-postgres-action

This action handles the setup and teardown of a PostgreSQL database.

Prerequisites

This action does not provision WSL or Docker itself. On Windows runners it requires setup-wsl-action to run first in the same job — that action provisions WSL2 + Docker, keeps the instance alive, and exports the WSL_DISTRIBUTION, WSL_IP, and WSL_TOOLS_MODULE_PATH environment variables this action relies on. On Linux runners setup-wsl-action is a no-op but should still be included so the workflow is uniform.

If setup-wsl-action has not run, the action fails fast with a clear error.

Usage

See action.yml

steps:
- name: Setup WSL
  uses: Particular/setup-wsl-action@v1
- name: Setup Postgres
  uses: Particular/setup-postgres-action@v1.0.0
  with:
    connection-string-name: <my connection string name>
    init-script: /path/to/init-posgres.sql
    registry-login-server: index.docker.io
    registry-username: ${{ secrets.DOCKERHUB_USERNAME }}
    registry-password: ${{ secrets.DOCKERHUB_TOKEN }}}}    

connection-string-name is required. init-script is optional.

For logging into a container registry when running on Windows:

  • registry-login-server defaults to index.docker.io and is not required if logging into Docker Hub.
  • registry-username and registry-password are optional and will result in pulling the container anonymously if omitted.

On Linux runners the PostgreSQL container runs directly through Docker. On Windows runners the Linux PostgreSQL container runs inside WSL2 provisioned by setup-wsl-action — run it first, see Prerequisites.

License

The scripts and documentation in this project are released under the MIT License.

Development

Open the folder in Visual Studio Code. If you don't already have them, you will be prompted to install remote development extensions. After installing them, and re-opening the folder in a container, do the following:

Run the npm installation

npm install

When changing index.js, either run npm run dev beforehand, which will watch the file for changes and automatically compile it, or run npm run prepare afterwards.

Testing

With Node.js

To test the setup action an .env.setup file in the root directory with the following content

# Input overrides
INPUT_CONNECTION-STRING-NAME=PostgresConnectionString
INPUT_TAG=setup-postgres-action

# Runner overrides
# Use LINUX to run on Linux, WINDOWS to run on Windows via WSL2
RUNNER_OS=WINDOWS

then execute the script

node -r dotenv/config dist/index.js dotenv_config_path=.env.setup

To test the cleanup action add a .env.cleanup file in the root directory with the following content

# State overrides
STATE_IsPost=true
STATE_containerName=nameOfPreviouslyCreatedContainer
node -r dotenv/config dist/index.js dotenv_config_path=.env.cleanup

With PowerShell

To test the setup action set the required environment variables and execute setup.ps1 with the desired parameters.

$Env:RUNNER_OS=Windows
.\setup.ps1 -ContainerName psw-postgres-1 -ConnectionStringName PostgresConnectionString

To test the cleanup action set the required environment variables and execute cleanup.ps1 with the desired parameters.

$Env:RUNNER_OS=Windows
.\cleanup.ps1 -ContainerName psw-postgres-1

Running setup.ps1/cleanup.ps1 directly on Windows requires WSL_TOOLS_MODULE_PATH to point at setup-wsl-action's WslTools module (set it by running setup-wsl-action first).

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages