Introducing GitHub Actions for Compute@Edge, a new resource to help ship your code to the edge

One of the guiding principles for Compute@Edge, which is used to build, test, and deploy code in our serverless compute environment, is to make the developer experience as seamless and ergonomic as possible. As part of the Developer Relations team, I get to build lots of exciting tools on top of our own platform, and this is a great way to find areas where we can improve the experience for developers. Driven from this first-hand need to rapidly deploy applications to Fastly, today we’re introducing GitHub Actions for Compute@Edge

Let’s dig in on what’s new and how it’s different to the VCL deployment workflows you may be used to.

Infrastructure as code = automated deployments

For customers using VCL to create edge logic in their Fastly services, you give us your VCL code in source form (either via the API or entered into our web interface), then we run our own compiler to convert the VCL into highly optimized and secure C and run it as native code on our edge servers.

While entering code into a web UI may be convenient, customers with complex services quickly move beyond looking at their VCL as “configuration,” and many consider it to be an integral part of the architecture of their overall system. Even if your Fastly service is incredibly simple, the modern philosophy of treating all infrastructure as code means that whether or not you think of your configuration as software, you can still benefit from capturing it in code, and deploying it in a repeatable, automatable way.

The modern solution to “infrastructure as code” is primarily powered by continuous integration (CI) systems, such as Travis, CircleCI, Jenkins, and more recently, GitHub Actions. A CI server can run your testing and deployment scripts automatically whenever code is pushed to your repository, providing the ability for you to deploy your services via the Fastly Command Line Interface (CLI) or API.

For our customers using VCL, we provide an industry standard way to manage infrastructure as code with our Terraform provider. For years, this has been used by teams to deploy changes to Fastly services, but Compute@Edge brings some changes.

Compute@Edge adds a build step

With Compute@Edge, you need to compile your code into a Wasm binary before sending it to Fastly. The Fastly CLI provides commands to do that, and can be used on your development machines or in your CI environment to build and deploy your Compute@Edge applications.

This means that automating deployments requires you to instruct the CI platform to install the Fastly CLI, compile your code, as well as securely store the authentication tokens that provide access to your Fastly account.

Enter GitHub Actions for Compute@Edge

GitHub Actions is becoming one of the most popular CI systems available thanks to its ease of use and integration with GitHub source code repositories. For example, the development team over at loveholidays is already building their Compute@Edge deployment workflows on Actions.

The charm of GitHub Actions is its massive library of community-created open source workflows, and GitHub has productised this by providing a Marketplace to help developers discover actions relevant to their projects. It’s now easier than ever to implement a third party tool in your CI workflows.

That is why we built GitHub Actions for Compute@Edge. Compared to a traditional CI approach, Actions allows you to transition from a manually deployed application to a fully automated deployment workflow with ease. This is great because it means we can now use familiar patterns from web application deployment to push server-side logic to the edge, closer to the user. 

Give it a go

If you want to use GitHub Actions to enable automatic deployments in your own Compute@Edge application, here's how to get it set up for Rust projects:

  1. Create a workflow configuration in the .github/workflows folder with the following contents:

name: Deploy Application
on:
  push:
    branches: [main] # change to your default branch name

jobs:
  deploy:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v2
    - name: Install Rust toolchain
      uses: actions-rs/toolchain@v1
      with:
          toolchain: 1.49.0 # current Rust toolchain for Compute@Edge
          target: wasm32-wasi # WebAssembly target

    - name: Deploy to Compute@Edge
      uses: fastly/compute-actions@beta
      env:
        FASTLY_API_TOKEN: ${{ secrets.FASTLY_API_TOKEN }}

This workflow configuration tells GitHub to fetch your repo, install Rust, and then compile and deploy your Rust application to Compute@Edge.

2. Add your Fastly API token as a variable named FASTLY_API_TOKEN to "Secrets" in the repository settings. It must have permission to create and activate new service versions.

3. Commit and push to the main branch of your repository.

4. Go to your repository's "Actions" tab and monitor the logs. If the build and deployment is successful, you should see your Fastly service's domain printed to the console.
Note: Currently, while Compute@Edge is in limited availability, the Fastly CLI requires a specific version of the Rust toolchain. If a future release of the CLI changes the toolchain version, you'll need to update the actions workflow to match.

Moving forward

We hope to expand on this release to provide ever more continuous integration tooling, such as testing, preview branches, and commit statuses. Get in touch on the issue tracker or Developer Hub feedback form if you encounter any issues or would like to see new functionality.

Share this post

Ready to get started?

Get in touch or create an account.