Migrate to axum #6
This file contains hidden or 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
| name: CI/CD | |
| on: | |
| push: | |
| branches: [ main ] | |
| tags: [ '*' ] | |
| pull_request: | |
| env: | |
| REGISTRY: ghcr.io | |
| IMAGE_NAME: ${{ github.repository }} | |
| jobs: | |
| check: | |
| name: Nix CI | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - uses: cachix/install-nix-action@v24 | |
| with: | |
| nix_path: nixpkgs=channel:nixos-unstable | |
| - uses: DeterminateSystems/magic-nix-cache-action@v2 | |
| - run: nix flake check -L | |
| - run: nix build -L | |
| build: | |
| name: Build Binary | |
| needs: check | |
| if: github.event_name == 'push' && (github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/')) | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - uses: cachix/install-nix-action@v24 | |
| with: | |
| nix_path: nixpkgs=channel:nixos-unstable | |
| - uses: DeterminateSystems/magic-nix-cache-action@v2 | |
| - run: nix build -L | |
| - run: mkdir -p target/release && cp result/bin/testaustime target/release/testaustime-rs | |
| - uses: actions/upload-artifact@v4 | |
| with: | |
| name: build | |
| path: target/release/testaustime-rs | |
| build-image: | |
| name: Build Docker image | |
| needs: check | |
| if: github.event_name == 'push' && (github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/')) | |
| 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@v4 | |
| - 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 -L .#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: | |
| images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} | |
| tags: | | |
| type=raw,value={{branch}} | |
| type=raw,value=latest,enable=${{ startsWith(github.ref, 'refs/tags/') }} | |
| type=raw,value={{tag}},enable=${{ startsWith(github.ref, 'refs/tags/') }} | |
| type=match,pattern=\d+,group=0,enable=${{ startsWith(github.ref, 'refs/tags/') }} | |
| flavor: | | |
| latest=false | |
| - 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 |