# Upload assets to the CDN

This how-to guide shows you how to upload assets to the [CDN](/services/cdn.md).

## Prerequisites

- A [Nais team](/explanations/team.md).
- A GitHub repository that the team has access to.
- The repository needs to have a [GitHub workflow](/build.md) that builds the assets you want to upload.

## Authorize repository for upload

1. Open [Nais console](https://console.dev-nais.cloud.nais.io) 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

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

```yaml
name: Push to CDN

on:
  push:
    branches:
      - 'main'

jobs:
  upload:
    runs-on: ubuntu-latest

    permissions:
      contents: read
      id-token: write

    steps:
      - uses: actions/checkout@v6 # Should be pinned (1)
      - name: Upload static files to CDN
        uses: nais/deploy/actions/cdn-upload/v2@master # Should be pinned
        with:
          tenant: dev-nais
          team: <MY-TEAM> # Replace with "team-name"
          source: <The path to your build folder or assets> # Replace
          destination: <A destination you pick, like /my-app/dist> # Replace
      - run: 'echo "uploaded file ${{ steps.upload.outputs.uploaded }}"'
```

1. GitHub actions should be pinned to a SHA for better security. Read more in GitHub [Secure use reference](https://docs.github.com/en/actions/reference/security/secure-use#using-third-party-actions).

For more information on the inputs and outputs of the action, see the [CDN Upload action reference](/services/cdn/reference/upload-assets.md).

## Use the uploaded assets

The assets from the CDN will be available at:

```
https://cdn.dev-nais.cloud.nais.io/<team>/<destination>
```

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

## Related pages

🎯 Learn how to [manage CDN assets](/services/cdn/how-to/manage-assets.md)
