Experiment: Deploy Preview with GH Actions

I was testing out something.

We can use GH actions to run preview app environments.

Something like FeaturePeek or Jenkins X Preview Environments .

WARNING::moneybag::moneybag::moneybag: this is suited for self-hosted runners only! You risk a high charge

The gist:

Assume you have a self-hosted runner available at:
http://my-test-runner.yolo.com

And a pseudo workflow:

name: Launch Apps
on:
  pull_request:
    branches: ["*"]
jobs:
  launch-app:
    runs-on: [self-hosted, linux]
    container:
      image: node:13
      ports:
        - 25666:25666
      options: --cpus 0
    steps:
      - uses: actions/checkout@v2
      - name: Run docs
        run: cd docs && npx serve -l 25666

Our docs page will be accessible at:
http://my-test-runner.yolo.com:25666

The app will be available until a timeout of six hours.

Related thoughts:

  • If we don’t assign a static port, docker will randomize it and we extract it and post a link to a PR. We can run many review apps on powerful machine
  • We can many GH action runners on a single powerful machine
  • Native GH action containers will automatically garbage collect
  • We will need a cleanup script for previous workflow runs styfle/cancel-workflow-action@0.4.1
  • We can use docker run to run arbitrary image but we will need smarter cleanup scripts
1 Like

Hi @molszanski,

Thanks for your sharing!

The 6 hour timeout limitation is NOT applied to self-hosted runner, please refer to the doc here for the details.

All of your steps are executed in the container, for the cleanup, probably can be done by removing container on the runner.

If you have any questions, you are always to raise a ticket here.