Skip to main content

Spawn and Github Actions

Spawn is easy to integrate with Github Actions. We provide actions that plug directly into your workflows allowing you to use Spawn functionality without having to install and script spawnctl on your agents.

Most of the spawnctl commands have their own action:

If you've used spawnctl, the action inputs and outputs should be familiar. See the README.md in each action's repository to learn what inputs each action requires and what outputs it provides, or examine the example workflow below.

Example workflow#

The following example workflow shows how each of the available Github actions is used. The workflow runs through the following steps:

  • Create a data image
  • Create a data container from the image
  • Display the connection details for the new data container
  • Save and reset the data container
  • Delete the container and the image
name: Demo Spawn Actions
# Set up the workflow with a manual trigger.
on:
workflow_dispatch: {}
jobs:
demo-actions:
name: Demo Spawn Github Actions
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: create data image
id: create-image
uses: red-gate/create-spawn-data-image/@v1
with:
dataImageYaml: demo/github/image.yaml
lifetime: '5h'
- name: create data container
id: create-container
uses: red-gate/create-spawn-data-container/@v1
with:
dataImage: ${{ steps.create-image.outputs.dataImageName }}
lifetime: '5h'
- name: display connection details
run: |
echo "Connection details for the new container."
echo "Plug these into eg Flyway to do migration testing."
echo "These values are sensitive and will be masked."
echo "container name: $containerName"
echo "container host: $containerHost"
echo "container port: $containerPort"
echo "container username: $containerUsername"
echo "container password: $containerPassword"
env:
containerName: ${{ steps.create-container.outputs.dataContainerName }}
containerHost: ${{ steps.create-container.outputs.dataContainerHost }}
containerPort: ${{ steps.create-container.outputs.dataContainerPort }}
containerUsername: ${{ steps.create-container.outputs.dataContainerUsername }}
containerPassword: ${{ steps.create-container.outputs.dataContainerPassword }}
- name: save data container
uses: red-gate/save-spawn-data-container/@v1
with:
dataContainer: ${{ steps.create-container.outputs.dataContainerName }}
- name: reset data container
uses: red-gate/reset-spawn-data-container/@v1
with:
dataContainer: ${{ steps.create-container.outputs.dataContainerName }}
- name: delete data container
if: always()
uses: red-gate/delete-spawn-data-container/@v1
with:
dataContainer: ${{ steps.create-container.outputs.dataContainerName }}
- name: delete data image
if: always()
uses: red-gate/delete-spawn-data-image/@v1
with:
dataImage: ${{ steps.create-image.outputs.dataImageName }}
env:
SPAWNCTL_ACCESS_TOKEN: ${{ secrets.SPAWNCTL_ACCESS_TOKEN }}

Note that all of the actions require a SPAWNCTL_ACCESS_TOKEN secret available to the repository in which the workflow runs.

Feedback#

We welcome all feedback on the Github actions. Please open an issue or a pull request on the individual action repositories.