-
Notifications
You must be signed in to change notification settings - Fork 75
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce signed, fully reproducible container images that are created on pushes to main and published via GitHub packages.
- Loading branch information
1 parent
b8f3ef1
commit 131775e
Showing
6 changed files
with
187 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
--- | ||
name: Create OCI image | ||
on: | ||
pull_request: | ||
branches: | ||
- main | ||
push: | ||
branches: | ||
- main | ||
|
||
permissions: read-all | ||
|
||
jobs: | ||
publish-image: | ||
runs-on: ubuntu-22.04 | ||
permissions: | ||
packages: write | ||
id-token: write | ||
steps: | ||
- name: Checkout | ||
uses: >- # v3.5.3 | ||
actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 | ||
- name: Install Nix | ||
uses: >- # v7 | ||
DeterminateSystems/nix-installer-action@5620eb4af6b562c53e4d4628c0b6e4f9d9ae8612 | ||
with: | ||
github-token: ${{ secrets.GITHUB_TOKEN }} | ||
- name: Cache Nix derivations | ||
uses: >- # Custom commit, last pinned at 2023-11-17. | ||
DeterminateSystems/magic-nix-cache-action@a04e6275a6bea232cd04fc6f3cbf20d4cb02a3e1 | ||
- name: Test image | ||
run: | | ||
nix run .#local-image-test | ||
- name: Upload image | ||
run: | | ||
nix run .#publish-ghcr | ||
env: | ||
GHCR_REGISTRY: ghcr.io | ||
GHCR_USERNAME: ${{ github.actor }} | ||
GHCR_PASSWORD: ${{ secrets.GITHUB_TOKEN }} | ||
GHCR_IMAGE_NAME: ${{ github.repository }} | ||
if: github.ref == 'refs/heads/main' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,3 +10,4 @@ __pycache__ | |
.direnv/ | ||
.DS_Store | ||
.pre-commit-config.yaml | ||
result |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
{ pkgs, ... }: | ||
|
||
pkgs.writeShellScriptBin "local-image-test" '' | ||
set -xeuo pipefail | ||
# Commit hashes would not be a good choice here as they are not | ||
# fully dependent on the inputs to the image. For instance, amending | ||
# nothing would still lead to a new hash. Instead we use the | ||
# derivation hash as the tag so that the tag is reused if the image | ||
# didn't change. | ||
IMAGE_TAG=$(nix eval .#image.imageTag --raw) | ||
$(nix build .#image --print-build-logs --verbose) \ | ||
&& ./result \ | ||
| ${pkgs.skopeo}/bin/skopeo \ | ||
copy \ | ||
docker-archive:/dev/stdin \ | ||
docker-daemon:native-link:''${IMAGE_TAG} | ||
# Ensure that the image has minimal closure size. | ||
CI=1 ${pkgs.dive}/bin/dive \ | ||
native-link:''${IMAGE_TAG} \ | ||
--highestWastedBytes=0 | ||
'' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
{ pkgs, ... }: | ||
|
||
pkgs.writeShellScriptBin "publish-ghcr" '' | ||
set -xeuo pipefail | ||
echo $GHCR_PASSWORD | ${pkgs.skopeo}/bin/skopeo \ | ||
login \ | ||
--username=$GHCR_USERNAME \ | ||
--password-stdin \ | ||
ghcr.io | ||
# Commit hashes would not be a good choice here as they are not | ||
# fully dependent on the inputs to the image. For instance, amending | ||
# nothing would still lead to a new hash. Instead we use the | ||
# derivation hash as the tag so that the tag is reused if the image | ||
# didn't change. | ||
IMAGE_TAG=$(nix eval .#image.imageTag --raw) | ||
TAGGED_IMAGE=''${GHCR_REGISTRY}/''${GHCR_IMAGE_NAME}:''${IMAGE_TAG} | ||
$(nix build .#image --print-build-logs --verbose) \ | ||
&& ./result \ | ||
| ${pkgs.zstd}/bin/zstd \ | ||
| ${pkgs.skopeo}/bin/skopeo \ | ||
copy \ | ||
docker-archive:/dev/stdin \ | ||
docker://''${TAGGED_IMAGE} | ||
echo $GHCR_PASSWORD | ${pkgs.cosign}/bin/cosign \ | ||
login \ | ||
--username=$GHCR_USERNAME \ | ||
--password-stdin \ | ||
ghcr.io | ||
${pkgs.cosign}/bin/cosign \ | ||
sign \ | ||
--yes \ | ||
''${GHCR_REGISTRY}/''${GHCR_IMAGE_NAME}@$( \ | ||
${pkgs.skopeo}/bin/skopeo \ | ||
inspect \ | ||
--format "{{ .Digest }}" \ | ||
docker://''${TAGGED_IMAGE} \ | ||
) | ||
'' |