Skip to content

Commit

Permalink
feat(): v0.0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
sandy2008 committed Jul 31, 2022
0 parents commit 13f4225
Show file tree
Hide file tree
Showing 5 changed files with 123 additions and 0 deletions.
5 changes: 5 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
FROM postgres:alpine

COPY clone.sh /clone.sh
RUN chmod +x /clone.sh
ENTRYPOINT ["/clone.sh"]
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2022 Monoid Dev

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
28 changes: 28 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# PostgreSQL GitHub Action

This [GitHub Action](https://github.com/features/actions) will clone a PostgreSQL database from source to destination.

# Usage

See [action.yml](action.yml)

Basic:
```yaml
steps:
- uses: MonoidDev/clone-postgresql-action@v1
with:
from-host: 'host'
from-port: 'port'
from-username: 'username'
from-password: 'password'
from-database: 'db-name'
to-host: 'host'
to-port: 'port'
to-username: 'username'
to-password: 'password'
to-database: 'db-name'
```
# License
The scripts and documentation in this project are released under the [MIT License](LICENSE)
62 changes: 62 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
name: 'Clone PostgreSQL'
description: 'Clone a PostgreSQL database'
author: 'Monoid Dev'
branding:
icon: 'database'
color: 'blue'
inputs:
from-host:
description: 'Hostname of Source PostgreSQL'
required: true
default: 'localhost'
from-port:
description: 'Port of Source PostgreSQL'
required: true
default: '5432'
from-username:
description: 'Username of Source PostgreSQL'
required: true
default: 'username'
from-password:
description: 'Password of Source PostgreSQL'
required: true
default: 'password'
from-database:
description: 'Database Name of Source PostgreSQL'
required: true
default: 'db-name'
to-host:
description: 'Hostname of Remote PostgreSQL'
required: true
default: 'localhost'
to-port:
description: 'Port of Remote PostgreSQL'
required: true
default: '5432'
to-username:
description: 'Username of Remote PostgreSQL'
required: true
default: 'username'
to-password:
description: 'Password of Remote PostgreSQL'
required: true
default: 'password'
to-database:
description: 'Database Name of Remote PostgreSQL'
required: true
default: 'db-name'
runs:
using: 'docker'
image: 'Dockerfile'
args:
- ${{ inputs.from-host }}
- ${{ inputs.from-port }}
- ${{ inputs.from-username }}
- ${{ inputs.from-password }}
- ${{ inputs.from-database }}
- ${{ inputs.to-host }}
- ${{ inputs.to-port }}
- ${{ inputs.to-username }}
- ${{ inputs.to-password }}
- ${{ inputs.to-database }}

7 changes: 7 additions & 0 deletions clone.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/sh

# dump the database in custom-format archive
PGPASSWORD=$4 pg_dump -Fc -U $3 -h $1 -p $2 $5 > db.dump

# restore the database
PGPASSWORD=$9 pg_restore -U $8 -h $6 -p $7 -d ${10} db.dump --clean

0 comments on commit 13f4225

Please sign in to comment.