This repo demonstrates the following CI pipeline:
- Deploying a Preevy environment per pull request on a Kubernetes server provisioned on GKE
- Offloading the build to an external Kubernetes build driver and using GAR as an image registry.
- Optionally linking the environment to a Livecycle playground
- Integration with GitHub: automatic PR comment, creation of GH deployment and environment (see below).
- Preevy will build the Compose app on a Kubernetes builder in GKE and store the images in GAR.
- Preevy will provision an environment on the GKE cluster with this PR content.
- A comment with the environment URLs will be posted on the PR.
- A GH environment will be created (named
pr-NNN
, where NNN is the PR number) and shown on the repo main page.
- Preevy will delete the provisioned environment in Kubernetes.
- The PR comment will be updated to reflect the fact that the Preevy environment no longer exists.
- The GH environment will be deleted (optional, see below).
- Create a GKE cluster or use an existing one. Note: Autopilot clusters are not currently supported, because they do not allow privileged containers which are required by Preevy.
- Create a Kubernetes builder in the GKE cluster. This is as simple as running
docker buildx create --driver kubernetes
. - Create a preevy profile using the Preevy init command and store it in a Google Cloud Storage bucket.
- Create the
PREEVY_PROFILE_URL
GitHub Actions environment variable and set it to the Preevy profile URL. - Create a GCE service account, make sure it has the proper permissions to access the GKE cluster. Download its credentials JSON file and paste it into the GitHub Actions secret
PREEVY_SA_KEY
. - Copy the
preevy_up.yaml
andpreevy_down.yaml
GitHub Actions workflows to your repo.
To use a Livecycle playground, create a livecycle.dev account and follow the instructions on installing the Livecycle SDK to receive an API key. Store it as a GitHub Actions secret LIVECYCLE_API_KEY
.
To delete GH deployments and environments on PR closure, you need to setup a private GH App which will be used by the GHA flows. This is beacuse the default GITHUB_TOKEN
does not have enough permissions to delete those resources.
To disable this feature, remove the last steps of the preevy_down.yaml
workflow as documented in the file itself. You will have to remove the environments manually from the repo's "Environments" page.
After setting up the GH app:
- Set the GHA secret
GH_APP_PRIVATE_KEY
to the app private key. - Set the GHA var
GH_APP_ID
to the app id. - Install the app at the repo.
The demo Compose app in this repo is taken from the react-express-mysql
sample Compose app from the Awesome Compose project by Docker. See the app README for details.