Pull request previews with WunderPreview and Spawn

Andrew Farries
Spawn DB
Published in
3 min readJul 21, 2021

Level up your pull request workflow with live preview environments backed by dedicated databases

Photo by Michal Matlon on Unsplash

WunderPreview provides all stakeholders in a software project with a window into the work in progress features of an application. By building your application on every pull request and publishing it for all team members to see, visibility is increased and feedback is given earlier, tightening the build, test, deploy cycle.

What can I preview?

Essentially, anything that builds as a Docker container and exposes a TCP port to which other services can connect. This makes WunderPreview well suited to traditional 3 tier web applications as well as more complex microservice architectures.

Using WunderPreview is a three step process:

  • Sign up with WunderPreview.
  • Link the Github repositories for which you want previews.
  • Point WunderPreview at the Dockerfilefor the application build.

WunderPreview will then start building and publishing live previews for your pull requests.

What about my database?

WunderPreview offers a single Postgres instance per Github organisation. You can use this database from your preview environments by plugging the relevant environment variables into your app.

For some applications and organisations a single database instance will be enough, but you might bump up against limitations of this approach: if the PR you are previewing makes database schema changes, preview environments of other PRs may be broken by your changes. The same can be said for previews of PRs that require specific data to demonstrate a new feature — the data that one PR adds to the shared database will be visible to all previews. In an ideal world, we would give each preview environment its own dedicated, isolated database.

Spawn

Spawn is a service for provisioning ephemeral, cloud-hosted databases for development workflows and CI pipelines. The basic workflow is:

  • Create a data image. This is often a sanitised copy of production.
  • Create data containers. Each data container is based on a data image, is fully isolated from other data containers and starts in seconds regardless of the image size.

Put together, Spawn and WunderPreview allow you to create live preview environments for every commit, with each preview backed by its own dedicated database.

Show me the code

We’ve published a three tier web application as an example of what can be done with WunderPreview and Spawn. The architecture looks like this:

architecture of the demo application

The backend code lives here and the frontend is here.

Every time the backend C# API container starts it creates fresh copies of the todo and account databases, using Spawn:

creating data containers on application startup

This means that every time you run the backend, you are working with a completely fresh, isolated copy of the database.

When the application starts up, Flyway is used to migrate our database to the desired state:

applying migrations to our data containers

Every preview now starts with its own dedicated database, making it fully independent of other previews. Schema changes can be made safely on each branch and will only affect their own preview.

Conclusion

WunderPreview gives you live preview environments for every commit in your pull request. Use it to to aid PR reviews and demo work in progress features of your application.

Spawn allows you to go beyond a single database instance backing all your preview environments, giving each preview its own dedicated, isolated database instance. Pull requests that modify the database schema, or add specific data can do so without impacting preview environments on other branches.

Sign up with WunderPreview and Spawn for free today!

--

--