Using Snaplet with GitHub Actions is a powerful combination to automate your development infrastructure requirements, like keeping a staging database automatically updated.
In this tutorial we'll show you how to create a GitHub Actions Workflow to capture a snapshot from your source database, and restore it to your target database at 4am every morning.
In order to restore snapshots you'll need:
- Setup a source database in Snaplet
- You've run the
snaplet setupcommand in your GitHub repository, which created a
.snaplet/config.jsonfile. This file associates your repository with your snapshots.
- A Snaplet CLI access token (opens in a new tab).
- A target database with superuser priviledges and a connection string to that database.
This GitHub Actions Workflow will capture a new snapshot in the cloud at 4am every day.
It installs the Snaplet CLI and runs the
snaplet snapshot create -y command.
- Create a
.github/workflowsdirectory in your repository on GitHub if this directory does not already exist.
- In the
.github/workflowsdirectory, create a file named
- Copy the following yaml into
This workflow runs every morning at 4am, and can also be manually triggered (opens in a new tab)
It checks out the repository, in order to access the
.snaplet/config.json, then it installs the Snaplet CLI and runs the
snaplet snapshot create command.
snaplet snapshot restore -y instead to restore the last captured snapshot rather than creating a new one.
We're almost done. The last step is to securely add our
SNAPLET_DATA_TARGET_DB_URL secrets to our GitHub repository.
- On GitHub.com, navigate to the main page of your GitHub repository.
- Under your repository name, click on Settings.
- In the left sidebar, click Secrets.
- Click New repository secret.
- Type a name for your secret in the Name input box and enter the value for your secret.
- Click Add Secret.