Skip to content

Build and Push Images #10

Build and Push Images

Build and Push Images #10

Workflow file for this run

name: Build and Push Images
on:
workflow_dispatch:
inputs:
mise_version:
description: "Mise version to build (defaults to latest)"
required: false
default: "latest"
force:
description: "Force build even if image exists"
required: false
type: boolean
default: false
schedule:
- cron: "24 * * * *"
jobs:
get-version:
runs-on: ubuntu-latest
outputs:
version: ${{ steps.set-version.outputs.version }}
steps:
- id: set-version
run: |
if [ "${{ github.event.inputs.mise_version }}" = "latest" ] || [ -z "${{ github.event.inputs.mise_version }}" ]; then
VERSION=$(curl -s https://api.github.com/repos/jdx/mise/releases/latest | jq -r .tag_name | sed 's/^v//')
else
VERSION=${{ github.event.inputs.mise_version }}
fi
echo "version=$VERSION" >> $GITHUB_OUTPUT
build:
needs: get-version
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
base: [forky, trixie, bookworm, sid]
variant: ["", "-slim"]
permissions:
contents: read
packages: write
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to GHCR
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Login to Dockerhub
uses: docker/login-action@v3
with:
username: ${{ vars.DOCKERHUB_USER }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Get dated tag
id: dated-tag
run: |
BASE_TAG="${{ matrix.base }}${{ matrix.variant }}"
DIGEST=$(curl -s "https://hub.docker.com/v2/repositories/library/debian/tags/${BASE_TAG}" | jq -r .digest)
DATED_TAG=$(curl -s "https://hub.docker.com/v2/repositories/library/debian/tags/?page_size=100" | \
jq -r --arg DIGEST "$DIGEST" '.results[] | select(.digest == $DIGEST) | .name' | \
grep -E "^${{ matrix.base }}-[0-9]{8}${{ matrix.variant }}$" | head -n 1)
if [ -z "$DATED_TAG" ]; then
echo "Could not find dated tag for ${BASE_TAG}, falling back to ${BASE_TAG}"
DATED_TAG="${BASE_TAG}"
fi
echo "dated_tag=${DATED_TAG}" >> $GITHUB_OUTPUT
- name: Generate tags
id: tags
run: |
VERSION="${{ needs.get-version.outputs.version }}"
BASE="${{ matrix.base }}"
VARIANT="${{ matrix.variant }}"
DATED_TAG="${{ steps.dated-tag.outputs.dated_tag }}"
# Use a heredoc to build the tags list
cat <<EOF > tags.txt
ghcr.io/${{ github.repository }}:${BASE}${VARIANT}
ghcr.io/${{ github.repository }}:${VERSION}-${BASE}${VARIANT}
ghcr.io/${{ github.repository }}:${DATED_TAG}
ghcr.io/${{ github.repository }}:${VERSION}-${DATED_TAG}
amartani/mise:${BASE}${VARIANT}
amartani/mise:${VERSION}-${BASE}${VARIANT}
amartani/mise:${DATED_TAG}
amartani/mise:${VERSION}-${DATED_TAG}
EOF
if [ "$BASE" = "trixie" ]; then
echo "ghcr.io/${{ github.repository }}:latest${VARIANT}" >> tags.txt
echo "ghcr.io/${{ github.repository }}:${VERSION}${VARIANT}" >> tags.txt
echo "amartani/mise:latest${VARIANT}" >> tags.txt
echo "amartani/mise:${VERSION}${VARIANT}" >> tags.txt
fi
{
echo 'tags<<EOF'
cat tags.txt
echo 'EOF'
} >> "$GITHUB_OUTPUT"
- name: Check if image exists
id: check-image
run: |
TAG="ghcr.io/${{ github.repository }}:${{ needs.get-version.outputs.version }}-${{ steps.dated-tag.outputs.dated_tag }}"
if docker buildx imagetools inspect "$TAG" > /dev/null 2>&1; then
echo "exists=true" >> $GITHUB_OUTPUT
else
echo "exists=false" >> $GITHUB_OUTPUT
fi
- name: Build and push
if: github.event.inputs.force == 'true' || steps.check-image.outputs.exists == 'false'
uses: docker/build-push-action@v6
with:
context: ./debian
file: ./debian/Dockerfile
push: true
platforms: linux/amd64,linux/arm64
build-args: |
BASE_IMAGE=debian:${{ matrix.base }}${{ matrix.variant }}
MISE_VERSION=${{ needs.get-version.outputs.version }}
tags: ${{ steps.tags.outputs.tags }}