Skip to content

Example: Publish an OpenFaaS function

This example will publish an OpenFaaS function to GitHub's Container Registry (GHCR).

  • The example uses Docker's buildx and QEMU for a multi-arch build
  • Dynamic variables to inject the SHA and OWNER name from the repo
  • Uses the token that GitHub assigns to the action to publish the containers.

You can also run this example on GitHub's own hosted runners.

Docker CE is preinstalled in the actuated VM image, and will start upon boot-up.

Certified for:

  • x86_64

Use a private repository if you're not using actuated yet

GitHub recommends using a private repository with self-hosted runners because changes can be left over from a previous run, even when using Actions Runtime Controller. Actuated uses an ephemeral VM with an immutable image, so can be used on both public and private repos. Learn why in the FAQ.

Try out the action on your agent

For alexellis' repository called alexellis/autoscaling-functions, then check out the .github/workflows/publish.yml file:

  • The "Setup QEMU" and "Set up Docker Buildx" steps configure the builder to produce a multi-arch image.
  • The "OWNER" variable means this action can be run on any organisation without having to hard-code a username for GHCR.
  • Only the bcrypt function is being built with the --filter command added, remove it to build all functions in the stack.yml.
  • --platforms linux/amd64,linux/arm64,linux/arm/v7 will build for regular Intel/AMD machines, 64-bit Arm and 32-bit Arm i.e. Raspberry Pi, most users can reduce this list to just "linux/amd64" for a speed improvement

Make sure you edit runs-on: and set it to runs-on: actuated-4cpu-12gb

name: publish

on:
  push:
    branches:
      - '*'
  pull_request:
    branches:
      - '*'

permissions:
  actions: read
  checks: write
  contents: read
  packages: write

jobs:
  publish:
    runs-on: actuated-4cpu-12gb
    steps:
      - uses: actions/checkout@master
        with:
          fetch-depth: 1
      - name: Get faas-cli
        run: curl -sLSf https://cli.openfaas.com | sudo sh
      - name: Pull custom templates from stack.yml
        run: faas-cli template pull stack
      - name: Set up QEMU
        uses: docker/setup-qemu-action@v3
      - name: Set up Docker Buildx
        uses: docker/setup-buildx-action@v3
      - name: Get TAG
        id: get_tag
        run: echo ::set-output name=TAG::latest-dev
      - name: Get Repo Owner
        id: get_repo_owner
        run: >
          echo ::set-output name=repo_owner::$(echo ${{ github.repository_owner }} |
          tr '[:upper:]' '[:lower:]')
      - name: Docker Login
        run: > 
          echo ${{secrets.GITHUB_TOKEN}} | 
          docker login ghcr.io --username 
          ${{ steps.get_repo_owner.outputs.repo_owner }} 
          --password-stdin
      - name: Publish functions
        run: >
          OWNER="${{ steps.get_repo_owner.outputs.repo_owner }}" 
          TAG="latest"
          faas-cli publish
          --extra-tag ${{ github.sha }}
          --build-arg GO111MODULE=on
          --platforms linux/amd64,linux/arm64,linux/arm/v7
          --filter bcrypt

If you'd like to deploy the function, check out a more comprehensive example of how to log in and deploy in Serverless For Everyone Else