Skip to main content
In cases where you need more control over how your apps build and deploy when creating new preview environments, it is possible to leverage the Porter CLI in combination with custom CI actions to handle a wider range of workflows.

Using the CLI

Spinning up an isolated preview environment is as simple as running the following command:
porter apply -f porter.yaml --preview
This will create a new preview environment using the currently checked out branch.

Customizing Github Actions

Porter uses Github Actions to build and deploy your apps. When setting up preview environments, a workflow file with a name like porter-preview-<app-name>.yml will be created in your repository. You can customize this file to suit your needs. For example, it is possible to add conditionals to only run the workflow for specific branches or tags. This can be useful if you want to only create preview environments when a specific branch naming convention is used. If you only want to create preview environments for branches that start with feat/, you can add the following to your workflow file:
...
jobs:
  porter-deploy:
    runs-on: ubuntu-latest
    if: ${{ startsWith(github.head_ref, 'feat/') }}
    steps:
    - name: Checkout code
...
For more information on Github Actions, see the Github Actions documentation.

Opening a shell

In cases where you need to open a shell into a preview env’s running apps, you need to first retrieve the preview env name and then run porter app run:
  1. Retrieve the preview env name by running porter target list --preview. Copy the name of the preview env you’d like to open a shell into.
  2. Next, run porter app run <APP_NAME> -x <TARGET_NAME> -- <COMMAND> where <APP_NAME> is the name of the underlying app the preview env uses as a template, and <TARGET_NAME> is the preview env name you copied from running the first command. This will spin up a new replica and open a shell; if you wish to use an existing running replica, add the -e flag to porter app run.