Skip to content
Open
Show file tree
Hide file tree
Changes from 14 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .envrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
if ! has nix_direnv_version || ! nix_direnv_version 2.2.1; then
source_url "https://raw.githubusercontent.com/nix-community/nix-direnv/2.2.1/direnvrc" "sha256-zelF0vLbEl5uaqrfIzbgNzJWGmLzCmYAkInj/LNxvKs="
fi

watch_file flake.nix
watch_file flake.lock
if ! use flake . --no-pure-eval
then
echo "devenv could not be built. The devenv environment was not loaded. Make the necessary changes to devenv.nix and hit enter to try again." >&2
fi
114 changes: 89 additions & 25 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
@@ -1,42 +1,107 @@
name: Docker

on:
push:
branches:
- "main"
tags:
- "*"
workflow_dispatch:

env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}

jobs:
build-and-push-image:
name: Build and publish
runs-on: ubuntu-latest
build-image:
name: Build Docker image
strategy:
matrix:
runner:
- ubuntu-24.04
- ubuntu-24.04-arm
runs-on: ${{ matrix.runner }}
permissions:
contents: read
packages: write
steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Set up QEMU
uses: docker/setup-qemu-action@v2

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2


- name: Install Nix
uses: cachix/install-nix-action@v24
with:
nix_path: nixpkgs=channel:nixos-unstable

- name: Set up Magic Nix Cache
uses: DeterminateSystems/magic-nix-cache-action@v2

- name: Build Docker image with Nix
run: |
nix build .#docker
IMAGE_PATH=$(readlink -f result)
echo "IMAGE_PATH=$IMAGE_PATH" >> $GITHUB_ENV

- name: Load Docker image
run: |
docker load < ${{ env.IMAGE_PATH }}

- name: Log in to the Container registry
uses: docker/login-action@v2
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}


- name: Determine architecture
id: arch
run: |
if [ "${{ matrix.runner }}" = "ubuntu-24.04" ]; then
echo "arch=amd64" >> $GITHUB_OUTPUT
echo "platform=linux/amd64" >> $GITHUB_OUTPUT
else
echo "arch=arm64" >> $GITHUB_OUTPUT
echo "platform=linux/arm64" >> $GITHUB_OUTPUT
fi

- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v4
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=raw,value={{branch}}-${{ steps.arch.outputs.arch }}
type=raw,value=latest-${{ steps.arch.outputs.arch }},enable=${{ startsWith(github.ref, 'refs/tags/') }}
type=raw,value={{tag}}-${{ steps.arch.outputs.arch }},enable=${{ startsWith(github.ref, 'refs/tags/') }}
flavor: |
latest=false

- name: Get image name from Nix build
id: image
run: |
IMAGE_NAME=$(docker images --format "{{.Repository}}:{{.Tag}}" | head -n 1)
echo "name=$IMAGE_NAME" >> $GITHUB_OUTPUT

- name: Tag and push Docker image
run: |
for tag in ${{ steps.meta.outputs.tags }}; do
docker tag ${{ steps.image.outputs.name }} $tag
docker push $tag
done

create-manifest:
name: Create multi-arch manifest
needs: build-image
runs-on: ubuntu-24.04
permissions:
contents: read
packages: write
steps:
- name: Log in to the Container registry
uses: docker/login-action@v2
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Extract metadata for manifest
id: meta
uses: docker/metadata-action@v4
with:
Expand All @@ -48,14 +113,13 @@ jobs:
type=match,pattern=\d+,group=0,enable=${{ startsWith(github.ref, 'refs/tags/') }}
flavor: |
latest=false

- name: Build and push Docker image
uses: docker/build-push-action@v3
with:
context: .
platforms: linux/amd64,linux/arm64
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max

- name: Create and push manifest
run: |
TAGS="${{ steps.meta.outputs.tags }}"
for tag in $TAGS; do
docker manifest create $tag \
${tag}-amd64 \
${tag}-arm64
docker manifest push $tag
done
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,6 @@ target
*/target
.env
settings.toml
result
.direnv
.devenv
Loading
Loading