├── .github └── workflows │ └── ci.yml ├── Dockerfile ├── LICENSE ├── README.md ├── action.yml ├── entrypoint.sh └── test ├── .gitignore ├── index.js ├── package-lock.json ├── package.json └── sql └── 001.sql /.github/workflows/ci.yml: -------------------------------------------------------------------------------- 1 | name: CI 2 | 3 | on: [push, pull_request] 4 | 5 | jobs: 6 | test: 7 | runs-on: ubuntu-latest 8 | steps: 9 | - uses: actions/checkout@v1 10 | 11 | - uses: ./ 12 | with: 13 | postgresql password: test 14 | postgresql init scripts: test/sql 15 | 16 | - uses: actions/setup-node@v1 17 | 18 | - run: npm ci 19 | working-directory: test 20 | 21 | - run: node index.js 22 | working-directory: test 23 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM docker:stable 2 | 3 | COPY entrypoint.sh /entrypoint.sh 4 | 5 | ENTRYPOINT ["/entrypoint.sh"] 6 | 7 | EXPOSE $PORT 8 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 Harmon 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # PostgreSQL Docker Action 2 | 3 | This [GitHub Action](https://github.com/features/actions) sets up a PostgreSQL database. 4 | It utilizes the [PostgreSQL Docker](https://hub.docker.com/_/postgres) images. 5 | 6 | **Note**: This is a fork from [here](https://github.com/hank-cp/postgresql-action), which is a fork from [here](https://github.com/danielweller-swp/postgresql-action), and originally created [here](https://github.com/Harmon758/postgresql-action). 7 | It was first forked due to inactivity from the original maintainer. 8 | 9 | ## Usage 10 | 11 | See [action.yml](action.yml). 12 | 13 | Example: 14 | 15 | ```yaml 16 | steps: 17 | - uses: CasperWA/postgresql-action@v1.2 18 | with: 19 | postgresql version: '12' # See https://hub.docker.com/_/postgres for available versions 20 | postgresql db: my_db 21 | postgresql init scripts: init-db/sql 22 | postgresql conf: max_prepared_transactions=100 23 | postgresql port: 2345 24 | postgresql auth: trust 25 | ``` 26 | 27 | ## Inputs 28 | 29 | ### `postgresql version` 30 | 31 | **Optional**: Version of PostgreSQL to use. 32 | **Default**: `latest` 33 | 34 | ### `postgresql db` 35 | 36 | **Optional**: Name for the database that is created. 37 | **Default**: PostgreSQL default. 38 | 39 | ### `postgresql user` 40 | 41 | **Optional**: Create the specified user with superuser power. 42 | **Default**: PostgreSQL default. 43 | 44 | ### `postgresql password` 45 | 46 | **Optional**: Superuser password. 47 | **Default**: PostgreSQL default. 48 | 49 | ### `postgresql init scripts` 50 | 51 | **Optional**: Relative path (from repository root) to directory containing database init scripts. 52 | **Default**: PostgreSQL default. 53 | 54 | ### `postgresql conf` 55 | 56 | **Optional**: `postgres` configurations. 57 | **Default**: PostgreSQL default. 58 | 59 | ### `postgresql port` 60 | 61 | **Optional**: Port to bind to the docker. 62 | Also the port to be exposed by the docker. 63 | **Default**: `5432` 64 | 65 | ### `postgresql auth` 66 | 67 | **Optional**: Set auth-method for host connections (see [PostgreSQL docs](https://www.postgresql.org/docs/current/auth-pg-hba-conf.html) under _**`auth-method`**_ for list of recognized values and their meaning). 68 | **Default**: PostgreSQL default. 69 | 70 | ## License 71 | 72 | The scripts and documentation in this project are released under the [MIT License](LICENSE) 73 | -------------------------------------------------------------------------------- /action.yml: -------------------------------------------------------------------------------- 1 | name: Setup PostgreSQL 2 | description: Setup a PostgreSQL database 3 | author: Harmon 4 | branding: 5 | icon: database 6 | color: blue 7 | inputs: 8 | # See https://hub.docker.com/_/postgres for supported versions 9 | # and further details on input environment variables 10 | postgresql version: 11 | description: Version of PostgreSQL to use 12 | required: false 13 | default: latest 14 | postgresql db: 15 | description: POSTGRES_DB - name for the default database that is created 16 | required: false 17 | default: '' 18 | postgresql user: 19 | description: POSTGRES_USER - create the specified user with superuser power 20 | required: false 21 | default: '' 22 | postgresql password: 23 | description: POSTGRES_PASSWORD - superuser password 24 | required: false 25 | default: '' 26 | postgresql init scripts: 27 | description: POSTGRES_INIT_SCRIPTS - directory containing DB init scripts 28 | required: false 29 | default: '' 30 | postgresql conf: 31 | description: POSTGRES_CONF - postgres configurations 32 | required: false 33 | default: '' 34 | postgresql port: 35 | description: POSTGRES_PORT - port to bind to the docker 36 | required: false 37 | default: 5432 38 | postgresql auth: 39 | description: POSTGRES_AUTH - set auth method for host connections 40 | required: false 41 | default: '' 42 | runs: 43 | using: docker 44 | env: 45 | PORT: ${{ inputs.postgresql_port }} 46 | image: Dockerfile 47 | -------------------------------------------------------------------------------- /entrypoint.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | docker_run="docker run" 4 | docker_run="$docker_run -e POSTGRES_DB=$INPUT_POSTGRESQL_DB" 5 | docker_run="$docker_run -e POSTGRES_USER=$INPUT_POSTGRESQL_USER" 6 | docker_run="$docker_run -e POSTGRES_PASSWORD=$INPUT_POSTGRESQL_PASSWORD" 7 | docker_run="$docker_run -e POSTGRES_HOST_AUTH_METHOD=$INPUT_POSTGRESQL_AUTH" 8 | 9 | if [ ! -z "$INPUT_POSTGRESQL_INIT_SCRIPTS" ] 10 | then 11 | REPO=`echo "$GITHUB_REPOSITORY" | cut -d "/" -f 2` 12 | INIT_SCRIPT_PATH="/home/runner/work/$REPO/$REPO/$INPUT_POSTGRESQL_INIT_SCRIPTS" 13 | docker_run="$docker_run -v $INIT_SCRIPT_PATH:/docker-entrypoint-initdb.d" 14 | fi 15 | 16 | docker_run="$docker_run -d -p $INPUT_POSTGRESQL_PORT:5432 postgres:$INPUT_POSTGRESQL_VERSION" 17 | 18 | if [ ! -z "$INPUT_POSTGRESQL_CONF" ] 19 | then 20 | docker_run="$docker_run -c '$INPUT_POSTGRESQL_CONF'" 21 | fi 22 | 23 | sh -c "$docker_run" 24 | -------------------------------------------------------------------------------- /test/.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | -------------------------------------------------------------------------------- /test/index.js: -------------------------------------------------------------------------------- 1 | const { Client } = require('pg') 2 | 3 | async function run() { 4 | const client = new Client({ 5 | host: 'localhost', 6 | user: 'postgres', 7 | database: 'postgres', 8 | password: 'test', 9 | port: 5432 10 | }) 11 | await client.connect() 12 | const res = await client.query('SELECT * FROM Persons') 13 | const data = res.rows[0] 14 | if (data.personid != 1) { 15 | throw new Error("Unexpected PersonId") 16 | } 17 | await client.end() 18 | } 19 | 20 | async function sleep(ms) { 21 | return new Promise(resolve => { 22 | setTimeout(resolve, ms) 23 | }) 24 | } 25 | 26 | run().catch((err) => { 27 | console.error(err) 28 | process.exit(1) 29 | }) 30 | -------------------------------------------------------------------------------- /test/package-lock.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "test", 3 | "version": "1.0.0", 4 | "lockfileVersion": 1, 5 | "requires": true, 6 | "dependencies": { 7 | "buffer-writer": { 8 | "version": "2.0.0", 9 | "resolved": "https://registry.npmjs.org/buffer-writer/-/buffer-writer-2.0.0.tgz", 10 | "integrity": "sha512-a7ZpuTZU1TRtnwyCNW3I5dc0wWNC3VR9S++Ewyk2HHZdrO3CQJqSpd+95Us590V6AL7JqUAH2IwZ/398PmNFgw==" 11 | }, 12 | "packet-reader": { 13 | "version": "1.0.0", 14 | "resolved": "https://registry.npmjs.org/packet-reader/-/packet-reader-1.0.0.tgz", 15 | "integrity": "sha512-HAKu/fG3HpHFO0AA8WE8q2g+gBJaZ9MG7fcKk+IJPLTGAD6Psw4443l+9DGRbOIh3/aXr7Phy0TjilYivJo5XQ==" 16 | }, 17 | "pg": { 18 | "version": "7.13.0", 19 | "resolved": "https://registry.npmjs.org/pg/-/pg-7.13.0.tgz", 20 | "integrity": "sha512-ByCwYi39UrrPxu48WDPNj+osbhzFYe29EQpVyabfHZsfNfvXwQM/pZ86mRbJUlJf8J8GG3T36FjcKjSMmcjQfg==", 21 | "requires": { 22 | "buffer-writer": "2.0.0", 23 | "packet-reader": "1.0.0", 24 | "pg-connection-string": "0.1.3", 25 | "pg-pool": "^2.0.7", 26 | "pg-types": "^2.1.0", 27 | "pgpass": "1.x", 28 | "semver": "4.3.2" 29 | } 30 | }, 31 | "pg-connection-string": { 32 | "version": "0.1.3", 33 | "resolved": "https://registry.npmjs.org/pg-connection-string/-/pg-connection-string-0.1.3.tgz", 34 | "integrity": "sha1-2hhHsglA5C7hSSvq9l1J2RskXfc=" 35 | }, 36 | "pg-int8": { 37 | "version": "1.0.1", 38 | "resolved": "https://registry.npmjs.org/pg-int8/-/pg-int8-1.0.1.tgz", 39 | "integrity": "sha512-WCtabS6t3c8SkpDBUlb1kjOs7l66xsGdKpIPZsg4wR+B3+u9UAum2odSsF9tnvxg80h4ZxLWMy4pRjOsFIqQpw==" 40 | }, 41 | "pg-pool": { 42 | "version": "2.0.7", 43 | "resolved": "https://registry.npmjs.org/pg-pool/-/pg-pool-2.0.7.tgz", 44 | "integrity": "sha512-UiJyO5B9zZpu32GSlP0tXy8J2NsJ9EFGFfz5v6PSbdz/1hBLX1rNiiy5+mAm5iJJYwfCv4A0EBcQLGWwjbpzZw==" 45 | }, 46 | "pg-types": { 47 | "version": "2.2.0", 48 | "resolved": "https://registry.npmjs.org/pg-types/-/pg-types-2.2.0.tgz", 49 | "integrity": "sha512-qTAAlrEsl8s4OiEQY69wDvcMIdQN6wdz5ojQiOy6YRMuynxenON0O5oCpJI6lshc6scgAY8qvJ2On/p+CXY0GA==", 50 | "requires": { 51 | "pg-int8": "1.0.1", 52 | "postgres-array": "~2.0.0", 53 | "postgres-bytea": "~1.0.0", 54 | "postgres-date": "~1.0.4", 55 | "postgres-interval": "^1.1.0" 56 | } 57 | }, 58 | "pgpass": { 59 | "version": "1.0.2", 60 | "resolved": "https://registry.npmjs.org/pgpass/-/pgpass-1.0.2.tgz", 61 | "integrity": "sha1-Knu0G2BltnkH6R2hsHwYR8h3swY=", 62 | "requires": { 63 | "split": "^1.0.0" 64 | } 65 | }, 66 | "postgres-array": { 67 | "version": "2.0.0", 68 | "resolved": "https://registry.npmjs.org/postgres-array/-/postgres-array-2.0.0.tgz", 69 | "integrity": "sha512-VpZrUqU5A69eQyW2c5CA1jtLecCsN2U/bD6VilrFDWq5+5UIEVO7nazS3TEcHf1zuPYO/sqGvUvW62g86RXZuA==" 70 | }, 71 | "postgres-bytea": { 72 | "version": "1.0.0", 73 | "resolved": "https://registry.npmjs.org/postgres-bytea/-/postgres-bytea-1.0.0.tgz", 74 | "integrity": "sha1-AntTPAqokOJtFy1Hz5zOzFIazTU=" 75 | }, 76 | "postgres-date": { 77 | "version": "1.0.4", 78 | "resolved": "https://registry.npmjs.org/postgres-date/-/postgres-date-1.0.4.tgz", 79 | "integrity": "sha512-bESRvKVuTrjoBluEcpv2346+6kgB7UlnqWZsnbnCccTNq/pqfj1j6oBaN5+b/NrDXepYUT/HKadqv3iS9lJuVA==" 80 | }, 81 | "postgres-interval": { 82 | "version": "1.2.0", 83 | "resolved": "https://registry.npmjs.org/postgres-interval/-/postgres-interval-1.2.0.tgz", 84 | "integrity": "sha512-9ZhXKM/rw350N1ovuWHbGxnGh/SNJ4cnxHiM0rxE4VN41wsg8P8zWn9hv/buK00RP4WvlOyr/RBDiptyxVbkZQ==", 85 | "requires": { 86 | "xtend": "^4.0.0" 87 | } 88 | }, 89 | "semver": { 90 | "version": "4.3.2", 91 | "resolved": "https://registry.npmjs.org/semver/-/semver-4.3.2.tgz", 92 | "integrity": "sha1-x6BxWKgL7dBSNVt3DYLWZA+AO+c=" 93 | }, 94 | "split": { 95 | "version": "1.0.1", 96 | "resolved": "https://registry.npmjs.org/split/-/split-1.0.1.tgz", 97 | "integrity": "sha512-mTyOoPbrivtXnwnIxZRFYRrPNtEFKlpB2fvjSnCQUiAA6qAZzqwna5envK4uk6OIeP17CsdF3rSBGYVBsU0Tkg==", 98 | "requires": { 99 | "through": "2" 100 | } 101 | }, 102 | "through": { 103 | "version": "2.3.8", 104 | "resolved": "https://registry.npmjs.org/through/-/through-2.3.8.tgz", 105 | "integrity": "sha1-DdTJ/6q8NXlgsbckEV1+Doai4fU=" 106 | }, 107 | "xtend": { 108 | "version": "4.0.2", 109 | "resolved": "https://registry.npmjs.org/xtend/-/xtend-4.0.2.tgz", 110 | "integrity": "sha512-LKYU1iAXJXUgAXn9URjiu+MWhyUXHsvfp7mcuYm9dSUKK0/CjtrUwFAxD82/mCWbtLsGjFIad0wIsod4zrTAEQ==" 111 | } 112 | } 113 | } 114 | -------------------------------------------------------------------------------- /test/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "test", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "keywords": [], 10 | "author": "", 11 | "license": "ISC", 12 | "dependencies": { 13 | "pg": "^7.13.0" 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /test/sql/001.sql: -------------------------------------------------------------------------------- 1 | CREATE TABLE Persons ( 2 | PersonID int, 3 | LastName varchar(255), 4 | FirstName varchar(255), 5 | Address varchar(255), 6 | City varchar(255) 7 | ); 8 | 9 | INSERT INTO Persons VALUES (1, 'Last', 'First', 'TestAddress', 'TestCity'); 10 | --------------------------------------------------------------------------------