Create Preview Deployments on Forge with Laravel Harbor

Laravel Harbor is a CLI tool that allows you to quickly create on-demand preview environments for your app on Laravel Forge. Using this CLI, you can use GitHub actions to automatically deploy your branches when pull requests are created and tear down the deployment from your server when the pull request is merged. Here's an example of a provisioning workflow using GitHub actions (taken from the documentation):

name: preview-provision
on:
  pull_request:
    types: [opened, edited, reopened, ready_for_review]
jobs:
  harbor-provision:
    if: |
      github.event.pull_request.draft == false &&
      contains(github.event.pull_request.title, '[harbor]')
    runs-on: ubuntu-latest
    container:
      image: kirschbaumdevelopment/laravel-test-runner:8.1
    steps:
      - name: Install Harbor via Composer
        run: composer global require mehrancodes/laravel-harbor -q
      - name: Start Provisioning
        env:
            FORGE_TOKEN: ${{ secrets.FORGE_API_TOKEN }}
            FORGE_SERVER: ${{ secrets.FORGE_SERVER_ID }}
            FORGE_GIT_REPOSITORY: ${{ github.repository }}
            FORGE_GIT_BRANCH: ${{ github.head_ref }}
            FORGE_DOMAIN: harbor.com
        run: harbor provision

Once you've configured this CLI to run with GitHub actions, pull requests will get updated comments with test environment details, making it easy to see what your preview environment is for testing a feature:

Other features include:

To get started with Harbor and read the official docs, check out laravel-harbor.com. You'll need to have a Laravel Forge account as well; see Harbor's Prerequisites for details. Also, the CLI's source code is available on GitHub at mehrancodes/laravel-harbor if you want to check it out.


The post Create Preview Deployments on Forge with Laravel Harbor appeared first on Laravel News.

Join the Laravel Newsletter to get all the latest Laravel articles like this directly in your inbox.