diff --git a/.github/workflows/build-bootc-image.yaml b/.github/workflows/build-bootc-image.yaml index a9bb5bd..e15112e 100644 --- a/.github/workflows/build-bootc-image.yaml +++ b/.github/workflows/build-bootc-image.yaml @@ -60,6 +60,8 @@ jobs: strategy: fail-fast: false runs-on: ubuntu-24.04 + outputs: + image_version: ${{ steps.getversion.outputs.image_version }} steps: - name: Free disk space uses: hastd/free-disk-space@68572aeaadb7f76bd408246328e95926323402b5 # v0.1.2 @@ -97,6 +99,10 @@ jobs: - name: Install mkosi uses: systemd/mkosi@c4c3d793d0f6f0a2f26895de5ed9382396f36bb5 + - name: Set mkosi.version + # We need to do this because mkosi.version is not persistent between builds on CI + run: skopeo list-tags docker://${IMAGE_REGISTRY}/${IMAGE_NAME} | jq --arg date "$(date -u +%Y%m%d)" -r '.Tags[] | select(startswith($date+"."))' | sort -n | tail -1 > mkosi.version + - name: Render configuration (for debugging) run: mkosi cat-config --debug @@ -120,6 +126,12 @@ jobs: sudo mkosi -B --profile bootc ${args} --debug -ff --tools-tree-distribution=arch ${RELEASE_ARGUMENTS} + - name: Get Version + id: getversion + run: | + set -e + echo "image_version=$(cat mkosi.version)" >> "$GITHUB_OUTPUT" + - name: Load image id: load run: | @@ -247,9 +259,9 @@ jobs: tags: | type=raw,value=${{ env.DEFAULT_TAG }} type=raw,value=${{ env.DEFAULT_TAG }}-${{ github.sha }} - type=raw,value=${{ env.DEFAULT_TAG }}.{{date 'YYYYMMDD'}} - type=raw,value=${{ env.DEFAULT_TAG }}.{{date 'YYYYMMDD'}}-${{ github.sha }} - type=raw,value={{ date 'YYYYMMDD'}},enable=${{ env.DEFAULT_TAG == 'latest' }} + type=raw,value=${{ env.DEFAULT_TAG }}.${{ needs.build_push.outputs.image_version }} + type=raw,value=${{ env.DEFAULT_TAG }}.${{ needs.build_push.outputs.image_version }}-${{ github.sha }} + type=raw,value=${{ needs.build_push.outputs.image_version }},enable=${{ env.DEFAULT_TAG == 'latest' }} type=ref,event=pr type=sha,enable=${{ github.event_name == 'pull_request' }} labels: | @@ -268,7 +280,7 @@ jobs: org.opencontainers.image.title=${{ env.IMAGE_NAME }} org.opencontainers.image.url=https://github.com/${{ github.repository_owner }}/${{ env.IMAGE_NAME }}/tree/${{ github.sha }} org.opencontainers.image.vendor=${{ github.repository_owner }} - org.opencontainers.image.version=${{ env.DEFAULT_TAG }}.{{date 'YYYYMMDD'}} + org.opencontainers.image.version=${{ env.DEFAULT_TAG }}.${{ needs.build_push.outputs.image_version }} - name: Login to GitHub Container Registry if: inputs.publish diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 1826b8a..83a006b 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -2,7 +2,7 @@ Thank you for your interest in contributing to Apollo. To help your contribution be accepted more easily, please read through the following first. ## Building -Apollo is made with mkosi and bootc. You'll need mkosi, just, and preferably podman (docker should work too). A hypervisor is also recommended for testing images. +Apollo is made with mkosi and bootc. You'll need mkosi, python, just, and preferably podman (docker should work too). A hypervisor is also recommended for testing images. You can build a bootc-compatible oci archive with mkosi (an Arch-based environment is currently recommended) using the following command: ```bash diff --git a/mkosi.bump b/mkosi.bump index da1ecc2..0a9a6b6 100755 --- a/mkosi.bump +++ b/mkosi.bump @@ -1,5 +1,26 @@ -#!/bin/bash -set -e +#!/usr/bin/env python +from datetime import datetime, timezone -date +%Y%m%d%H%M%S +DEFAULT_INDEX=0 + +cur_date = datetime.now(timezone.utc).strftime("%Y%m%d") +old_date = None +old_index = 0 + +# Try to find the old version. If the file is missing or fails to parse, don't do anything +try: + old_version = open("mkosi.version", "r").read().split(".") + if len(old_version) == 2: + old_date = old_version[0] + old_index = int(old_version[1]) + +except FileNotFoundError, ValueError: + pass + +# If the date timestamp (YYYYMMDD) of the last built version is the same as the one we want to build, increment the counter index. If not, reset to 0 +if old_date != cur_date: + print(f"{cur_date}.{DEFAULT_INDEX}") +else: + new_index = old_index + 1 + print(f"{cur_date}.{new_index}") diff --git a/mkosi.postinst.d/os-info.chroot b/mkosi.postinst.d/os-info.chroot index 785b373..fb14734 100755 --- a/mkosi.postinst.d/os-info.chroot +++ b/mkosi.postinst.d/os-info.chroot @@ -28,4 +28,5 @@ HOME_URL="${HOME_URL}" SUPPORT_URL="${SUPPORT_URL}" LOGO="${LOGO}" DEFAULT_HOSTNAME="${HOSTNAME}" -EOF \ No newline at end of file +IMAGE_VERSION="${IMAGE_VERSION}" +EOF