Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
115 changes: 67 additions & 48 deletions .github/workflows/bake-rootfs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 \
Expand All @@ -152,66 +155,82 @@ 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
echo ">> upload artifact $f"
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-<tier>-<arch>.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-<tier>-<arch>.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 <date>_<sha>); 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
# <date>_<sha>); 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
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -58,11 +59,18 @@ public class RootfsCatalog {
/** Parsed CSV of UNCOMPRESSED sizes (optional 5th column, ADFA-5110). Absent => estimate. */
private static volatile Map<String, Long> 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;
Expand Down Expand Up @@ -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";
}

/**
Expand Down
Loading