From 308bff125a5793b5e3b2a9c2f4c64474d80aa4ee Mon Sep 17 00:00:00 2001 From: fithwum Date: Mon, 20 Jul 2026 08:13:40 -0700 Subject: [PATCH] revert change --- .gitea/workflows/teamspeak-build-alpine.yml | 347 ------------------ .gitea/workflows/teamspeak-build-basic.yml | 347 ------------------ ...k-build-debian.yml => teamspeak-build.yml} | 107 +++++- 3 files changed, 98 insertions(+), 703 deletions(-) delete mode 100644 .gitea/workflows/teamspeak-build-alpine.yml delete mode 100644 .gitea/workflows/teamspeak-build-basic.yml rename .gitea/workflows/{teamspeak-build-debian.yml => teamspeak-build.yml} (71%) diff --git a/.gitea/workflows/teamspeak-build-alpine.yml b/.gitea/workflows/teamspeak-build-alpine.yml deleted file mode 100644 index 9c8498c..0000000 --- a/.gitea/workflows/teamspeak-build-alpine.yml +++ /dev/null @@ -1,347 +0,0 @@ -name: Build Teamspeak-alpine - -on: - push: - branches: - - main - paths: - - '.gitea/workflows/teamspeak-build-alpine.yml' - - 'alpine/Dockerfile' - - 'alpine/*.sh' - - '!.cache/*' - - '!alpine/CHANGES.md' - - '!alpine/build-info.json' - schedule: - - cron: '15 21 * * 0' - -env: - IMAGE_REGISTRY: ${{ secrets.REPO_URL }} - IMAGE_ORG: ${{ secrets.GIT_USERNAME }} - IMAGE_REPO_TS: teamspeak-server - CACHE_DIR: .cache - -jobs: - check-for-changes: - runs-on: vm-docker-build2 - outputs: - should_build_alpine: ${{ steps.check.outputs.should_build_alpine }} - alpine_digest: ${{ steps.check.outputs.alpine_digest }} - steps: - - name: Checkout code - uses: actions/checkout@v3 - with: - fetch-depth: 0 - - - name: Ensure .cache directory - run: mkdir -p .cache - - - name: Pull latest base images - run: | - docker pull alpine:latest - - - name: Get base image digests - id: get_digest - run: | - alpine_digest=$(docker inspect --format='{{index .RepoDigests 0}}' alpine:latest || echo "unknown") - - echo "alpine_digest=$alpine_digest" >> $GITHUB_OUTPUT - - - name: Compare digests and detect changes - id: check - run: | - check_variant() { - variant=$1 - new_digest=$2 - digest_file=".cache/${variant}-base.digest" - - last_digest="" - if [ -f "$digest_file" ]; then - last_digest=$(cat "$digest_file") - fi - - if [ "$last_digest" != "$new_digest" ]; then - echo "[INFO] $variant base image changed" - echo "should_build_${variant}=true" >> $GITHUB_OUTPUT - else - echo "[INFO] $variant base image unchanged" - echo "should_build_${variant}=false" >> $GITHUB_OUTPUT - fi - - echo "${variant}_digest=$new_digest" >> $GITHUB_OUTPUT - } - - check_variant alpine "${{ steps.get_digest.outputs.alpine_digest }}" - - build-alpine: - needs: check-for-changes - if: needs.check-for-changes.outputs.should_build_alpine == 'true' - runs-on: vm-docker-build2 - outputs: - built: 'true' - steps: - - name: Checkout - uses: actions/checkout@v3 - with: - fetch-depth: 0 - - - name: Login to Docker registry - run: | - echo "${{ secrets.GIT_TOKEN }}" | docker login gitea.fithwum.tech -u "${{ secrets.GIT_USERNAME }}" --password-stdin - - - name: Build and Push Alpine Image - run: | - mkdir -p "${{ env.CACHE_DIR }}" - IMAGE="${{ env.IMAGE_REGISTRY }}/${{ env.IMAGE_ORG }}/${{ env.IMAGE_REPO_TS }}:alpine" - METAFILE="${{ env.CACHE_DIR }}/metadata-alpine.json" - echo "[INFO] Building $IMAGE" - docker buildx build --platform linux/amd64 --push -t "$IMAGE" --metadata-file "$METAFILE" ./alpine - - update-base-digest-cache: - needs: - - check-for-changes - - build-alpine - runs-on: vm-docker-build2 - steps: - - uses: actions/checkout@v3 - with: - fetch-depth: 0 - - - name: Update base digest cache - run: | - git config user.name "${{ secrets.GIT_USERNAME }}" - git config user.email "${{ secrets.GIT_EMAIL }}" - - mkdir -p .cache - - [[ "${{ needs.build-alpine.outputs.built }}" == "true" ]] && \ - echo "${{ needs.check-for-changes.outputs.alpine_digest }}" > .cache/alpine-base.digest - - if git status --porcelain | grep .; then - # Create a temporary branch - TEMP_BRANCH="tmp-digest-$(date -u +%s)" - git checkout -b "$TEMP_BRANCH" - - git add .cache/*-base.digest - git commit -m "Update base image digests ($(date -u +'%Y-%m-%dT%H:%M:%SZ'))" - - # Push temporary branch - git push origin "$TEMP_BRANCH" - - # Merge temp branch into main safely - git checkout main - git fetch origin main - git merge --no-ff --no-edit "$TEMP_BRANCH" - - # Push main branch - git push origin main - - # Delete temporary branch remotely - git push origin --delete "$TEMP_BRANCH" || true - else - echo "[INFO] No digest updates to commit." - fi - - generate-build-info: - needs: - - update-base-digest-cache - - build-alpine - if: | - needs.build-alpine.outputs.built == 'true' - runs-on: vm-docker-build2 - steps: - - name: Checkout source - uses: actions/checkout@v3 - with: - fetch-depth: 0 - - - name: Load digests from cache - id: base_digests - run: | - load_digest() { - file=".cache/$1-base.digest" - if [ -f "$file" ]; then - cat "$file" - else - echo "unknown" - fi - } - - echo "alpine=$(load_digest alpine)" >> $GITHUB_OUTPUT - - - name: Generate build-info.json for each variant - env: - IMAGE_REGISTRY: ${{ env.IMAGE_REGISTRY }} - IMAGE_ORG: ${{ env.IMAGE_ORG }} - IMAGE_REPO_TS: ${{ env.IMAGE_REPO_TS }} - run: | - variants=(alpine) - - human_size() { - local b=$1 - local d='' - local s=0 - local S=(B KB MB GB TB) - while ((b >= 1024 && s < ${#S[@]}-1)); do - d=$((b % 1024)) - b=$((b / 1024)) - s=$((s + 1)) - done - printf "%s%s\n" "$b" "${S[$s]}" - } - - variants=() - [[ "${{ needs.build-alpine.outputs.built }}" == "true" ]] && variants+=("alpine") - - for variant in "${variants[@]}"; do - image_tag="${IMAGE_REGISTRY}/${IMAGE_ORG}/${IMAGE_REPO_TS}:${variant}" - digest=$(docker inspect --format='{{index .RepoDigests 0}}' "$image_tag" 2>/dev/null || echo "unknown") - size_bytes=$(docker image inspect "$image_tag" --format='{{.Size}}' 2>/dev/null || echo 0) - size_human=$(numfmt --to=iec --suffix=B $size_bytes 2>/dev/null || echo "${size_bytes}B") - commit_hash=$(git rev-parse HEAD) - build_time=$(date -u +"%Y-%m-%dT%H:%M:%SZ") - - case "$variant" in - alpine) - base_digest="${{ steps.base_digests.outputs.alpine }}" - ;; - esac - - mkdir -p "$variant" - jq -n \ - --arg version "$variant" \ - --arg commit "$commit_hash" \ - --arg build_time "$build_time" \ - --arg image_tag "$image_tag" \ - --arg digest "$digest" \ - --arg image_size "$size_human" \ - --argjson image_size_bytes "$size_bytes" \ - --arg base_digest "$base_digest" \ - '{ - version: $version, - commit: $commit, - build_time: $build_time, - image_tag: $image_tag, - digest: $digest, - image_size: $image_size, - image_size_bytes: $image_size_bytes, - base_digest: $base_digest - }' > "$variant/build-info.json" - done - - - name: Show generated build-info.json - run: | - find . -name build-info.json -exec echo '--- {} ---' \; -exec cat {} \; - - - name: Commit and push build-info if changed - run: | - git config user.name "${{ secrets.GIT_USERNAME }}" - git config user.email "${{ secrets.GIT_EMAIL }}" - - if git status --porcelain | grep .; then - # Create a temporary branch - TEMP_BRANCH="tmp-buildinfo-$(date -u +%s)" - git checkout -b "$TEMP_BRANCH" - - git add */build-info.json - git commit -m "Update build-info on $(date -u +'%Y-%m-%dT%H:%M:%SZ')" - - # Push temp branch - git push origin "$TEMP_BRANCH" - - # Switch back to main - git checkout main - git fetch origin main - - # Merge temp branch using --allow-unrelated-histories (safe in CI) - git merge --no-ff --no-edit "$TEMP_BRANCH" || true - - # Force push main to remote to ensure update - git push origin main --force - - # Delete temporary branch locally and remotely - git branch -D "$TEMP_BRANCH" - git push origin --delete "$TEMP_BRANCH" || true - else - echo "[INFO] No build-info changes to commit." - fi - - generate-changelogs: - needs: - - check-for-changes - - generate-build-info - if: | - needs.check-for-changes.outputs.should_build_alpine == 'true' - runs-on: vm-docker-build2 - steps: - - name: Checkout source - uses: actions/checkout@v3 - with: - fetch-depth: 0 - - - name: Sync with latest main - run: | - git fetch origin main - git reset --hard origin/main - - - name: Generate changelogs only for updated variants - run: | - versions=() - if [[ "${{ needs.check-for-changes.outputs.should_build_alpine }}" == "true" ]]; then - versions+=("alpine") - fi - - for version in "${versions[@]}"; do - echo "[INFO] Updating changelog for $version" - changelog="$version/CHANGES.md" - mkdir -p "$(dirname "$changelog")" - touch "$changelog" - - infofile="$version/build-info.json" - last_commit="" - if [ -f "$infofile" ]; then - last_commit=$(jq -r '.commit' "$infofile") - fi - - # Check if last_commit exists in history, fallback to last 10 commits if not - if ! git cat-file -e "${last_commit}^{commit}" 2>/dev/null; then - echo "[WARN] Last commit from build-info.json not found, using last 10 commits" - last_commit="" - fi - - echo -e "\n## $(date -u +'%Y-%m-%dT%H:%M:%SZ')" >> "$changelog" - git log -n 10 --pretty=format:"- %s (%an)" \ - --no-merges \ - --invert-grep \ - --grep="Update changelogs on" >> "$changelog" - - done - - - name: Commit and push changelogs - run: | - git config user.name "${{ secrets.GIT_USERNAME }}" - git config user.email "${{ secrets.GIT_EMAIL }}" - - if git status --porcelain | grep .; then - # Create a temporary branch - TEMP_BRANCH="tmp-changelog-$(date -u +%s)" - git checkout -b "$TEMP_BRANCH" - - git add */CHANGES.md - git commit -m "Update changelogs on $(date -u +'%Y-%m-%dT%H:%M:%SZ')" --no-verify - - # Push temporary branch - git push origin "$TEMP_BRANCH" - - # Merge temporary branch into main safely - git checkout main - git fetch origin main - git merge --no-ff --no-edit "$TEMP_BRANCH" - - # Push main branch - git push origin main - - # Delete temporary branch remotely - git push origin --delete "$TEMP_BRANCH" || true - else - echo "[INFO] No changelog changes to commit." - fi \ No newline at end of file diff --git a/.gitea/workflows/teamspeak-build-basic.yml b/.gitea/workflows/teamspeak-build-basic.yml deleted file mode 100644 index 347e914..0000000 --- a/.gitea/workflows/teamspeak-build-basic.yml +++ /dev/null @@ -1,347 +0,0 @@ -name: Build Teamspeak-basic(debian) - -on: - push: - branches: - - main - paths: - - '.gitea/workflows/teamspeak-build-basic.yml' - - 'basic/Dockerfile' - - 'basic/*.sh' - - '!.cache/*' - - '!basic/CHANGES.md' - - '!basic/build-info.json' - schedule: - - cron: '15 21 * * 0' - -env: - IMAGE_REGISTRY: ${{ secrets.REPO_URL }} - IMAGE_ORG: ${{ secrets.GIT_USERNAME }} - IMAGE_REPO_TS: teamspeak-server - CACHE_DIR: .cache - -jobs: - check-for-changes: - runs-on: vm-docker-build2 - outputs: - should_build_basic: ${{ steps.check.outputs.should_build_basic }} - basic_digest: ${{ steps.check.outputs.basic_digest }} - steps: - - name: Checkout code - uses: actions/checkout@v3 - with: - fetch-depth: 0 - - - name: Ensure .cache directory - run: mkdir -p .cache - - - name: Pull latest base images - run: | - docker pull gitea.fithwum.tech/${{ secrets.GIT_USERNAME }}/debian-base:bookworm - - - name: Get base image digests - id: get_digest - run: | - basic_digest=$(docker inspect --format='{{index .RepoDigests 0}}' gitea.fithwum.tech/${{ secrets.GIT_USERNAME }}/debian-base:bookworm || echo "unknown") - - echo "basic_digest=$basic_digest" >> $GITHUB_OUTPUT - - - name: Compare digests and detect changes - id: check - run: | - check_variant() { - variant=$1 - new_digest=$2 - digest_file=".cache/${variant}-base.digest" - - last_digest="" - if [ -f "$digest_file" ]; then - last_digest=$(cat "$digest_file") - fi - - if [ "$last_digest" != "$new_digest" ]; then - echo "[INFO] $variant base image changed" - echo "should_build_${variant}=true" >> $GITHUB_OUTPUT - else - echo "[INFO] $variant base image unchanged" - echo "should_build_${variant}=false" >> $GITHUB_OUTPUT - fi - - echo "${variant}_digest=$new_digest" >> $GITHUB_OUTPUT - } - - check_variant basic "${{ steps.get_digest.outputs.basic_digest }}" - - build-basic: - needs: check-for-changes - if: needs.check-for-changes.outputs.should_build_basic == 'true' - runs-on: vm-docker-build2 - outputs: - built: 'true' - steps: - - name: Checkout - uses: actions/checkout@v3 - with: - fetch-depth: 0 - - - name: Login to Docker registry - run: | - echo "${{ secrets.GIT_TOKEN }}" | docker login gitea.fithwum.tech -u "${{ secrets.GIT_USERNAME }}" --password-stdin - - - name: Build and Push Basic Image - run: | - mkdir -p "${{ env.CACHE_DIR }}" - IMAGE="${{ env.IMAGE_REGISTRY }}/${{ env.IMAGE_ORG }}/${{ env.IMAGE_REPO_TS }}:basic" - METAFILE2="${{ env.CACHE_DIR }}/metadata-basic.json" - echo "[INFO] Building $IMAGE" - docker buildx build --platform linux/amd64 --push -t "$IMAGE" --metadata-file "$METAFILE2" ./basic - - update-base-digest-cache: - needs: - - check-for-changes - - build-basic - runs-on: vm-docker-build2 - steps: - - uses: actions/checkout@v3 - with: - fetch-depth: 0 - - - name: Update base digest cache - run: | - git config user.name "${{ secrets.GIT_USERNAME }}" - git config user.email "${{ secrets.GIT_EMAIL }}" - - mkdir -p .cache - - [[ "${{ needs.build-basic.outputs.built }}" == "true" ]] && \ - echo "${{ needs.check-for-changes.outputs.basic_digest }}" > .cache/basic-base.digest - - if git status --porcelain | grep .; then - # Create a temporary branch - TEMP_BRANCH="tmp-digest-$(date -u +%s)" - git checkout -b "$TEMP_BRANCH" - - git add .cache/*-base.digest - git commit -m "Update base image digests ($(date -u +'%Y-%m-%dT%H:%M:%SZ'))" - - # Push temporary branch - git push origin "$TEMP_BRANCH" - - # Merge temp branch into main safely - git checkout main - git fetch origin main - git merge --no-ff --no-edit "$TEMP_BRANCH" - - # Push main branch - git push origin main - - # Delete temporary branch remotely - git push origin --delete "$TEMP_BRANCH" || true - else - echo "[INFO] No digest updates to commit." - fi - - generate-build-info: - needs: - - update-base-digest-cache - - build-basic - if: | - needs.build-basic.outputs.built == 'true' - runs-on: vm-docker-build2 - steps: - - name: Checkout source - uses: actions/checkout@v3 - with: - fetch-depth: 0 - - - name: Load digests from cache - id: base_digests - run: | - load_digest() { - file=".cache/$1-base.digest" - if [ -f "$file" ]; then - cat "$file" - else - echo "unknown" - fi - } - - echo "basic=$(load_digest basic)" >> $GITHUB_OUTPUT - - - name: Generate build-info.json for each variant - env: - IMAGE_REGISTRY: ${{ env.IMAGE_REGISTRY }} - IMAGE_ORG: ${{ env.IMAGE_ORG }} - IMAGE_REPO_TS: ${{ env.IMAGE_REPO_TS }} - run: | - variants=(basic) - - human_size() { - local b=$1 - local d='' - local s=0 - local S=(B KB MB GB TB) - while ((b >= 1024 && s < ${#S[@]}-1)); do - d=$((b % 1024)) - b=$((b / 1024)) - s=$((s + 1)) - done - printf "%s%s\n" "$b" "${S[$s]}" - } - - variants=() - [[ "${{ needs.build-basic.outputs.built }}" == "true" ]] && variants+=("basic") - - for variant in "${variants[@]}"; do - image_tag="${IMAGE_REGISTRY}/${IMAGE_ORG}/${IMAGE_REPO_TS}:${variant}" - digest=$(docker inspect --format='{{index .RepoDigests 0}}' "$image_tag" 2>/dev/null || echo "unknown") - size_bytes=$(docker image inspect "$image_tag" --format='{{.Size}}' 2>/dev/null || echo 0) - size_human=$(numfmt --to=iec --suffix=B $size_bytes 2>/dev/null || echo "${size_bytes}B") - commit_hash=$(git rev-parse HEAD) - build_time=$(date -u +"%Y-%m-%dT%H:%M:%SZ") - - case "$variant" in - basic) - base_digest="${{ steps.base_digests.outputs.basic }}" - ;; - esac - - mkdir -p "$variant" - jq -n \ - --arg version "$variant" \ - --arg commit "$commit_hash" \ - --arg build_time "$build_time" \ - --arg image_tag "$image_tag" \ - --arg digest "$digest" \ - --arg image_size "$size_human" \ - --argjson image_size_bytes "$size_bytes" \ - --arg base_digest "$base_digest" \ - '{ - version: $version, - commit: $commit, - build_time: $build_time, - image_tag: $image_tag, - digest: $digest, - image_size: $image_size, - image_size_bytes: $image_size_bytes, - base_digest: $base_digest - }' > "$variant/build-info.json" - done - - - name: Show generated build-info.json - run: | - find . -name build-info.json -exec echo '--- {} ---' \; -exec cat {} \; - - - name: Commit and push build-info if changed - run: | - git config user.name "${{ secrets.GIT_USERNAME }}" - git config user.email "${{ secrets.GIT_EMAIL }}" - - if git status --porcelain | grep .; then - # Create a temporary branch - TEMP_BRANCH="tmp-buildinfo-$(date -u +%s)" - git checkout -b "$TEMP_BRANCH" - - git add */build-info.json - git commit -m "Update build-info on $(date -u +'%Y-%m-%dT%H:%M:%SZ')" - - # Push temp branch - git push origin "$TEMP_BRANCH" - - # Switch back to main - git checkout main - git fetch origin main - - # Merge temp branch using --allow-unrelated-histories (safe in CI) - git merge --no-ff --no-edit "$TEMP_BRANCH" || true - - # Force push main to remote to ensure update - git push origin main --force - - # Delete temporary branch locally and remotely - git branch -D "$TEMP_BRANCH" - git push origin --delete "$TEMP_BRANCH" || true - else - echo "[INFO] No build-info changes to commit." - fi - - generate-changelogs: - needs: - - check-for-changes - - generate-build-info - if: | - needs.check-for-changes.outputs.should_build_basic == 'true' - runs-on: vm-docker-build2 - steps: - - name: Checkout source - uses: actions/checkout@v3 - with: - fetch-depth: 0 - - - name: Sync with latest main - run: | - git fetch origin main - git reset --hard origin/main - - - name: Generate changelogs only for updated variants - run: | - versions=() - if [[ "${{ needs.check-for-changes.outputs.should_build_basic }}" == "true" ]]; then - versions+=("basic") - fi - - for version in "${versions[@]}"; do - echo "[INFO] Updating changelog for $version" - changelog="$version/CHANGES.md" - mkdir -p "$(dirname "$changelog")" - touch "$changelog" - - infofile="$version/build-info.json" - last_commit="" - if [ -f "$infofile" ]; then - last_commit=$(jq -r '.commit' "$infofile") - fi - - # Check if last_commit exists in history, fallback to last 10 commits if not - if ! git cat-file -e "${last_commit}^{commit}" 2>/dev/null; then - echo "[WARN] Last commit from build-info.json not found, using last 10 commits" - last_commit="" - fi - - echo -e "\n## $(date -u +'%Y-%m-%dT%H:%M:%SZ')" >> "$changelog" - git log -n 10 --pretty=format:"- %s (%an)" \ - --no-merges \ - --invert-grep \ - --grep="Update changelogs on" >> "$changelog" - - done - - - name: Commit and push changelogs - run: | - git config user.name "${{ secrets.GIT_USERNAME }}" - git config user.email "${{ secrets.GIT_EMAIL }}" - - if git status --porcelain | grep .; then - # Create a temporary branch - TEMP_BRANCH="tmp-changelog-$(date -u +%s)" - git checkout -b "$TEMP_BRANCH" - - git add */CHANGES.md - git commit -m "Update changelogs on $(date -u +'%Y-%m-%dT%H:%M:%SZ')" --no-verify - - # Push temporary branch - git push origin "$TEMP_BRANCH" - - # Merge temporary branch into main safely - git checkout main - git fetch origin main - git merge --no-ff --no-edit "$TEMP_BRANCH" - - # Push main branch - git push origin main - - # Delete temporary branch remotely - git push origin --delete "$TEMP_BRANCH" || true - else - echo "[INFO] No changelog changes to commit." - fi \ No newline at end of file diff --git a/.gitea/workflows/teamspeak-build-debian.yml b/.gitea/workflows/teamspeak-build.yml similarity index 71% rename from .gitea/workflows/teamspeak-build-debian.yml rename to .gitea/workflows/teamspeak-build.yml index e86f8fd..be085f4 100644 --- a/.gitea/workflows/teamspeak-build-debian.yml +++ b/.gitea/workflows/teamspeak-build.yml @@ -1,16 +1,16 @@ -name: Build Teamspeak-debian +name: Build and Push Teamspeak Images on Base Image Update on: push: branches: - main paths: - - '.gitea/workflows/teamspeak-build-debian.yml' - - 'debian/Dockerfile' - - 'debian/*.sh' + - '.gitea/workflows/*.yml' + - '**/Dockerfile' + - '**/*.sh' - '!.cache/*' - - '!debian/CHANGES.md' - - '!debian/build-info.json' + - '!**/CHANGES.md' + - '!**/build-info.json' schedule: - cron: '15 21 * * 0' @@ -24,8 +24,12 @@ jobs: check-for-changes: runs-on: vm-docker-build2 outputs: + should_build_alpine: ${{ steps.check.outputs.should_build_alpine }} should_build_debian: ${{ steps.check.outputs.should_build_debian }} + should_build_basic: ${{ steps.check.outputs.should_build_basic }} + alpine_digest: ${{ steps.check.outputs.alpine_digest }} debian_digest: ${{ steps.check.outputs.debian_digest }} + basic_digest: ${{ steps.check.outputs.basic_digest }} steps: - name: Checkout code uses: actions/checkout@v3 @@ -37,14 +41,19 @@ jobs: - name: Pull latest base images run: | + docker pull alpine:latest docker pull gitea.fithwum.tech/${{ secrets.GIT_USERNAME }}/debian-base:bookworm - name: Get base image digests id: get_digest run: | + alpine_digest=$(docker inspect --format='{{index .RepoDigests 0}}' alpine:latest || echo "unknown") debian_digest=$(docker inspect --format='{{index .RepoDigests 0}}' gitea.fithwum.tech/${{ secrets.GIT_USERNAME }}/debian-base:bookworm || echo "unknown") + basic_digest=$debian_digest # basic uses debian-base + echo "alpine_digest=$alpine_digest" >> $GITHUB_OUTPUT echo "debian_digest=$debian_digest" >> $GITHUB_OUTPUT + echo "basic_digest=$basic_digest" >> $GITHUB_OUTPUT - name: Compare digests and detect changes id: check @@ -70,7 +79,33 @@ jobs: echo "${variant}_digest=$new_digest" >> $GITHUB_OUTPUT } + check_variant alpine "${{ steps.get_digest.outputs.alpine_digest }}" check_variant debian "${{ steps.get_digest.outputs.debian_digest }}" + check_variant basic "${{ steps.get_digest.outputs.basic_digest }}" + + build-alpine: + needs: check-for-changes + if: needs.check-for-changes.outputs.should_build_alpine == 'true' + runs-on: vm-docker-build2 + outputs: + built: 'true' + steps: + - name: Checkout + uses: actions/checkout@v3 + with: + fetch-depth: 0 + + - name: Login to Docker registry + run: | + echo "${{ secrets.GIT_TOKEN }}" | docker login gitea.fithwum.tech -u "${{ secrets.GIT_USERNAME }}" --password-stdin + + - name: Build and Push Alpine Image + run: | + mkdir -p "${{ env.CACHE_DIR }}" + IMAGE="${{ env.IMAGE_REGISTRY }}/${{ env.IMAGE_ORG }}/${{ env.IMAGE_REPO_TS }}:alpine" + METAFILE="${{ env.CACHE_DIR }}/metadata-alpine.json" + echo "[INFO] Building $IMAGE" + docker buildx build --platform linux/amd64 --push -t "$IMAGE" --metadata-file "$METAFILE" ./alpine build-debian: needs: check-for-changes @@ -96,10 +131,36 @@ jobs: echo "[INFO] Building $IMAGE" docker buildx build --platform linux/amd64 --push -t "$IMAGE" --metadata-file "$METAFILE" ./debian + build-basic: + needs: check-for-changes + if: needs.check-for-changes.outputs.should_build_basic == 'true' + runs-on: vm-docker-build2 + outputs: + built: 'true' + steps: + - name: Checkout + uses: actions/checkout@v3 + with: + fetch-depth: 0 + + - name: Login to Docker registry + run: | + echo "${{ secrets.GIT_TOKEN }}" | docker login gitea.fithwum.tech -u "${{ secrets.GIT_USERNAME }}" --password-stdin + + - name: Build and Push Basic Image + run: | + mkdir -p "${{ env.CACHE_DIR }}" + IMAGE="${{ env.IMAGE_REGISTRY }}/${{ env.IMAGE_ORG }}/${{ env.IMAGE_REPO_TS }}:basic" + METAFILE2="${{ env.CACHE_DIR }}/metadata-basic.json" + echo "[INFO] Building $IMAGE" + docker buildx build --platform linux/amd64 --push -t "$IMAGE" --metadata-file "$METAFILE2" ./basic + update-base-digest-cache: needs: - check-for-changes + - build-alpine - build-debian + - build-basic runs-on: vm-docker-build2 steps: - uses: actions/checkout@v3 @@ -113,9 +174,15 @@ jobs: mkdir -p .cache + [[ "${{ needs.build-alpine.outputs.built }}" == "true" ]] && \ + echo "${{ needs.check-for-changes.outputs.alpine_digest }}" > .cache/alpine-base.digest + [[ "${{ needs.build-debian.outputs.built }}" == "true" ]] && \ echo "${{ needs.check-for-changes.outputs.debian_digest }}" > .cache/debian-base.digest + [[ "${{ needs.build-basic.outputs.built }}" == "true" ]] && \ + echo "${{ needs.check-for-changes.outputs.basic_digest }}" > .cache/basic-base.digest + if git status --porcelain | grep .; then # Create a temporary branch TEMP_BRANCH="tmp-digest-$(date -u +%s)" @@ -144,9 +211,13 @@ jobs: generate-build-info: needs: - update-base-digest-cache + - build-alpine - build-debian + - build-basic if: | - needs.build-debian.outputs.built == 'true' + needs.build-alpine.outputs.built == 'true' || + needs.build-debian.outputs.built == 'true' || + needs.build-basic.outputs.built == 'true' runs-on: vm-docker-build2 steps: - name: Checkout source @@ -166,7 +237,9 @@ jobs: fi } + echo "alpine=$(load_digest alpine)" >> $GITHUB_OUTPUT echo "debian=$(load_digest debian)" >> $GITHUB_OUTPUT + echo "basic=$(load_digest basic)" >> $GITHUB_OUTPUT - name: Generate build-info.json for each variant env: @@ -174,7 +247,7 @@ jobs: IMAGE_ORG: ${{ env.IMAGE_ORG }} IMAGE_REPO_TS: ${{ env.IMAGE_REPO_TS }} run: | - variants=(debian) + variants=(alpine debian basic) human_size() { local b=$1 @@ -190,7 +263,9 @@ jobs: } variants=() + [[ "${{ needs.build-alpine.outputs.built }}" == "true" ]] && variants+=("alpine") [[ "${{ needs.build-debian.outputs.built }}" == "true" ]] && variants+=("debian") + [[ "${{ needs.build-basic.outputs.built }}" == "true" ]] && variants+=("basic") for variant in "${variants[@]}"; do image_tag="${IMAGE_REGISTRY}/${IMAGE_ORG}/${IMAGE_REPO_TS}:${variant}" @@ -201,9 +276,15 @@ jobs: build_time=$(date -u +"%Y-%m-%dT%H:%M:%SZ") case "$variant" in + alpine) + base_digest="${{ steps.base_digests.outputs.alpine }}" + ;; debian) base_digest="${{ steps.base_digests.outputs.debian }}" ;; + basic) + base_digest="${{ steps.base_digests.outputs.basic }}" + ;; esac mkdir -p "$variant" @@ -270,7 +351,9 @@ jobs: - check-for-changes - generate-build-info if: | - needs.check-for-changes.outputs.should_build_debian == 'true' + needs.check-for-changes.outputs.should_build_alpine == 'true' || + needs.check-for-changes.outputs.should_build_debian == 'true' || + needs.check-for-changes.outputs.should_build_basic == 'true' runs-on: vm-docker-build2 steps: - name: Checkout source @@ -286,9 +369,15 @@ jobs: - name: Generate changelogs only for updated variants run: | versions=() + if [[ "${{ needs.check-for-changes.outputs.should_build_alpine }}" == "true" ]]; then + versions+=("alpine") + fi if [[ "${{ needs.check-for-changes.outputs.should_build_debian }}" == "true" ]]; then versions+=("debian") fi + if [[ "${{ needs.check-for-changes.outputs.should_build_basic }}" == "true" ]]; then + versions+=("basic") + fi for version in "${versions[@]}"; do echo "[INFO] Updating changelog for $version"