This is an example of using Github actions to automatically deploy an app to preview changes and spin down the app once the PR is closed.
This repository includes two GitHub workflows to automate preview deployments of your application using the deploy demo app as an example:
The preview.yml
workflow automatically deploys a preview app for every pull request, enabling reviewers to test the changes introduced in the PR in a separate app in a selected Aptible environment.
What this workflow does:
- Triggers on pull request creation and when pushing changes to the pull request
- Creates a PostgreSQL database and Redis database for the preview app
- Configures a new Aptible app configured with the necessary environment variables to connect to the databases from the previous step
- Builds and pushes a Docker image tagged with the PR number
- Deploys the application to Aptible using the image built in the previous step
- Creates an HTTPS endpoint for accessing the preview app
Inputs:
-
Required inputs (must be configured as GitHub secrets):
vars.APTIBLE_ROBOT_USERNAME
: Aptible robot account email for authenticationsecrets.APTIBLE_ROBOT_PASSWORD
: Aptible robot account passwordsecrets.DOCKERHUB_USERNAME
: DockerHub username for pushing images and deploying to Aptiblesecrets.DOCKERHUB_TOKEN
: DockerHub access token for authenticationsecrets.DOCKERHUB_PASSWORD
: DockerHub password for Deploy to Aptible step
-
Configurable environment variables (can be modified in the workflow file):
APTIBLE_ENVIRONMENT
: The Aptible environment to deploy to (default:preview-apps
)IMAGE_NAME
: Docker image name to use (default:aptible/deploy-demo-app
)APTIBLE_APP_NAME
: Name pattern for the Aptible app (default:demo-pr-${{ github.event.number }}
)TAG
: Docker image tag to use (default:pr-${{ github.event.number }}
)
The deprovision_preview.yml
workflow handles the cleanup of preview resources when a pull request is closed.
What this workflow does:
- Triggers when a pull request is closed (merged or rejected)
- Deprovisions the Aptible app and endpoint associated with the PR
- Deprovisions the PostgreSQL and Redis databases created for the preview
Inputs:
-
Required inputs (must be configured as GitHub secrets and variables):
vars.APTIBLE_ROBOT_USERNAME
: Aptible robot account email for authenticationsecrets.APTIBLE_ROBOT_PASSWORD
: Aptible robot account password
-
Configurable environment variables (can be modified in the workflow file):
APTIBLE_ENVIRONMENT
: The Aptible environment to deploy to (default:preview-apps
)APTIBLE_APP_NAME
: Name pattern for the Aptible app (default:demo-pr-${{ github.event.number }}
)
These workflows cover the simplest use case, so they can be customized further using the options provided by using different events to trigger the workflows. The push and pull_request event documentation in particular includes practical examples for everyday use cases.
Copyright (c) 2025 Aptible. All rights reserved.