Best reviewed with -w --color-moved. This just moves the code
into a separate workflow. This will allow us to reuse it in
the release job for github releng of releases.
(cherry picked from commit 745983dfc0)
85 lines
3.0 KiB
YAML
85 lines
3.0 KiB
YAML
name: "Push Docker Image"
|
|
|
|
on:
|
|
workflow_call:
|
|
secrets:
|
|
DOCKERHUB_USERNAME:
|
|
required: true
|
|
DOCKERHUB_TOKEN:
|
|
required: true
|
|
|
|
permissions: {}
|
|
|
|
jobs:
|
|
# Steps to test CI automation in your own fork.
|
|
# 1. Sign-up for https://hub.docker.com/
|
|
# 2. Store your dockerhub username as DOCKERHUB_USERNAME in "Repository secrets" of your fork repository settings (https://github.com/$githubuser/nix/settings/secrets/actions)
|
|
# 3. Create an access token in https://hub.docker.com/settings/security and store it as DOCKERHUB_TOKEN in "Repository secrets" of your fork
|
|
check_secrets:
|
|
permissions:
|
|
contents: none
|
|
name: Check presence of secrets
|
|
runs-on: ubuntu-24.04
|
|
outputs:
|
|
docker: ${{ steps.secret.outputs.docker }}
|
|
steps:
|
|
- name: Check for DockerHub secrets
|
|
id: secret
|
|
env:
|
|
_DOCKER_SECRETS: ${{ secrets.DOCKERHUB_USERNAME }}${{ secrets.DOCKERHUB_TOKEN }}
|
|
run: |
|
|
echo "docker=${{ env._DOCKER_SECRETS != '' }}" >> $GITHUB_OUTPUT
|
|
|
|
push:
|
|
name: Push docker image to DockerHub and GHCR
|
|
needs: [check_secrets]
|
|
permissions:
|
|
contents: read
|
|
packages: write
|
|
if: needs.check_secrets.outputs.docker == 'true'
|
|
runs-on: ubuntu-24.04
|
|
steps:
|
|
- uses: actions/checkout@v6
|
|
with:
|
|
fetch-depth: 0
|
|
- uses: ./.github/actions/install-nix-action
|
|
with:
|
|
dogfood: false
|
|
extra_nix_config: |
|
|
experimental-features = flakes nix-command
|
|
- run: echo NIX_VERSION="$(nix eval .\#nix.version | tr -d \")" >> $GITHUB_ENV
|
|
- run: nix build .#dockerImage -L
|
|
- run: docker load -i ./result/image.tar.gz
|
|
- run: docker tag nix:$NIX_VERSION ${{ secrets.DOCKERHUB_USERNAME }}/nix:$NIX_VERSION
|
|
- run: docker tag nix:$NIX_VERSION ${{ secrets.DOCKERHUB_USERNAME }}/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
|
|
uses: docker/login-action@v3
|
|
with:
|
|
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
|
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
|
- run: docker push ${{ secrets.DOCKERHUB_USERNAME }}/nix:$NIX_VERSION
|
|
- run: docker push ${{ secrets.DOCKERHUB_USERNAME }}/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:latest
|
|
docker push $IMAGE_ID:$NIX_VERSION
|
|
docker push $IMAGE_ID:latest
|
|
# deprecated 2024-02-24
|
|
docker tag nix:$NIX_VERSION $IMAGE_ID:master
|
|
docker push $IMAGE_ID:master
|