Skip to main content

How do I configure GitHub Workflow for Deployment to an Ephemeral PR Preview Environment?

External Action

The configuration described here takes place outside of Wayfinder.


Prerequisites


Why do I need this configuration?

In this section you're configuring the .github/workflows/pr.yam file so when you commit your deployment manifests for the first time, then it will deploy your application to an ephemeral PR Preview environment and generate a PR preview link. On subsequent commits, it will redeploy your app component.


Update .github/workflows/pr.yaml

Update the .github/workflows/pr.yaml file as per the example.

In the section below you are assigning the values for the workspace access token's variables that you've created earlier.

        env:
WAYFINDER_SERVER: ${{ vars.WAYFINDER_SERVER }}
WAYFINDER_WORKSPACE: ${{ vars.WAYFINDER_WORKSPACE }}
WAYFINDER_TOKEN: ${{ secrets.WAYFINDER_TOKEN }}

In the section below you are:

  • creating your PR link for the PR review,
  • creating the environment (existing cluster) and finally,
  • deploying the component to the environment
        run: |
export ENV_NAME="pr-${{ github.event.pull_request.number }}"
wf create appenv --app MY_APP_NAME --env ${ENV_NAME} --cluster ${{ vars.PR_PREVIEW_CLUSTER }} --stage nonprod || true
wf deploy component MY_APP_NAME ${ENV_NAME} --component MY_COMPONENT_NAME --image ${IMAGE_TAG} --wait-for-ready 3m


Following below is the complete example that deploys your app and that creates a PR preview link for review.


name: build-publish

on:
pull_request:

build:
runs-on: ubuntu-latest
outputs:
tags: ${{ steps.meta.outputs.tags }}
- name: Login to docker registry
uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and Push to GitHub Packages
id: build-push
uses: docker/build-push-action@v2
continue-on-error: true
timeout-minutes: 3
with:
context: .
file: ./Dockerfile
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}

deploy-pr-preview:
needs:
- build
runs-on: ubuntu-latest
container:
image: quay.io/appvia-wf-dev/wftoolbox:latest
steps:
- name: Deploy to app environment
id: deploy
env:
WAYFINDER_SERVER: ${{ vars.WAYFINDER_SERVER }}
WAYFINDER_WORKSPACE: ${{ vars.WAYFINDER_WORKSPACE }}
WAYFINDER_TOKEN: ${{ secrets.WAYFINDER_TOKEN }}
IMAGE_TAG: ${{ needs.build.outputs.tags }}
run: |
export ENV_NAME="pr-${{ github.event.pull_request.number }}"
wf create appenv --app MY_APP_NAME --env ${ENV_NAME} --cluster ${{ vars.PR_PREVIEW_CLUSTER }} --stage nonprod || true
wf deploy component MY_APP_NAME ${ENV_NAME} --component MY_COMPONENT_NAME --image ${IMAGE_TAG} --wait-for-ready 3m



What comes next?