Build and Push Images #406
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: Build and Push Images | |
| on: | |
| pull_request: | |
| 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", "-buildpack", "-buildpack-curl", "-buildpack-scm"] | |
| permissions: | |
| contents: read | |
| packages: write | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v6 | |
| - name: Set up QEMU | |
| uses: docker/setup-qemu-action@v4 | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v4 | |
| - name: Login to GHCR | |
| if: github.event_name != 'pull_request' | |
| uses: docker/login-action@v4 | |
| with: | |
| registry: ghcr.io | |
| username: ${{ github.actor }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Login to Dockerhub | |
| if: github.event_name != 'pull_request' | |
| uses: docker/login-action@v4 | |
| with: | |
| username: ${{ vars.DOCKERHUB_USER }} | |
| password: ${{ secrets.DOCKERHUB_TOKEN }} | |
| - name: Get dated tag | |
| id: dated-tag | |
| run: | | |
| BASE="${{ matrix.base }}" | |
| VARIANT="${{ matrix.variant }}" | |
| if [[ "$VARIANT" == -buildpack* ]]; then | |
| REPO_NAME="buildpack-deps" | |
| UPSTREAM_VARIANT=$(echo "$VARIANT" | sed 's/-buildpack//') | |
| else | |
| REPO_NAME="debian" | |
| UPSTREAM_VARIANT="$VARIANT" | |
| fi | |
| UPSTREAM_TAG="${BASE}${UPSTREAM_VARIANT}" | |
| DIGEST=$(curl -s "https://hub.docker.com/v2/repositories/library/${REPO_NAME}/tags/${UPSTREAM_TAG}" | jq -r .digest) | |
| DATED_VERSION=$(curl -s "https://hub.docker.com/v2/repositories/library/${REPO_NAME}/tags/?page_size=100" | \ | |
| jq -r --arg DIGEST "$DIGEST" '.results[] | select(.digest == $DIGEST) | .name' | \ | |
| grep -E "^${BASE}-[0-9]{8}${UPSTREAM_VARIANT}$" | sed -E "s/^${BASE}-([0-9]{8})${UPSTREAM_VARIANT}$/\1/" | head -n 1) | |
| if [ -n "$DATED_VERSION" ]; then | |
| MISE_DATED_TAG="${BASE}-${DATED_VERSION}${VARIANT}" | |
| UPSTREAM_DATED_TAG="${BASE}-${DATED_VERSION}${UPSTREAM_VARIANT}" | |
| else | |
| echo "Could not find dated tag for ${REPO_NAME}:${UPSTREAM_TAG}, falling back" | |
| MISE_DATED_TAG="${BASE}${VARIANT}" | |
| UPSTREAM_DATED_TAG="${UPSTREAM_TAG}" | |
| fi | |
| echo "dated_tag=${MISE_DATED_TAG}" >> $GITHUB_OUTPUT | |
| echo "upstream_image=${REPO_NAME}:${UPSTREAM_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 }}:${VERSION}-${DATED_TAG} | |
| amartani/mise:${BASE}${VARIANT} | |
| amartani/mise:${VERSION}-${BASE}${VARIANT} | |
| 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_name == 'pull_request' || github.event.inputs.force == 'true' || steps.check-image.outputs.exists == 'false' | |
| uses: docker/build-push-action@v7 | |
| with: | |
| context: ./debian | |
| file: ./debian/Dockerfile | |
| push: ${{ github.event_name != 'pull_request' }} | |
| platforms: linux/amd64,linux/arm64 | |
| build-args: | | |
| BASE_IMAGE=${{ steps.dated-tag.outputs.upstream_image }} | |
| MISE_VERSION=${{ needs.get-version.outputs.version }} | |
| tags: ${{ steps.tags.outputs.tags }} | |
| update-dockerhub-description: | |
| needs: build | |
| runs-on: ubuntu-latest | |
| if: github.event_name != 'pull_request' | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v6 | |
| - name: Docker Hub Description | |
| uses: peter-evans/dockerhub-description@v5 | |
| with: | |
| username: ${{ vars.DOCKERHUB_USER }} | |
| password: ${{ secrets.DOCKERHUB_TOKEN }} | |
| repository: amartani/mise |