From e61441607da180b93e01ed28d81cbb1d987b3634 Mon Sep 17 00:00:00 2001 From: Dan Nixon Date: Thu, 16 Jan 2025 15:37:39 +0000 Subject: [PATCH] Add container image build to CI --- .github/workflows/ci.yml | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index dfea3af..09eae82 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -49,3 +49,27 @@ jobs: - name: Build run: nix build --print-build-logs + + - name: Build and push container image + if: ${{ github.ref_name == 'main' || github.ref_type == 'tag' }} + run: | + set -x + + # Build image via Nix and take the resulting path as the local container registry + local_cr="docker-archive://$(nix build .#container-image --no-link --print-out-paths)" + + # The container registry to push images to (GHCR) + remote_cr="docker://ghcr.io/dannixon/git-collage" + remote_cr_creds="${{ github.repository_owner }}:${{ github.token }}" + + # Push image using the Git ref name as the image tag (i.e. "main" or the tag name) + skopeo copy --dest-creds="$remote_cr_creds" "$local_cr" "$remote_cr:${{ github.ref_name }}" + + # Push image using the Git SHA as the image tag + skopeo copy --dest-creds="$remote_cr_creds" "$local_cr" "$remote_cr:${{ github.sha }}" + + # If the trigger was a tag (i.e. a release) + if [[ "${{ github.ref_type }}" == 'tag' ]]; then + # Push image using the "latest" tag + skopeo copy --dest-creds="$remote_cr_creds" "$local_cr" "$remote_cr:latest" + fi