Skip to content

Commit 1e8f0af

Browse files
thokra-navtronghnchristeredvartsen
authored
Add info about retagging images for publishing to other registries (#751)
* Add info about retagging images for publishing to other registries Co-authored-by: Trong Huu Nguyen <[email protected]> Co-authored-by: Christer Edvartsen <[email protected]>
1 parent 5a40917 commit 1e8f0af

File tree

2 files changed

+66
-7
lines changed

2 files changed

+66
-7
lines changed

docs/build/how-to/build-and-deploy.md

+7-7
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
tags: [build, deploy, how-to]
33
---
44

5-
# Build and deploy with Github Actions
5+
# Build and deploy with GitHub Actions
66

7-
This how-to guide shows you how to build and deploy your application using [Github Actions](https://help.github.com/en/actions/automating-your-workflow-with-github-actions) and the Nais deploy action.
7+
This how-to guide shows you how to build and deploy your application using [GitHub Actions](https://help.github.com/en/actions/automating-your-workflow-with-github-actions) and the Nais deploy action.
88

99
## Prerequisites
1010

@@ -61,10 +61,10 @@ It then deploys the [app.yaml](../../workloads/application/reference/application
6161

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

64-
!!! info "Google Artifact Registry (GAR)"
64+
!!! info "Registry used by Nais"
6565

66-
The [nais/docker-build-push GitHub action](https://github.com/nais/docker-build-push) builds and pushes images to the _Google Artifact Registry_ (GAR).
66+
The [nais/docker-build-push GitHub action](https://github.com/nais/docker-build-push) as well as the
67+
[nais/login GitHub action](https://github.com/nais/login) work with a registry that is only meant for use within the Nais platform.
6768

68-
This is a registry managed by Nais and is the recommended way to store your container images for use in workloads on Nais.
69-
70-
We keep images that are deployed, as well as the last 10 versions for each image regardless of age. Versions older than 90 days are automatically deleted.
69+
Usage of this registry for other purposes is not supported.
70+
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](./use-image-outside-nais.md).
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
---
2+
tags: [how-to, build, image]
3+
---
4+
5+
# Using the image outside of Nais
6+
7+
When using the [nais/docker-build-push](https://github.com/nais/docker-build-push) action, the image is pushed to a registry that is meant for use within the Nais platform.
8+
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.
9+
10+
## Push to GitHub Container Registry
11+
12+
After the image is built by `nais/docker-build-push`, you can push it to the GitHub Container Registry (GHCR) by adding the following step to your workflow:
13+
14+
- `packages: write` permission is required to push images to the GHCR.
15+
- Step to retag the image after it has been built.
16+
17+
```yaml hl_lines="13 21-26"
18+
name: Build and deploy
19+
on:
20+
push:
21+
branches:
22+
- main
23+
jobs:
24+
build_and_deploy:
25+
name: Build, push and deploy
26+
runs-on: ubuntu-latest
27+
permissions:
28+
contents: read
29+
id-token: write
30+
packages: write
31+
steps:
32+
- uses: actions/checkout@v4
33+
- name: Build and push image and SBOM to OCI registry
34+
uses: nais/docker-build-push@v0
35+
id: docker-build-push
36+
with:
37+
team: <MY-TEAM> # Replace
38+
- name: Push image to ghcr.io
39+
run: |
40+
# Log in to the GitHub Container Registry
41+
echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin
42+
# Tag the image, e.g. ghcr.io/owner/repo:latest
43+
docker buildx imagetools create -t ghcr.io/${{ github.repository }}:latest ${{ steps.docker-build-push.outputs.image }}
44+
- name: Deploy to Nais
45+
uses: nais/deploy/actions/deploy@v2
46+
env:
47+
CLUSTER: <MY-CLUSTER> # Replace (1)
48+
RESOURCE: .nais/app.yaml #, topic.yaml, statefulset.yaml, etc.
49+
VAR: image=${{ steps.docker-build-push.outputs.image }}
50+
TELEMETRY: ${{ steps.docker-build-push.outputs.telemetry }}
51+
```
52+
53+
## Even more control
54+
55+
If you need more control of how the image is built, e.g. supporting more platforms etc, you can use the [nais/login action](https://github.com/nais/login) to log in to the registry
56+
provided by Nais, and build the image using e.g. [docker/build-push-action](https://github.com/docker/build-push-action).
57+
You can also use the [nais/attest-sign](https://github.com/nais/attest-sign) action to sign the image before pushing it to the registry.
58+
59+
See the [nais/docker-build-push action file](https://github.com/nais/docker-build-push/blob/main/action.yml) for a complete example.

0 commit comments

Comments
 (0)