Flow Preview Environments
Easily create a first class PR preview environment experience within Flows
Overview
Preview environments are a powerful software testing pattern whereby you create a near clone of a dev environment with the code of a feature branch during the duration of a pull request. This has a few great benefits:
- Reduces churn in your dev environment, improving overall stability - which is a common failure in large organizations with many in-flight changes
- Makes it easier to test code in isolation - the code only has the changes happening in your branch
- Reduces dev data corruption issues - true if you implement database forking as part of the preview, making it easy to test things like schema migrations
This is extremely easy to implement with Plural because of a few things:
- GitOps patterns make it really easy to redeploy and reconfigure services
- Plural already has the webhook and event system to track PR updates natively implemented within its server
- Plural also already has a secure way of managing SCM credentials, so it can natively implement the Github/Gitlab comment feedback to make an ideal DevEx around preview environments
Demo Video
If you just want to see it in action, here's a quick YouTube video demo:
How to Implement
Implementing preview environments is quite simple. You functionally just need to register one custom resource, a PreviewEnvironmentTemplate like below:
yaml
apiVersion: deployments.plural.sh/v1alpha1
kind: PreviewEnvironmentTemplate
metadata:
name: test
spec:
flowRef:
kind: Flow
name: flow-test
referenceServiceRef:
kind: ServiceDeployment
name: flow-test-dev
namespace: flow-test
template:
namespace: "flow-test-pr-{{ pr.number }}"
name: "flow-test-pr-{{ pr.number }}"
syncConfig:
deleteNamespace: true # ensure the temp namespace is deleted on cleanup
helm:
values:
image:
tag: "sha-{{ commitSha | slice: 0, 7 }}"
ingress:
hosts:
- host: flow-test-pr-{{ pr.number }}.your.domain # give a unique pr domain for the environment
paths:
- path: /
pathType: ImplementationSpecific
tls:
hosts:
- flow-test-pr-{{ pr.number }}.your.domain # also ensure certs still work
secretName: flow-test-pr-{{ pr.number }}-tls