Skip to content

Upload assets to the CDN

This how-to guide shows you how to upload assets to the CDN.

Prerequisites

  • A NAIS team.
  • A GitHub repository that the team has access to.
  • The repository needs to have a GitHub workflow that builds the assets you want to upload.

Authorize repository for upload

  1. Open NAIS console in your browser and select your team.
  2. Select the Repositories tab
  3. Input your repository (organization/repository) and press Add.

Upload assets with the CDN action

SPA deploy

We also provide an action for swift deployment of single page applications (SPA), spa-deploy.

In your Github Workflow, add the following step to upload your assets to the CDN.

name: Push to CDN

on:
  push:
    branches:
      - 'main'

jobs:
  upload:
    runs-on: ubuntu-latest

    permissions:
      contents: 'read'
      id-token: 'write'

    steps:
      - uses: 'actions/checkout@v4'

      - name: Upload static files to CDN
        uses: nais/deploy/actions/cdn-upload/v2@master
        with:
          team: <team slug> # Required, e.g. "team-name"
          source: <The path to your build folder or assets>
          destination: <A destination you pick, like /my-app/dist>
          identity_provider: ${{ secrets.NAIS_WORKLOAD_IDENTITY_PROVIDER }} # Provided as Organization Secret
          project_id: ${{ vars.NAIS_MANAGEMENT_PROJECT_ID }} # Provided as Organization Variable
  
      - run: echo uploaded file ${{ steps.upload.outputs.uploaded }}

For more information on the inputs and outputs of the action, see the CDN Upload action reference.

Use the uploaded assets

The assets from the CDN will be available at:

https://cdn.nav.no/<team>/<destination>

and

https://cdn.nav.cloud.nais.io/<team>/<destination>

CORS is automatically configured to accept GET from any origin (*).

🎯 Learn how to manage CDN assets