Skip to content

Build and deploy with Github Actions

This how-to guide shows you how to build and deploy your application using Github Actions and the NAIS deploy action.

0. Prerequisites

1. Authorize your Github repository for deployment

  1. Open NAIS console in your browser and select your team.
  2. Select the Repositories tab
  3. Find the repository you want to deploy from, and click Authorize

2. Create a Github workflow


If you require a more advanced workflow, or already have one. Just copy the relevant parts from the example below.


name: Build and deploy
      - main
    name: Build, push and deploy
    runs-on: ubuntu-latest
      contents: read
      id-token: write
      - uses: actions/checkout@v4
      - name: Push docker image to GAR
        uses: nais/docker-build-push@v0
        id: docker-build-push
          team: <MY-TEAM> # Replace
          identity_provider: ${{ secrets.NAIS_WORKLOAD_IDENTITY_PROVIDER }} # Provided as Organization Secret
          project_id: ${{ vars.NAIS_MANAGEMENT_PROJECT_ID }} # Provided as Organization Variable
      - name: Deploy to NAIS
        uses: nais/deploy/actions/deploy@v2
          CLUSTER: <MY-CLUSTER> # Replace
          RESOURCE: .nais/app.yaml #, topic.yaml, statefulset.yaml, etc.
          VAR: image=${{ steps.docker-build-push.outputs.image }}

This example workflow is a minimal example that builds, signs, and pushes your container image to the image registry. It then deploys the app.yaml, injecting the image tag from the previous step.

When this file is pushed to the main branch, the workflow will be triggered and you are all set.