Skip to content

Commit 5da78a6

Browse files
committed
Refactor
1 parent 052ef1a commit 5da78a6

File tree

4 files changed

+153
-79
lines changed

4 files changed

+153
-79
lines changed

.github/workflows/build.yml

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
name: Build Firecracker Versions
2+
3+
on:
4+
workflow_call:
5+
outputs:
6+
versions:
7+
description: "JSON array of versions that were built"
8+
value: ${{ jobs.prepare.outputs.versions }}
9+
workflow_dispatch:
10+
11+
jobs:
12+
prepare:
13+
runs-on: ubuntu-latest
14+
outputs:
15+
versions: ${{ steps.set-versions.outputs.versions }}
16+
steps:
17+
- uses: actions/checkout@v4
18+
19+
- name: Parse versions from file
20+
id: set-versions
21+
run: |
22+
# Read versions, skip comments and empty lines, output as JSON array
23+
versions=$(grep -v '^ *#' firecracker_versions.txt | grep -v '^$' | jq -R -s -c 'split("\n") | map(select(length > 0))')
24+
echo "versions=$versions" >> $GITHUB_OUTPUT
25+
echo "Building versions: $versions"
26+
27+
build:
28+
needs: prepare
29+
runs-on: ubuntu-latest
30+
strategy:
31+
fail-fast: true
32+
matrix:
33+
version: ${{ fromJson(needs.prepare.outputs.versions) }}
34+
steps:
35+
- uses: actions/checkout@v4
36+
37+
- name: Build Firecracker ${{ matrix.version }}
38+
run: ./build.sh "${{ matrix.version }}"
39+
40+
- name: Upload build artifact
41+
uses: actions/upload-artifact@v4
42+
with:
43+
name: firecracker-${{ matrix.version }}
44+
path: builds/
45+
retention-days: 7

.github/workflows/fc-versions.yml

Lines changed: 52 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -2,68 +2,49 @@ name: FC Versions
22

33
on:
44
push:
5+
workflow_dispatch:
6+
7+
concurrency:
8+
group: ${{ github.workflow }}-${{ github.head_ref || github.ref }}
9+
cancel-in-progress: true
510

611
permissions:
712
id-token: write
813
contents: write
914

1015
jobs:
16+
# Run parallel builds via reusable workflow
17+
build:
18+
uses: ./.github/workflows/build.yml
19+
1120
publish:
12-
name: Build Firecracker and upload
21+
name: Collect and upload builds
22+
needs: build
1323
runs-on: ubuntu-22.04
1424
steps:
1525
- name: Checkout repository
1626
uses: actions/checkout@v4
17-
18-
- uses: actions/create-github-app-token@v1
19-
id: app-token
2027
with:
21-
app-id: ${{ vars.VERSION_BUMPER_APPID }}
22-
private-key: ${{ secrets.VERSION_BUMPER_SECRET }}
28+
fetch-depth: 0
2329

24-
- name: Get the last release
25-
id: last_release
26-
continue-on-error: true
27-
uses: cardinalby/git-get-release-action@v1
28-
env:
29-
GITHUB_TOKEN: ${{ github.token }}
30+
# Download all build artifacts
31+
- name: Download all build artifacts
32+
uses: actions/download-artifact@v4
3033
with:
31-
latest: true
32-
prerelease: false
33-
draft: false
34+
path: builds
35+
pattern: firecracker-*
36+
merge-multiple: true
3437

35-
- name: Get next version
36-
id: get-version
37-
run: |
38-
if [ "${{ steps.last_release.outputs.tag_name }}" == "" ]; then
39-
echo "No previous release found, starting with v0.0.1"
40-
echo "version=v0.0.1" >> $GITHUB_OUTPUT
41-
else
42-
version=${{ steps.last_release.outputs.tag_name }}
43-
result=$(echo ${version} | awk -F. -v OFS=. '{$NF += 1 ; print}')
44-
echo "version=$result" >> $GITHUB_OUTPUT
45-
fi
46-
47-
- name: Test next version
48-
run: echo "Next version is ${{ steps.get-version.outputs.version }}"
38+
- name: List downloaded builds
39+
run: find builds -type f | head -20
4940

5041
- name: Setup Service Account
42+
if: github.ref_name == 'main'
5143
uses: google-github-actions/auth@v2
5244
with:
5345
project_id: ${{ secrets.GCP_PROJECT_ID }}
5446
workload_identity_provider: ${{ secrets.GCP_WORKLOAD_IDENTITY_PROVIDER }}
5547

56-
- name: Build firecrackers
57-
run: sudo make build
58-
59-
- name: Upload firecrackers as artifact
60-
if: github.ref_name != 'main'
61-
uses: actions/upload-artifact@v4
62-
with:
63-
name: firecracker-${{ github.run_id }}
64-
path: ./builds
65-
retention-days: 7
66-
6748
- name: Upload firecrackers to GCS
6849
if: github.ref_name == 'main'
6950
uses: "google-github-actions/upload-cloud-storage@v1"
@@ -73,34 +54,41 @@ jobs:
7354
gzip: false
7455
parent: false
7556

76-
- name: Create Git tag
57+
- name: Create releases for each Firecracker version
7758
if: github.ref_name == 'main'
59+
env:
60+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
7861
run: |
7962
git config user.name "github-actions"
8063
git config user.email "[email protected]"
81-
git tag ${{ steps.get-version.outputs.version }}
82-
git push origin ${{ steps.get-version.outputs.version }}
83-
env:
84-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
85-
8664
87-
- name: Prepare release assets
88-
if: github.ref_name == 'main'
89-
run: |
90-
mkdir -p release-assets
9165
for dir in ./builds/*/; do
92-
name=$(basename "$dir")
93-
cp "$dir/vmlinux.bin" "release-assets/${name}.bin"
94-
done
95-
env:
96-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
66+
version_name=$(basename "$dir")
67+
binary_path="$dir/firecracker"
9768
98-
- name: Upload Release Asset
99-
if: github.ref_name == 'main'
100-
uses: softprops/action-gh-release@v2
101-
env:
102-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
103-
with:
104-
name: Firecrackers ${{ steps.get-version.outputs.version }}
105-
tag_name: ${{ steps.get-version.outputs.version }}
106-
files: "./release-assets/*"
69+
echo "Processing $version_name..."
70+
71+
# Check if tag already exists
72+
if git rev-parse "refs/tags/$version_name" >/dev/null 2>&1; then
73+
echo "Tag $version_name already exists, skipping..."
74+
continue
75+
fi
76+
77+
# Check if release already exists
78+
if gh release view "$version_name" >/dev/null 2>&1; then
79+
echo "Release $version_name already exists, skipping..."
80+
continue
81+
fi
82+
83+
echo "Creating tag and release for $version_name..."
84+
85+
# Create and push tag
86+
git tag "$version_name"
87+
git push origin "$version_name"
88+
89+
# Create release with the binary
90+
gh release create "$version_name" \
91+
--title "Firecracker $version_name" \
92+
--notes "Firecracker build: $version_name" \
93+
"$binary_path#${version_name}"
94+
done

README.md

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# fc-kernels
1+
# fc-versions
22

33
## Overview
44

@@ -8,22 +8,25 @@ This project automates the building of custom Firecracker. It supports building
88

99
- Linux environment (for building firecracker)
1010

11-
## Building Kernels
11+
## Building Firecrackers
1212

1313
1. **Configure firecracker versions:**
14-
- Edit `firecracker_versions.txt` to specify which kernel versions to build (one per line, e.g., `<last_tag-prelease>-<first-8-letters-of-the-specific-commit>`).
14+
- Edit `firecracker_versions.txt` to specify which firecracker versions to build (one per line, e.g., `<last_tag-prelease>-<first-8-letters-of-the-specific-commit>`).
1515

1616
2. **Build:**
17+
1718
```sh
1819
make build
1920
# or directly
2021
./build.sh
2122
```
22-
The built kernels will be placed in `builds/vmlinux-<version>/vmlinux.bin`.
23+
24+
The built firecrackers will be placed in `builds/firecracker-<version>/firecracker`.
2325

2426
## Development Workflow
25-
- On every push, GitHub Actions will automatically build the kernels and save it as an artifact.
27+
28+
- On every push, GitHub Actions will automatically build the firecrackers and save it as an artifact.
2629

2730
## License
2831

29-
This project is licensed under the Apache License 2.0. See [LICENSE](LICENSE) for details.
32+
This project is licensed under the Apache License 2.0. See [LICENSE](LICENSE) for details.

build.sh

Lines changed: 47 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,32 +2,70 @@
22

33
set -euo pipefail
44

5+
FIRECRACKER_REPO_URL="https://github.com/e2b-dev/firecracker.git"
6+
57
function build_version {
68
local version=$1
7-
echo "Starting build for Firecracker commit: $version"
89

9-
echo "Checking out repo for Firecracker at commit: $version"
10-
git checkout "${version}"
10+
# Detect if the version is of the form tag_shorthash (e.g., v1.12.1_abcdef12)
11+
if [[ "$version" =~ ^([^_]+)_([0-9a-fA-F]+)$ ]]; then
12+
local tag="${BASH_REMATCH[1]}"
13+
local shorthash="${BASH_REMATCH[2]}"
14+
echo "Starting build for Firecracker tag: $tag and shorthash: $shorthash"
15+
16+
echo "Checking out repo at tag: $tag"
17+
git checkout "$tag"
18+
19+
# Find full hash from shorthash
20+
fullhash=$(git rev-parse --verify "$shorthash^{commit}" 2>/dev/null || true)
21+
if [[ -z "$fullhash" ]]; then
22+
echo "Error: Could not resolve hash $shorthash"
23+
exit 1
24+
fi
25+
26+
# Ensure that $fullhash is a descendant of $tag
27+
if git merge-base --is-ancestor "$tag" "$fullhash"; then
28+
echo "Shorthash $shorthash is AFTER tag $tag -- proceeding"
29+
git checkout "$fullhash"
30+
else
31+
echo "Error: shorthash $shorthash is not a descendant of tag $tag"
32+
exit 1
33+
fi
34+
version_name="${tag}_$shorthash"
35+
else
36+
echo "Starting build for Firecracker at commit: $version"
37+
echo "Checking out repo for Firecracker at commit: $version"
38+
git checkout "${version}"
39+
# The format will be: latest_tag_latest_commit_hash — v1.7.0-dev_g8bb88311
40+
version_name=$(git describe --tags --abbrev=0 "$(git rev-parse HEAD)")_$(git rev-parse --short HEAD)
41+
fi
1142

12-
# The format will be: latest_tag_latest_commit_hash — v1.7.0-dev_g8bb88311
13-
version_name=$(git describe --tags --abbrev=0 $(git rev-parse HEAD))_$(git rev-parse --short HEAD)
1443
echo "Version name: $version_name"
1544

1645
echo "Building Firecracker version: $version_name"
17-
tools/devtool -y build --release
46+
# Build only the firecracker binary, skip jailer and snapshot-editor for faster builds
47+
tools/devtool -y build --release -- --bin firecracker
1848

1949
echo "Copying finished build to builds directory"
2050
mkdir -p "../builds/${version_name}"
2151
cp build/cargo_target/x86_64-unknown-linux-musl/release/firecracker "../builds/${version_name}/firecracker"
2252
}
2353

54+
# If a version is passed as argument, build only that version
55+
# Otherwise, build all versions from firecracker_versions.txt
56+
if [[ $# -ge 1 ]]; then
57+
versions=("$@")
58+
else
59+
mapfile -t versions < <(grep -v '^ *#' firecracker_versions.txt | grep -v '^$')
60+
fi
61+
2462
echo "Cloning the Firecracker repository"
25-
git clone https://github.com/firecracker-microvm/firecracker.git firecracker
63+
git clone $FIRECRACKER_REPO_URL firecracker
2664
cd firecracker
2765

28-
grep -v '^ *#' <../firecracker_versions.txt | while IFS= read -r version; do
66+
for version in "${versions[@]}"; do
2967
build_version "$version"
3068
done
3169

3270
cd ..
33-
rm -rf firecracker
71+
rm -rf firecracker

0 commit comments

Comments
 (0)