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 ΒΆ
Note
If you require a more advanced workflow, or already have one: copy the relevant parts from the example below.
.github/workflows/main.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 }}" \
--waitThis 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.
Registry used by Nais
The nais/docker-build-push GitHub action as well as the nais/login GitHub action work with a registry that is only meant for use within the Nais platform.
Usage of this registry for other purposes is not supported. If you need to use the image outside of Nais, e.g. locally in a development environment, you should push the image to another registry.
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.