Skip to content
This repository was archived by the owner on Sep 19, 2024. It is now read-only.

Commit b8dbafd

Browse files
authored
Merge pull request #2 from rcknr/composite-update
Update and convert to composite action
2 parents f9ddcb1 + df47736 commit b8dbafd

File tree

7 files changed

+57
-1351
lines changed

7 files changed

+57
-1351
lines changed

.github/workflows/snaplet-restore.yml

Lines changed: 9 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -16,52 +16,37 @@ jobs:
1616
postgres:
1717
image: postgres:latest # Must match the database where snapshot was taken
1818
env:
19+
PGDATA: /data # Important: data location has to be changed as default is defined as a volume, so snapshot won't persist
1920
POSTGRES_PASSWORD: postgres
2021
POSTGRES_USER: postgres
21-
POSTGRES_DB: videolet
22+
POSTGRES_DB: snapshot
2223
options: >-
2324
--health-cmd pg_isready
2425
--health-interval 10s
2526
--health-timeout 5s
2627
--health-retries 5
28+
--name snapshot
2729
ports:
2830
- 5432:5432
2931

3032
steps:
3133
- name: Checkout Repository Code
3234
uses: actions/checkout@v2
33-
- uses: actions/setup-node@v2
34-
with:
35-
node-version: '16'
36-
cache: 'yarn'
37-
38-
- name: Install Dependencies
39-
run: yarn install --frozen-lockfile
40-
41-
- name: Build
42-
run: yarn build
43-
35+
4436
- name: Login to Docker Hub
4537
uses: docker/login-action@v1
4638
with:
4739
registry: ${{ secrets.GHCR_CONTAINER_REGISTRY_SERVER }}
4840
username: ${{ secrets.GHCR_CONTAINER_REGISTRY_USER }}
4941
password: ${{ secrets.GHCR_CONTAINER_REGISTRY_PASSWORD }}
5042

51-
- name: Install Snaplet
52-
run: curl -sL https://app.snaplet.dev/get-cli/ | bash
53-
5443
- name: Snaplet Restore
5544
uses: ./
5645
with:
57-
docker-container-registry-user: snaplet
58-
docker-image-name: publish-postgres-with-data-docker-action_database
46+
docker-container-name: snapshot
47+
docker-image-tag: ghcr.io/snaplet/publish-postgres-with-data-docker-action_database
48+
snaplet-database-url: postgres://postgres:postgres@localhost:5432/snapshot
5949
env:
6050
SNAPLET_ACCESS_TOKEN: ${{ secrets.SNAPLET_ACCESS_TOKEN }}
61-
SNAPLET_DATABASE_ID: ckq46skzy358532hraos3ptc7p
62-
SNAPLET_RESTORE_DB_NAME: videolet
63-
PGHOST: localhost
64-
PGUSER: postgres
65-
PGPASSWORD: postgres
66-
PGPORT: 5432
67-
PGDATABASE: videolet
51+
SNAPLET_PROJECT_ID: ${{ secrets.SNAPLET_PROJECT_ID }}
52+

README.md

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,26 @@
11
# Introduction
22

3-
Snaplet's Github action lets your create safe database snapshots on-demand.
3+
This action lets your restore a Snaplet snapshot into a Docker container and push it to your registry for later use.
4+
To use it you need to create a workflow with a service container running a database. This container will be populated with data and pushed to a registry.
45

56
# Inputs
67

7-
## `docker-container-registry-user`
8+
## `docker-container-name`
89

9-
**required** The name of docker registry user.
10+
**required** Name of the docker container running the database.
1011

11-
## `docker-container-registry-server`
12+
## `docker-image-tag`
1213

13-
The URL of docker registry server. Default `ghcr.io`
14+
**required** A tag to apply and push the image with. Must be fully qualified including registry URL e.g. `ghcr.io/snaplet/snaplet-snapshot:latest`.
1415

15-
## `docker-image-tag`
16+
## `snaplet-database-url`
17+
18+
**required** A connection string to use to restore a snapshot.
19+
20+
## `snaplet-restore-command`
1621

17-
The name of the docker image tag to use. Default `snaplet_database`.
22+
A command to run to restore a snapshot. Default `snaplet snapshot restore --latest`.
1823

1924
## Example usage
2025

21-
```
22-
uses: snaplet/publish-postgres-with-data-docker-action@main
23-
with:
24-
docker-container-registry-user: <docker-registry-user>
25-
docker-image-tag: <docker-image-tag>
26-
env:
27-
SNAPLET_ACCESS_TOKEN: ${{ secrets.SNAPLET_ACCESS_TOKEN }}
28-
SNAPLET_DATABASE_ID: <snaplet-database-id>
29-
PGHOST: localhost
30-
PGUSER: postgres
31-
PGPASSWORD: postgres
32-
PGPORT: 5432
33-
PGDATABASE: <restore-database-name>
34-
```
26+
Apart from inputs this action expects standard Snaplet environment variables to authenticate the CLI. See example workflow in `.github/workflows/snaplet-restore.yml`.

action.yml

Lines changed: 35 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,40 @@ name: Postgres Docker image with "baked-in" data
22
author: Snaplet, Inc.
33
description: Creates a Postgres Docker Image, with data from a Snaplet snapshot, for restoration in Codespaces, development environments.
44
inputs:
5-
docker-image-name:
6-
description: Name of docker image
7-
required: false
8-
default: snaplet_database
9-
docker-container-registry-server:
10-
description: URL of docker registry server
11-
required: false
12-
default: ghcr.io
13-
docker-container-registry-user:
14-
description: Name of docker registry user
5+
docker-container-name:
6+
description: Name of docker database container
7+
required: true
8+
type: string
9+
docker-image-tag:
10+
description: Tag for docker image
1511
required: true
12+
type: string
13+
snaplet-database-url:
14+
description: Connection string to restore a snapshot
15+
required: true
16+
type: string
17+
snaplet-restore-command:
18+
description: Command used to restore a snapshot
19+
required: false
20+
type: string
21+
default: snaplet snapshot restore --latest
1622
runs:
17-
using: "node12"
18-
main: "dist/index.js"
23+
using: "composite"
24+
steps:
25+
- name: Install Snaplet
26+
run: |
27+
curl -sS "https://app.snaplet.dev/get-cli/" | bash &> "/dev/null"
28+
echo "$HOME/.local/bin" >> "$GITHUB_PATH"
29+
shell: bash
30+
31+
- name: Restore snapshot
32+
run: ${{ inputs.snaplet-restore-command }}
33+
shell: bash
34+
env:
35+
SNAPLET_TARGET_DATABASE_URL: ${{ inputs.snaplet-database-url }}
36+
37+
- name: Commit and push Docker image
38+
run: |
39+
docker commit ${{ inputs.docker-container-name }} ${{ inputs.docker-container-tag }}
40+
docker push ${{ inputs.docker-container-tag }}
41+
shell: bash

0 commit comments

Comments
 (0)