-
Notifications
You must be signed in to change notification settings - Fork 2
fix: add GCS migration and upload-release scripts #22
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
be7f6f7
fix: add migration script for flat-path firecracker binaries to amd64/
ValentaTomas f054bf1
move migrate-gcs-arch.sh to scripts/
ValentaTomas 031372a
simplify migration script: remove --delete-old
ValentaTomas cbea1a2
fix: don't hardcode firecrackers/ prefix, accept full GCS path
ValentaTomas 12bc1ef
skip versions that already have amd64/firecracker
ValentaTomas 0cd7a29
add upload-release-to-gcs.sh for uploading release assets to GCS
ValentaTomas File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,82 @@ | ||
| #!/bin/bash | ||
| # Copies flat-path firecracker binaries into amd64/ subdirectories in GCS. | ||
| # | ||
| # Before ARM64 support was added, builds were uploaded as: | ||
| # {version_name}/firecracker | ||
| # | ||
| # The arch-aware layout expects: | ||
| # {version_name}/amd64/firecracker | ||
| # | ||
| # This script finds flat-path binaries and copies them into the amd64/ subdir | ||
| # so the orchestrator's arch-based path resolution can find them. | ||
| # | ||
| # Usage: | ||
| # ./scripts/migrate-gcs-arch.sh <bucket-or-path> # dry-run: show what would be copied | ||
| # ./scripts/migrate-gcs-arch.sh <bucket-or-path> --apply # copy flat -> amd64/ | ||
| # | ||
| # Examples: | ||
| # ./scripts/migrate-gcs-arch.sh gs://e2b-staging-fc-versions | ||
| # ./scripts/migrate-gcs-arch.sh gs://e2b-prod-public-builds/firecrackers --apply | ||
|
|
||
| set -euo pipefail | ||
|
|
||
| GCS_PATH="${1:?Usage: $0 <bucket-or-path> [--apply]}" | ||
| shift | ||
|
|
||
| APPLY=false | ||
| for arg in "$@"; do | ||
| case "$arg" in | ||
| --apply) APPLY=true ;; | ||
| *) echo "Unknown flag: $arg"; exit 1 ;; | ||
| esac | ||
| done | ||
|
|
||
| # Normalize: strip trailing slash | ||
| GCS_PATH="${GCS_PATH%/}" | ||
|
|
||
| echo "Scanning ${GCS_PATH} for flat-path firecracker binaries..." | ||
| echo "" | ||
|
|
||
| # Match only flat-path binaries: {version}/firecracker | ||
| # The single * does NOT match path separators, so this excludes | ||
| # {version}/{arch}/firecracker. | ||
| objects=$(gsutil ls "${GCS_PATH}/*/firecracker" 2>/dev/null || true) | ||
|
|
||
| if [[ -z "$objects" ]]; then | ||
| echo "No flat-path firecracker binaries found in ${GCS_PATH}" | ||
| exit 0 | ||
| fi | ||
|
|
||
| copied=0 | ||
| skipped=0 | ||
| while IFS= read -r src; do | ||
| [[ -z "$src" ]] && continue | ||
|
|
||
| # Insert /amd64 before the filename: | ||
| # .../v1.10.1/firecracker -> .../v1.10.1/amd64/firecracker | ||
| dst="${src%/firecracker}/amd64/firecracker" | ||
|
|
||
| # Skip if destination already exists | ||
| if gsutil -q stat "$dst" 2>/dev/null; then | ||
| echo " SKIP $dst (already exists)" | ||
| ((skipped++)) || true | ||
| continue | ||
| fi | ||
|
|
||
| if [[ "$APPLY" == true ]]; then | ||
| echo " COPY $src" | ||
| echo " -> $dst" | ||
| gsutil cp "$src" "$dst" | ||
| else | ||
| echo " [dry-run] $src" | ||
| echo " -> $dst" | ||
| fi | ||
| ((copied++)) || true | ||
| done <<< "$objects" | ||
|
|
||
| echo "" | ||
| echo "Total: $copied to copy, $skipped skipped (already exist)" | ||
| if [[ "$APPLY" != true && "$copied" -gt 0 ]]; then | ||
| echo "" | ||
| echo "This was a dry run. Add --apply to actually copy." | ||
| fi |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,112 @@ | ||
| #!/usr/bin/env bash | ||
| # Uploads firecracker-{amd64,arm64} assets from a fc-versions GitHub release | ||
| # to GCS at: | ||
| # <bucket>/<version_name>/<arch>/firecracker | ||
| # <bucket>/<version_name>/firecracker (legacy amd64 copy) | ||
| # | ||
| # Existing objects are never overwritten. | ||
| # | ||
| # Usage: | ||
| # ./scripts/upload-release-to-gcs.sh --tag <tag> --bucket <bucket> [--dry-run] [--repo <repo>] | ||
| # | ||
| # Options: | ||
| # --tag <tag> Release tag / version name (e.g. v1.14.1_af9c995). | ||
| # --bucket <bucket> Target bucket (with optional path prefix), e.g. | ||
| # my-bucket | ||
| # my-bucket/firecrackers | ||
| # gs://my-bucket/firecrackers | ||
| # --repo <repo> GitHub repo (default: e2b-dev/fc-versions). | ||
| # --dry-run Print what would be uploaded without writing. | ||
| # -h, --help Show this help. | ||
|
|
||
| set -euo pipefail | ||
|
|
||
| REPO="e2b-dev/fc-versions" | ||
| TAG="" | ||
| BUCKET="" | ||
| DRY_RUN=false | ||
|
|
||
| usage() { sed -n '2,/^$/p' "$0" | sed 's/^# \{0,1\}//'; exit "${1:-0}"; } | ||
|
|
||
| while [[ $# -gt 0 ]]; do | ||
| case "$1" in | ||
| --tag) TAG="${2:?--tag needs a value}"; shift 2 ;; | ||
| --bucket) BUCKET="${2:?--bucket needs a value}"; shift 2 ;; | ||
| --repo) REPO="${2:?--repo needs a value}"; shift 2 ;; | ||
| --dry-run) DRY_RUN=true; shift ;; | ||
| -h|--help) usage 0 ;; | ||
| *) echo "Unknown argument: $1" >&2; usage 1 ;; | ||
| esac | ||
| done | ||
|
|
||
| [[ -n "$TAG" ]] || { echo "ERROR: --tag is required" >&2; usage 1; } | ||
| [[ -n "$BUCKET" ]] || { echo "ERROR: --bucket is required" >&2; usage 1; } | ||
|
|
||
| command -v gh >/dev/null || { echo "ERROR: gh CLI not found" >&2; exit 1; } | ||
| command -v gcloud >/dev/null || { echo "ERROR: gcloud CLI not found" >&2; exit 1; } | ||
|
|
||
| BUCKET="${BUCKET#gs://}" | ||
| BUCKET="${BUCKET%/}" | ||
| BUCKET_URI="gs://${BUCKET}" | ||
|
|
||
| if ! gh release view "$TAG" --repo "$REPO" >/dev/null 2>&1; then | ||
| echo "ERROR: release '$TAG' not found in $REPO" >&2 | ||
| exit 1 | ||
| fi | ||
|
|
||
| echo "Release: $TAG" | ||
| echo "Target: ${BUCKET_URI}" | ||
| $DRY_RUN && echo "Mode: dry-run" | ||
|
|
||
| ASSETS=() | ||
| while IFS= read -r line || [[ -n "$line" ]]; do | ||
| [[ -n "$line" ]] && ASSETS+=("$line") | ||
| done < <(gh release view "$TAG" --repo "$REPO" --json assets \ | ||
| --jq '.assets[].name') | ||
|
|
||
| if [[ "${#ASSETS[@]}" -eq 0 ]]; then | ||
| echo "ERROR: release $TAG has no assets" >&2 | ||
| exit 1 | ||
| fi | ||
|
|
||
| TMP_DIR=$(mktemp -d) | ||
| trap 'rm -rf "$TMP_DIR"' EXIT | ||
|
|
||
| uploaded=0 | ||
| skipped=0 | ||
| for asset in "${ASSETS[@]}"; do | ||
| if [[ "$asset" =~ ^firecracker-(amd64|arm64)$ ]]; then | ||
| arch="${BASH_REMATCH[1]}" | ||
| dst="${BUCKET_URI}/${TAG}/${arch}/firecracker" | ||
| elif [[ "$asset" == "firecracker" ]]; then | ||
| dst="${BUCKET_URI}/${TAG}/firecracker" | ||
| else | ||
| continue | ||
| fi | ||
|
|
||
| if gcloud storage ls "$dst" >/dev/null 2>&1; then | ||
| echo " EXISTS $dst" | ||
| skipped=$((skipped + 1)) | ||
| continue | ||
| fi | ||
|
|
||
| if $DRY_RUN; then | ||
| echo " WOULD $asset -> $dst" | ||
| uploaded=$((uploaded + 1)) | ||
| continue | ||
| fi | ||
|
|
||
| echo " UPLOAD $asset -> $dst" | ||
| gh release download "$TAG" --repo "$REPO" \ | ||
| --pattern "$asset" --dir "$TMP_DIR" --clobber >/dev/null | ||
| gcloud storage cp "$TMP_DIR/$asset" "$dst" | ||
| rm -f "$TMP_DIR/$asset" | ||
| uploaded=$((uploaded + 1)) | ||
| done | ||
|
|
||
| echo "" | ||
| if $DRY_RUN; then | ||
| echo "Dry run complete. Would upload: $uploaded, already in GCS: $skipped." | ||
| else | ||
| echo "Done. Uploaded: $uploaded, already in GCS: $skipped." | ||
| fi | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Upload script missing legacy flat-path copy for amd64
High Severity
The script's header comment documents that it uploads to both
<bucket>/<version_name>/<arch>/firecrackerand<bucket>/<version_name>/firecracker(legacy amd64 copy). However, when handling afirecracker-amd64asset, the code only uploads to the arch-specific path and never creates the legacy flat-path copy.build.shexplicitly creates both paths for amd64 with a comment noting "so existing production nodes that expect the old layout keep working." New releases lacking a barefirecrackerasset will have no legacy path, breaking backward compatibility.Additional Locations (1)
scripts/upload-release-to-gcs.sh#L3-L5Reviewed by Cursor Bugbot for commit 0cd7a29. Configure here.