Skip to content

Conditional for arm builds #51

Conditional for arm builds

Conditional for arm builds #51

# Build and publish nvim-dev container image
# Triggered on changes to dot_files/nvim/ or manual dispatch
# Image published to: ghcr.io/binarypie-dev/nvim-dev:latest
name: Build nvim-dev Image
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
on:
push:
branches:
- main
paths:
- 'dot_files/nvim/Containerfile'
- '.github/workflows/build-nvim-dev.yml'
pull_request:
paths:
- 'dot_files/nvim/Containerfile'
- '.github/workflows/build-nvim-dev.yml'
workflow_dispatch:
schedule:
# Rebuild daily to get updated packages
- cron: '0 6 * * *'
env:
IMAGE_NAME: nvim-dev
IMAGE_REGISTRY: ghcr.io/${{ github.repository_owner }}
jobs:
build:
runs-on: ${{ matrix.runner }}
strategy:
fail-fast: false
matrix:
include:
- platform: linux/amd64
runner: ubuntu-latest-m
suffix: amd64
- platform: linux/arm64
runner: ubuntu-latest-m-arm
suffix: arm64
permissions:
contents: read
packages: write
steps:
- name: Checkout repository
uses: actions/checkout@v6
- name: Install Docker (ARM)
if: matrix.suffix == 'arm64'
run: |
curl -fsSL https://get.docker.com | sh
sudo systemctl start docker
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to GitHub Container Registry
if: github.event_name != 'pull_request'
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.IMAGE_REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=raw,value=latest-${{ matrix.suffix }},enable=${{ github.ref == 'refs/heads/main' }}
type=sha,prefix=,suffix=-${{ matrix.suffix }}
type=ref,event=pr,suffix=-${{ matrix.suffix }}
- name: Build and push
uses: docker/build-push-action@v6
with:
context: dot_files/nvim
file: dot_files/nvim/Containerfile
platforms: ${{ matrix.platform }}
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha,scope=${{ matrix.suffix }}
cache-to: type=gha,mode=max,scope=${{ matrix.suffix }}
manifest:
needs: build
runs-on: ubuntu-latest
if: github.event_name != 'pull_request'
permissions:
packages: write
steps:
- name: Log in to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Create and push manifest
run: |
docker manifest create ${{ env.IMAGE_REGISTRY }}/${{ env.IMAGE_NAME }}:latest \
${{ env.IMAGE_REGISTRY }}/${{ env.IMAGE_NAME }}:latest-amd64 \
${{ env.IMAGE_REGISTRY }}/${{ env.IMAGE_NAME }}:latest-arm64
docker manifest push ${{ env.IMAGE_REGISTRY }}/${{ env.IMAGE_NAME }}:latest
# Also create SHA manifest
docker manifest create ${{ env.IMAGE_REGISTRY }}/${{ env.IMAGE_NAME }}:${{ github.sha }} \
${{ env.IMAGE_REGISTRY }}/${{ env.IMAGE_NAME }}:${{ github.sha }}-amd64 \
${{ env.IMAGE_REGISTRY }}/${{ env.IMAGE_NAME }}:${{ github.sha }}-arm64
docker manifest push ${{ env.IMAGE_REGISTRY }}/${{ env.IMAGE_NAME }}:${{ github.sha }}
- name: Generate build summary
run: |
echo "## nvim-dev Image Built" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "**Image:** \`${{ env.IMAGE_REGISTRY }}/${{ env.IMAGE_NAME }}:latest\`" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "### Usage" >> $GITHUB_STEP_SUMMARY
echo "\`\`\`bash" >> $GITHUB_STEP_SUMMARY
echo "distrobox create --name nvim-dev --image ${{ env.IMAGE_REGISTRY }}/${{ env.IMAGE_NAME }}:latest" >> $GITHUB_STEP_SUMMARY
echo "distrobox enter nvim-dev" >> $GITHUB_STEP_SUMMARY
echo "\`\`\`" >> $GITHUB_STEP_SUMMARY