docker: publish images to ghcr.io (#8066)

* docker: publish images to ghcr.io

docker.com announced their intention to remove the free plan used by
OSS. The nixos/nix image is essential to various CI runs to build with
nix. To provide a continuity plan, this commit pushes the image to
ghcr.io as well.

Co-authored-by: Sandro <sandro.jaeckel@gmail.com>
This commit is contained in:
Arthur Gautier 2023-10-20 10:28:26 -07:00 committed by GitHub
parent e824ab30cf
commit 85e5ac403f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 27 additions and 4 deletions

View file

@ -101,6 +101,9 @@ jobs:
docker_push_image: docker_push_image:
needs: [check_secrets, tests] needs: [check_secrets, tests]
permissions:
contents: read
packages: write
if: >- if: >-
github.event_name == 'push' && github.event_name == 'push' &&
github.ref_name == 'master' && github.ref_name == 'master' &&
@ -126,6 +129,9 @@ jobs:
- run: docker load -i ./result/image.tar.gz - run: docker load -i ./result/image.tar.gz
- run: docker tag nix:$NIX_VERSION nixos/nix:$NIX_VERSION - run: docker tag nix:$NIX_VERSION nixos/nix:$NIX_VERSION
- run: docker tag nix:$NIX_VERSION nixos/nix:master - run: docker tag nix:$NIX_VERSION nixos/nix:master
# We'll deploy the newly built image to both Docker Hub and Github Container Registry.
#
# Push to Docker Hub first
- name: Login to Docker Hub - name: Login to Docker Hub
uses: docker/login-action@v3 uses: docker/login-action@v3
with: with:
@ -133,3 +139,20 @@ jobs:
password: ${{ secrets.DOCKERHUB_TOKEN }} password: ${{ secrets.DOCKERHUB_TOKEN }}
- run: docker push nixos/nix:$NIX_VERSION - run: docker push nixos/nix:$NIX_VERSION
- run: docker push nixos/nix:master - run: docker push nixos/nix:master
# Push to GitHub Container Registry as well
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Push image
run: |
IMAGE_ID=ghcr.io/${{ github.repository_owner }}/nix
# Change all uppercase to lowercase
IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]')
docker tag nix:$NIX_VERSION $IMAGE_ID:$NIX_VERSION
docker tag nix:$NIX_VERSION $IMAGE_ID:master
docker push $IMAGE_ID:$NIX_VERSION
docker push $IMAGE_ID:master

View file

@ -3,14 +3,14 @@
To run the latest stable release of Nix with Docker run the following command: To run the latest stable release of Nix with Docker run the following command:
```console ```console
$ docker run -ti nixos/nix $ docker run -ti ghcr.io/nixos/nix
Unable to find image 'nixos/nix:latest' locally Unable to find image 'ghcr.io/nixos/nix:latest' locally
latest: Pulling from nixos/nix latest: Pulling from ghcr.io/nixos/nix
5843afab3874: Pull complete 5843afab3874: Pull complete
b52bf13f109c: Pull complete b52bf13f109c: Pull complete
1e2415612aa3: Pull complete 1e2415612aa3: Pull complete
Digest: sha256:27f6e7f60227e959ee7ece361f75d4844a40e1cc6878b6868fe30140420031ff Digest: sha256:27f6e7f60227e959ee7ece361f75d4844a40e1cc6878b6868fe30140420031ff
Status: Downloaded newer image for nixos/nix:latest Status: Downloaded newer image for ghcr.io/nixos/nix:latest
35ca4ada6e96:/# nix --version 35ca4ada6e96:/# nix --version
nix (Nix) 2.3.12 nix (Nix) 2.3.12
35ca4ada6e96:/# exit 35ca4ada6e96:/# exit