Introducing GitHub Actions for Compute

One of the guiding principles for Compute, 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

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 brings some changes.

Compute adds a build step

With Compute, 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 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

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 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. 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 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.

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 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. Read more about how Github used Fastly to improve performance.

Kailan Blanks
Senior Software Engineer, Developer Relations
Published

4 min read

Want to continue the conversation?
Schedule time with an expert
Share this post
Kailan Blanks
Senior Software Engineer, Developer Relations

As a software engineer on the Developer Relations team at Fastly, Kailan is responsible for customer-facing tooling and content. As part of his work, he maintains the Fastly Developer Hub and various open-source projects for our serverless compute environment, Compute@Edge. Outside of work hours, he can often be found exploring the Cornish countryside on his electric skateboard.

Ready to get started?

Get in touch or create an account.