This repository contains source code for a sample Next.js application that's used in conjunction with a set of Kubernetes manifests. These work in tandem with Neon's branching feature to create unique preview environments, each with their own unique serverless Postgres database.
- Each PR opened against the repository will trigger workflow that:
- Builds the Next.js application into a container image.
- Creates a Neon branch to use in the preview environment.
- An Argo CD Argo CD ApplicationSet will detect the PR and create a namespace on your Kubernetes cluster to deploy the new container image.
- Once the workflow associated with a pull request is complete it will:
- Update the Argo-managed preview environment with the Neon branch Postgres connection string and container image tag.
- Comment on the pull request with a link to the preview environment.
A Kubernetes cluster is required to run this sample. The manifests repository contains instructions and a script to configure a local Kubernetes environment and Argo CD instance.
To run the GitHub Actions workflow, add the following secrets to your fork of this repository using the Settings > Secrets and variables > Actions screen:
DOCKERHUB_TOKEN
- A token with write access to a repository on Docker Hub. Created from the Account Settings / Security page on Docker Hub.DOCKERHUB_USERNAME
- The username that owns theneon-kube-previews
repository that the container image will be written to.NEON_API_KEY
- Found in the Developer Settings screen on the Neon console.NEON_PROJECT_ID
- Found in Settings > General on the Neon project dashboard.ARGOCD_HOSTNAME
- Strictly the hostname, e.gargocd.foo.bar
withouthttps
.ARGOCD_USERNAME
- A valid Argo CD username. You can can useadmin
if you're prototyping.ARGOCD_PASSWORD
- The password associated with the givenARGOCD_USERNAME
.PREVIEW_SUBDOMAIN
- The subdomain that hosts preview environments, e.gneon.ngrok.app
. This will be used to form a full preview environment URL, i.ehttps://pr-1.${PREVIEW_SUBDOMAIN}
Note: Feel free to replace Docker Hub with Quay.io or your preferred container registry in the GitHub Actions workflow.
If you're unfamiliar with how to add secrets to a GitHub repository, you can learn more in GitHub's documentation.