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 CLI.
Prerequisites ΒΆ
- You're part of a Nais team
- A Github repository where the Nais team has access
- The repository contains a valid workload manifest
Authorize your Github repository for deployment ΒΆ
- Open Nais Console in your browser and select your team.
- Select the
Repositoriestab - Input your repository (
organization/repository) and pressAdd.
Create a Github workflow ΒΆ
.github/workflows/main.yaml
yaml
name: Build and deploy
on:
push:
branches:
- main
jobs:
build:
name: Build and push image
runs-on: ubuntu-latest
permissions:
contents: read
id-token: write
outputs:
image: ${{ steps.docker-build-push.outputs.image }}
steps:
- uses: actions/checkout@v6 # Should be pinned
- name: Build and push image and SBOM to OCI registry
uses: nais/docker-build-push@v0 # Should be pinned
id: docker-build-push
with:
team: <MY-TEAM> # Replace
deploy:
name: Deploy
needs: build
runs-on: ubuntu-latest
permissions:
contents: read
id-token: write
steps:
- uses: actions/checkout@v6 # Should be pinned
- uses: nais/setup@v1 # Should be pinned
with:
team: <MY-TEAM> # Replace
- name: Deploy to Nais
run: |
nais apply .nais/app.yaml \
--environment <MY-ENV> \
--set spec.image="${{ needs.build.outputs.image }}" \
--wait1
GitHub actions should be pinned to a SHA for better security. Read more in GitHub Secure use reference.
2
Environment is the Nais environment to deploy to. You can find available values in workloads/environments.
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 using the Nais CLI.
The freshly built image is passed to the deploy step with --set spec.image=<image>, which overrides the spec.image field in the manifest.
For how Nais resolves the image, see Applying a manifest.
When this file is pushed to the main branch, the workflow will be triggered, and you are all set.
What's next ΒΆ
This guide deploys to a single environment. To deploy to several environments and split manifest changes from code changes, see Set up a complete deploy pipeline.