Building and publishing applications to Fastly from CI

Applications written for Compute services can be compiled and tested outside the Fastly platform in many popular CI tools such as Jenkins, CircleCI or GitHub Actions. We have our own GitHub actions for Fastly, described below, or just use the Fastly CLI in other environments.

Code written for VCL services can only be compiled by Fastly. As a result the value of running automations for VCL services is lower, and while there are no tools created specifically to assist with automating processes relating to VCL services, many Fastly customers use Terraform or other orchestration tools to manage Fastly services, and those tools often have excellent support for running in CI environments. Learn more about using orchestration tools with Fastly.

GitHub Actions

GitHub Actions is a popular tool for running tasks on repositories in response to events such as pull requests being opened or merged. You can create workflows in GitHub Actions similarly to other CI tools by configuring the workflow to install and run the Fastly CLI, however we have created a set of pre-packaged workflows which make building and deploying Compute applications easier.

To compile and deploy a Compute service at the root of the repository, you can use the fastly/compute-actions main action. The following workflow will install the Fastly CLI, build your project (with dependencies and toolchains for the appropriate language), and deploy it to your Fastly service:

  1. Rust
  2. JavaScript
name: Deploy Application
on:
push:
branches: [master]
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install Rust toolchain
uses: actions-rs/toolchain@v1
with:
toolchain: 1.54.0 # current Rust toolchain for the Compute platform
target: wasm32-wasi # WebAssembly target
- name: Deploy to the Compute platform
uses: fastly/compute-actions@v5
env:
FASTLY_API_TOKEN: ${{ secrets.FASTLY_API_TOKEN }}

Custom Workflows

Alternatively, you can manually run the individual GitHub Actions for the Compute platform if you want finer control over your workflow:

  • fastly/compute-actions/setup - Download the Fastly CLI if not already installed
  • fastly/compute-actions/build - Build a Compute project. Equivalent to fastly compute build
  • fastly/compute-actions/deploy - Deploy a Compute project. Equivalent to fastly compute deploy
  • fastly/compute-actions/preview - Deploy a Compute project to a new Fastly Service, which is deleted when the pull-request is merged or closed.

For example, each time you open or update a pull request, you could create a temporary Fastly service to run the Compute application using the code updated in the PR, so you can test out the proposed change on the live Fastly platform before you merge the PR:

name: Fastly Compute Branch Previews
concurrency:
group: ${{ github.head_ref || github.run_id }}-${{ github.workflow}}
on:
pull_request:
types: [opened, synchronize, reopened, closed]
jobs:
deploy:
runs-on: ubuntu-latest
defaults:
run:
shell: bash
steps:
- uses: actions/checkout@v4
- uses: fastly/compute-actions/preview@v5
with:
fastly-api-token: ${{ secrets.FASTLY_API_KEY }}
github-token: ${{ secrets.GITHUB_TOKEN }}

See the full documentation on GitHub for the actions for more examples and details about each of the possible input properties.

Using the Fastly CLI in CI

Nearly any CI environment can run the Fastly CLI, and it's a great way to automate the process of building and deploying Compute apps. To validate that your code builds, use fastly compute build and to deploy, fastly compute publish.

The --non-interactive flag can be used with many CLI commands to suppress prompts and ensure the process does not hang.