From 434111d2d439dee7d4588e046b4b5960f0377d0f Mon Sep 17 00:00:00 2001 From: "Luis Guzman (AppDevForAll)" Date: Fri, 30 Oct 2026 03:20:43 -0600 Subject: [PATCH 1/3] K2GO-511 feat(bake): add dev mode (dev_latest_* staging pointers) dev uploads the dated tarballs and writes dev_latest_* pointers only, leaving the stable latest_* and the shared catalog inputs untouched; it never prunes. test and dev honor the tier/arch filters; publish alone moves latest_* and prunes. --- .github/workflows/bake-rootfs.yml | 115 +++++++++++++++++------------- 1 file changed, 67 insertions(+), 48 deletions(-) diff --git a/.github/workflows/bake-rootfs.yml b/.github/workflows/bake-rootfs.yml index a6090bd24..471da716c 100644 --- a/.github/workflows/bake-rootfs.yml +++ b/.github/workflows/bake-rootfs.yml @@ -12,27 +12,30 @@ name: Bake & publish K2Go RootFS # Debian tarballs K2Go builds on) into R2 exactly once, then only verifies its presence # on every later run. Retention: the prune keeps the newest 7 batches per (tier,arch). # -# K2GO-511: mode=test builds only. It uploads nothing and keeps no artifacts, so it is -# safe for trying an IIAB change. The seed-base job still runs: the builder downloads the -# base from R2, and seed-base only mirrors the pinned upstream base when it is missing. +# K2GO-511: three modes. test builds only (uploads nothing, keeps no artifacts), so it is safe +# for trying an IIAB change. dev stages the build as dev_latest_* pointers for on-device testing +# and touches NEITHER the stable latest_* NOR the shared catalog inputs (build-*.log, +# PUBLISH_QUEUE*.tsv). publish moves the stable latest_* pointers (what a production install +# downloads). The seed-base job runs in every mode: the builder downloads the base from R2, and +# seed-base only mirrors the pinned upstream base when it is missing. -run-name: Bake rootfs (${{ inputs.mode }}, ${{ inputs.mode == 'test' && format('{0} {1}', inputs.tier, inputs.arch) || 'all tiers, both arches' }}) +run-name: Bake rootfs (${{ inputs.mode }}, ${{ inputs.mode != 'publish' && format('{0} {1}', inputs.tier, inputs.arch) || 'all tiers, both arches' }}) on: workflow_dispatch: # manual only for now inputs: mode: - description: "test = build only, nothing uploaded. publish = upload to R2 and move the latest_* pointers." + description: "test = build only, nothing uploaded. dev = upload as dev_latest_* staging pointers (stable latest_* untouched). publish = upload and move the stable latest_* pointers (production)." type: choice - options: [test, publish] + options: [test, dev, publish] default: test tier: - description: "Tier to build (test mode only; publish always builds all)." + description: "Tier to build (test and dev modes only; publish always builds all)." type: choice options: [all, basic, standard, full, matomo] default: all arch: - description: "Architecture to build (test mode only; publish always builds both)." + description: "Architecture to build (test and dev modes only; publish always builds both)." type: choice options: [all, arm64-v8a, armeabi-v7a] default: all @@ -124,22 +127,22 @@ jobs: fail-fast: false # one arch must not cancel the other max-parallel: 2 # one node per arch, both at once matrix: - arch: ${{ fromJSON(inputs.mode == 'test' && inputs.arch != 'all' && format('["{0}"]', inputs.arch) || '["arm64-v8a","armeabi-v7a"]') }} + arch: ${{ fromJSON(inputs.mode != 'publish' && inputs.arch != 'all' && format('["{0}"]', inputs.arch) || '["arm64-v8a","armeabi-v7a"]') }} steps: - name: Checkout uses: actions/checkout@v5 - name: Ensure AWS CLI is available - if: inputs.mode == 'publish' + if: inputs.mode != 'test' run: aws --version || { sudo apt-get update && sudo apt-get install -y awscli; } - - name: Build ${{ inputs.mode == 'test' && inputs.tier || 'all' }} tier(s) for ${{ matrix.arch }} + - name: Build ${{ inputs.mode != 'publish' && inputs.tier || 'all' }} tier(s) for ${{ matrix.arch }} run: | TAG_ARG="" [ -n "${{ inputs.binaries_tag }}" ] && TAG_ARG="--binaries-tag ${{ inputs.binaries_tag }}" TIER_ARG="--all-tier" - [ "${{ inputs.mode }}" = test ] && [ "${{ inputs.tier }}" != all ] && TIER_ARG="--tier ${{ inputs.tier }}" + [ "${{ inputs.mode }}" != publish ] && [ "${{ inputs.tier }}" != all ] && TIER_ARG="--tier ${{ inputs.tier }}" sudo bash ./tools/rootfs-builder/build-iiab-rootfs.sh \ $TIER_ARG --arch "${{ matrix.arch }}" \ $TAG_ARG \ @@ -152,25 +155,36 @@ jobs: run: | { echo "### ${{ inputs.mode }} bake, ${{ matrix.arch }}" - if [ "${{ inputs.mode }}" = test ]; then echo "Test mode: nothing was uploaded."; fi + case "${{ inputs.mode }}" in + test) echo "Test mode: nothing was uploaded." ;; + dev) echo "Dev mode: staged as dev_latest_* (production latest_* untouched)." ;; + esac echo '```' ls -lh dist 2>/dev/null || echo "dist/ was not created" echo '```' } >> "$GITHUB_STEP_SUMMARY" - - name: Publish to R2 + prune (keep newest 7 per tier/arch) - if: inputs.mode == 'publish' + - name: Publish to R2 (${{ inputs.mode }}) + prune + if: inputs.mode != 'test' env: AWS_ACCESS_KEY_ID: ${{ vars.CLOUDFLARE_KEY_ID }} AWS_SECRET_ACCESS_KEY: ${{ secrets.CLOUDFLARE_SECRET_ACCESS_KEY }} run: | set -euo pipefail ARCH="${{ matrix.arch }}" + MODE="${{ inputs.mode }}" KEEP=7 # keep newest 7 batches per (tier,arch); heavy uploads, ~100GB at 7 ENDPOINT="https://${R2_ACCOUNT_ID}.r2.cloudflarestorage.com" PFX="${R2_KEY_PREFIX:-}" # '' or 'rootfs/' cd dist + # K2GO-511: dev and publish upload the SAME dated tarballs but write DIFFERENT pointer + # families. publish owns the stable latest_* pointers and the shared catalog inputs + # (build-*.log, PUBLISH_QUEUE*.tsv) the production catalogs consume. dev writes only + # dev_latest_* and touches NEITHER latest_* NOR those shared inputs, and never prunes, so a + # staging bake cannot change or delete anything a production install depends on. + if [ "$MODE" = dev ]; then PP="dev_latest_"; else PP="latest_"; fi + # 1) Big artifacts FIRST (data before any pointer that resolves to them). shopt -s nullglob for f in k2go_*.tar.gz; do @@ -178,40 +192,45 @@ jobs: aws s3 cp "$f" "s3://${BUCKET_NAME}/${PFX}${f}" --endpoint-url "$ENDPOINT" done - # 2) Everything ELSE in dist/ EXCEPT the stable pointers. Publish the WHOLE dist/, - # nothing is dropped: per-artifact sidecars (.meta4/.sha256/.installed/.torrent), - # the build--.log installer logs (consumed to compute catalogs), and - # PUBLISH_QUEUE.tsv. Tarballs are already up (step 1); the stable latest_* pointers - # are held for step 3 so a client never reads a pointer to a half-uploaded file. - aws s3 cp . "s3://${BUCKET_NAME}/${PFX}" --recursive \ - --exclude "*.tar.gz" \ - --exclude "latest_*.meta4" --exclude "latest_*.installed" \ - --endpoint-url "$ENDPOINT" - - # 3) Flip the stable pointers LAST (they overwrite; only after the data is fully up, - # so a client reading the new latest_*.meta4 never points at a half-uploaded tarball). + # 2) Per-artifact sidecars (.meta4/.sha256/.installed/.torrent). The stable latest_* + # pointers are held for step 3 so a client never reads a pointer to a half-uploaded + # file. dev ALSO holds back the shared catalog inputs (build--.log, + # PUBLISH_QUEUE.tsv) so a staging bake never overwrites what the production catalogs read. + EXCLUDES=(--exclude "*.tar.gz" --exclude "latest_*.meta4" --exclude "latest_*.installed") + if [ "$MODE" = dev ]; then EXCLUDES+=(--exclude "build-*.log" --exclude "PUBLISH_QUEUE*.tsv"); fi + aws s3 cp . "s3://${BUCKET_NAME}/${PFX}" --recursive "${EXCLUDES[@]}" --endpoint-url "$ENDPOINT" + + # 3) Flip the pointers LAST (only after the data is fully up, so a client reading a pointer + # never lands on a half-uploaded tarball). The builder writes latest_*; dev republishes + # those same bytes under dev_latest_* and leaves latest_* untouched. for f in latest_*.meta4 latest_*.installed; do - echo ">> pointer $f" - aws s3 cp "$f" "s3://${BUCKET_NAME}/${PFX}${f}" --endpoint-url "$ENDPOINT" + dest="${f/latest_/$PP}" + echo ">> pointer $dest" + aws s3 cp "$f" "s3://${BUCKET_NAME}/${PFX}${dest}" --endpoint-url "$ENDPOINT" done - # 4) Prune: keep only the newest $KEEP batches per (tier,arch); delete older + sidecars. - # Only the heavy dated tarballs accumulate (they carry _); logs and the - # TSV overwrite in place, so they never pile up. The prefix filter matches k2go_* - # only, so proot-distro-v*/ is never touched. - for meta in latest_*_"${ARCH}".meta4; do - base="${meta%.meta4}"; te="${base#latest_}"; tier="${te%_${ARCH}}" - mapfile -t keys < <(aws s3api list-objects-v2 --bucket "$BUCKET_NAME" \ - --prefix "${PFX}k2go_" --endpoint-url "$ENDPOINT" \ - --query "sort_by(Contents,&LastModified)[?contains(Key,'_${tier}_') && ends_with(Key,'_${ARCH}.tar.gz')].Key" \ - --output text | tr '\t' '\n' | sed '/^$/d') - n=${#keys[@]} - if (( n > KEEP )); then - for key in "${keys[@]:0:n-KEEP}"; do - echo ">> prune $key (+ sidecars)" - for ext in '' .meta4 .sha256 .installed .torrent; do - aws s3 rm "s3://${BUCKET_NAME}/${key}${ext}" --endpoint-url "$ENDPOINT" || true + # 4) Prune (publish only; dev never deletes): keep the newest $KEEP batches per (tier,arch); + # delete older + sidecars. Only the heavy dated tarballs accumulate (they carry + # _); logs and the TSV overwrite in place, so they never pile up. The prefix + # filter matches k2go_* only, so proot-distro-v*/ is never touched. + # FOLLOW-UP (K2GO-511): this prune is not yet pointer-aware, so it could delete a dated + # tarball a dev_latest_* staging pointer still names. Safe today (dev never reaches this + # branch, publish is manual); the pointer-protected two-lane prune is a separate step. + if [ "$MODE" = publish ]; then + for meta in latest_*_"${ARCH}".meta4; do + base="${meta%.meta4}"; te="${base#latest_}"; tier="${te%_${ARCH}}" + mapfile -t keys < <(aws s3api list-objects-v2 --bucket "$BUCKET_NAME" \ + --prefix "${PFX}k2go_" --endpoint-url "$ENDPOINT" \ + --query "sort_by(Contents,&LastModified)[?contains(Key,'_${tier}_') && ends_with(Key,'_${ARCH}.tar.gz')].Key" \ + --output text | tr '\t' '\n' | sed '/^$/d') + n=${#keys[@]} + if (( n > KEEP )); then + for key in "${keys[@]:0:n-KEEP}"; do + echo ">> prune $key (+ sidecars)" + for ext in '' .meta4 .sha256 .installed .torrent; do + aws s3 rm "s3://${BUCKET_NAME}/${key}${ext}" --endpoint-url "$ENDPOINT" || true + done done - done - fi - done + fi + done + fi From 4cacf4c72402c586ac6459b3c66310a06ae1a6d7 Mon Sep 17 00:00:00 2001 From: "Luis Guzman (AppDevForAll)" Date: Fri, 30 Oct 2026 03:31:34 -0600 Subject: [PATCH 2/3] K2GO-511 feat(rootfs): app installs dev_latest_* when the dev marker is set RootfsCatalog becomes the single builder of the rootfs pointer URL and routes to dev_latest_* when an enable-rootfs-dev marker exists in filesDir (user opt-in from the box terminal; the app never creates it), else the stable latest_*. InstallService drops its inline latest_* URL and calls the catalog. --- .../install/presentation/InstallService.java | 14 +++++-- .../k2go/rootfs/data/RootfsCatalog.java | 40 ++++++++++++++----- 2 files changed, 42 insertions(+), 12 deletions(-) diff --git a/controller/app/src/main/java/org/appdevforall/k2go/install/presentation/InstallService.java b/controller/app/src/main/java/org/appdevforall/k2go/install/presentation/InstallService.java index c31224b84..2d193ba76 100644 --- a/controller/app/src/main/java/org/appdevforall/k2go/install/presentation/InstallService.java +++ b/controller/app/src/main/java/org/appdevforall/k2go/install/presentation/InstallService.java @@ -491,9 +491,17 @@ private void startRootfsDownload() { // still intact and still bootable. work = org.appdevforall.k2go.install.domain.AbandonedInstall.Work.ROOTFS_BUILD; String archSuffix = (arch.contains("arm") && !arch.contains("64")) ? "armeabi-v7a" : "arm64-v8a"; - String tierString = tier.name().toLowerCase(Locale.US); - String directUrl = org.appdevforall.k2go.config.DownloadEndpoints.ROOTFS_STORE - + "/latest_" + tierString + "_" + archSuffix + ".meta4"; + // Unify the rootfs pointer URL through RootfsCatalog (single builder). The Context-aware + // catalog routes to the dev_latest_* staging channel when the enable-rootfs-dev marker is set + // in filesDir (K2GO-511), else the stable latest_*. + org.appdevforall.k2go.rootfs.domain.RootfsTier rTier = + (tier == null) ? org.appdevforall.k2go.rootfs.domain.RootfsTier.BASIC + : org.appdevforall.k2go.rootfs.domain.RootfsTier.valueOf(tier.name()); + org.appdevforall.k2go.rootfs.domain.RootfsAbi rAbi = + "armeabi-v7a".equals(archSuffix) + ? org.appdevforall.k2go.rootfs.domain.RootfsAbi.ARMEABI_V7A + : org.appdevforall.k2go.rootfs.domain.RootfsAbi.ARM64_V8A; + String directUrl = new org.appdevforall.k2go.rootfs.data.RootfsCatalog(this).metaUrl(rTier, rAbi); if (aria2Manager == null) aria2Manager = new Aria2Manager(); aria2Manager.startDownload(this, directUrl, new Aria2Manager.DownloadListener() { diff --git a/controller/app/src/main/java/org/appdevforall/k2go/rootfs/data/RootfsCatalog.java b/controller/app/src/main/java/org/appdevforall/k2go/rootfs/data/RootfsCatalog.java index 73be9e244..ca661e407 100644 --- a/controller/app/src/main/java/org/appdevforall/k2go/rootfs/data/RootfsCatalog.java +++ b/controller/app/src/main/java/org/appdevforall/k2go/rootfs/data/RootfsCatalog.java @@ -8,6 +8,7 @@ import org.appdevforall.k2go.rootfs.domain.RootfsTier; import java.io.BufferedReader; +import java.io.File; import java.io.InputStreamReader; import java.util.HashMap; import java.util.Locale; @@ -58,11 +59,18 @@ public class RootfsCatalog { /** Parsed CSV of UNCOMPRESSED sizes (optional 5th column, ADFA-5110). Absent => estimate. */ private static volatile Map csvInstalled; - /** No-arg: emergency-net only (no CSV). Kept for callers without a Context. */ - public RootfsCatalog() { } + /** Application context for the dev-channel marker check; null for the no-arg (prod-only) catalog. */ + private final Context appContext; - /** Context-aware: loads the packaged CSV so fallbackBytes() returns the last-known size. */ - public RootfsCatalog(Context context) { ensureCsvLoaded(context); } + /** No-arg: emergency-net only (no CSV) and the stable latest_* channel. Kept for callers without a Context. */ + public RootfsCatalog() { this.appContext = null; } + + /** Context-aware: loads the packaged CSV so fallbackBytes() returns the last-known size, and lets + * metaUrl()/installedUrl() route to the dev_latest_* staging channel when the marker is set. */ + public RootfsCatalog(Context context) { + this.appContext = (context != null) ? context.getApplicationContext() : null; + ensureCsvLoaded(context); + } private static void ensureCsvLoaded(Context context) { if (csvSizes != null || context == null) return; @@ -102,15 +110,29 @@ private static String key(String tier, String abi) { return tier.toLowerCase(Locale.US) + "|" + abi.toLowerCase(Locale.US); } - /** Builds the stable Metalink URL, e.g. {@code .../latest_basic_arm64-v8a.meta4}. */ + // K2GO-511: install from the dev_latest_* staging channel instead of the stable latest_* when the + // user drops an 'enable-rootfs-dev' marker in filesDir (HOME). The app NEVER creates it; it is a + // deliberate opt-in from the box terminal. No marker (or no Context) => the stable latest_*. + private static final String DEV_CHANNEL_MARKER = "enable-rootfs-dev"; + + private String pointerPrefix() { + if (appContext != null + && new File(appContext.getFilesDir(), DEV_CHANNEL_MARKER).exists()) { + return "dev_latest_"; + } + return "latest_"; + } + + /** Builds the Metalink URL, e.g. {@code .../latest_basic_arm64-v8a.meta4} (dev_latest_* when the + * dev-channel marker is set). */ public String metaUrl(RootfsTier tier, RootfsAbi abi) { - return BASE_URL + "latest_" + tier.name().toLowerCase(Locale.US) + "_" + abi.id() + ".meta4"; + return BASE_URL + pointerPrefix() + tier.name().toLowerCase(Locale.US) + "_" + abi.id() + ".meta4"; } - /** Stable sidecar URL for the UNCOMPRESSED size (ADFA-5110), - * e.g. {@code .../latest_full_arm64-v8a.installed} — a single integer, bytes. */ + /** Sidecar URL for the UNCOMPRESSED size (ADFA-5110), e.g. {@code .../latest_full_arm64-v8a.installed} + * (dev_latest_* when the dev-channel marker is set) — a single integer, bytes. */ public String installedUrl(RootfsTier tier, RootfsAbi abi) { - return BASE_URL + "latest_" + tier.name().toLowerCase(Locale.US) + "_" + abi.id() + ".installed"; + return BASE_URL + pointerPrefix() + tier.name().toLowerCase(Locale.US) + "_" + abi.id() + ".installed"; } /** From 9a761990f30e606fa9e45902dbda2237e41595fd Mon Sep 17 00:00:00 2001 From: "Luis Guzman (AppDevForAll)" Date: Fri, 30 Oct 2026 04:11:54 -0600 Subject: [PATCH 3/3] K2GO-511 style(rootfs): use ASCII colon in RootfsCatalog javadoc (no em-dash) --- .../java/org/appdevforall/k2go/rootfs/data/RootfsCatalog.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/controller/app/src/main/java/org/appdevforall/k2go/rootfs/data/RootfsCatalog.java b/controller/app/src/main/java/org/appdevforall/k2go/rootfs/data/RootfsCatalog.java index ca661e407..2f19519d0 100644 --- a/controller/app/src/main/java/org/appdevforall/k2go/rootfs/data/RootfsCatalog.java +++ b/controller/app/src/main/java/org/appdevforall/k2go/rootfs/data/RootfsCatalog.java @@ -130,7 +130,7 @@ public String metaUrl(RootfsTier tier, RootfsAbi abi) { } /** Sidecar URL for the UNCOMPRESSED size (ADFA-5110), e.g. {@code .../latest_full_arm64-v8a.installed} - * (dev_latest_* when the dev-channel marker is set) — a single integer, bytes. */ + * (dev_latest_* when the dev-channel marker is set) : a single integer, bytes. */ public String installedUrl(RootfsTier tier, RootfsAbi abi) { return BASE_URL + pointerPrefix() + tier.name().toLowerCase(Locale.US) + "_" + abi.id() + ".installed"; }