Live Preview
Tags: actionshackathon21
Published: 2021-11-26 02:47:17

### My Workflow

This project aims to provide temporary validation deployments that make the process of reviewing a PR easier by providing an environment in which the reviewer can verify if the changes are good-to-go from a user perspective. Its main advantage is to remove the requirement for pulling the branch code, building and running it locally.

Whenever the action is triggered, it will pull the application's Docker image (or images, if the project requires a docker-compose with multiple services), run it and magically expose it to the reviewers, posting the link to the application in a comment. The magic can be handled either by [Ngrok](https://ngrok.com/), a freemium tunneling service, or an open-source, self-hosted, [FRP (Fast Reverse Proxy)](https://github.com/fatedier/frp) server that works as a reverse proxy and tunneling platform.

As a demo we created a simple [Dockerfile](https://github.com/overhead-actions/live-preview-demos/blob/main/Dockerfile) with nginx and a [static html](https://github.com/overhead-actions/live-preview-demos/blob/main/static/index.html) page: https://github.com/overhead-actions/live-preview-demos/pull/1

{% github https://github.com/overhead-actions/live-preview-demos %}

![comment-pr](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0mkfp0uvzcoqk0bbmmo3.png)

![pipeline](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/eotncul008140bzgzj2m.png)
 
 

### Submission Category:

Maintainer Must-Haves

### Yaml Files

#### FRP (Fast Reverse Proxy)

- [Action](https://github.com/overhead-actions/live-preview-frp)
- [Workflow](https://github.com/overhead-actions/live-preview-demos/blob/main/.github/workflows/frp.yml)

```yml
name: Live Preview FRP

on: pull_request

jobs:
  default:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v2

      - name: Start services
        run: docker-compose up -d

      - name: Start tunnel
        uses: overhead-actions/live-preview-frp@main
        with:
          domain: ${{ github.head_ref }}.arthurbdiniz.com

      - name: Comment PR
        uses: unsplash/comment-on-pr@v1.3.0
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        with:
          msg: 'Here is your live preview URL 🚀: http://${{ github.head_ref }}.arthurbdiniz.com'
          check_for_duplicate_msg: false

      - name: Wait
        run: sleep 300
```

#### Ngrok

- [Action](https://github.com/overhead-actions/live-preview-ngrok)
- [Workflow](https://github.com/overhead-actions/live-preview-demos/blob/main/.github/workflows/ngrok.yml)

```yml
name: Live Preview NGROK

on: pull_request

jobs:
  default:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v2

      - name: Start services
        run: docker-compose up -d

      - name: Start tunnel
        uses: overhead-actions/live-preview@main
        with:
          protocol: http
          port: 4000
          ngrok_auth_token: ${{ secrets.NGROK_AUTH_TOKEN }}

      - name: Get URL
        id: vars
        run: echo "::set-output name=url::$(curl -s localhost:4040/api/tunnels | jq -r .tunnels[0].public_url)"

      - name: Comment PR
        uses: unsplash/comment-on-pr@v1.3.0
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        with:
          msg: 'Here is your live preview URL 🚀: ${{ steps.vars.outputs.url }}'
          check_for_duplicate_msg: false

      - name: Wait
        run: sleep 300
```

## Collaborators
 - [Arthur Diniz @arthurbdiniz](https://dev.to/arthurbdiniz)
 - [Victor Moura @victorcmoura](https://dev.to/victorcmoura)