From d46aa878af3dba33bbb5802c7edb3f4249589475 Mon Sep 17 00:00:00 2001 From: Alex Zenla Date: Thu, 16 May 2024 01:40:58 -0700 Subject: [PATCH] feat(build): fetch kernels from image registry instead of building the kernel (#156) Now that we have the kernel build infrastructure at https://github.com/edera-dev/kernels it makes sense to drop building the kernel and download the kernel images directly. This change introduces a ./hack/kernel/fetch.sh script which is backed by crates/build We utilize the OCI infrastructure itself to download the kernel image. The DEV guide has been updated to include calling the fetch script, and the OS builder now uses this method instead. Due to the lack of need for the kernel build infra to exist here now, it has also been removed. This should significantly speed up full builds. This change will also enable us to turn on os build workflows for all PRs. We should likely make the OS status checks required once this is merged. --- .github/workflows/check.yml | 6 +- .github/workflows/client.yml | 3 +- .github/workflows/kernel.yml | 36 -------- .github/workflows/nightly.yml | 8 +- .github/workflows/os.yml | 9 +- .github/workflows/release-binaries.yml | 14 +-- .github/workflows/release-plz.yml | 41 +++++---- .github/workflows/server.yml | 13 +-- Cargo.lock | 15 ++++ Cargo.toml | 1 + DEV.md | 4 +- crates/build/Cargo.toml | 25 ++++++ crates/build/bin/fetch_kernel.rs | 120 +++++++++++++++++++++++++ hack/dist/bundle.sh | 5 +- hack/kernel/build.sh | 36 -------- hack/kernel/common.sh | 75 ---------------- hack/kernel/config.sh | 16 ---- hack/kernel/fetch.sh | 17 ++++ 18 files changed, 213 insertions(+), 231 deletions(-) delete mode 100644 .github/workflows/kernel.yml create mode 100644 crates/build/Cargo.toml create mode 100644 crates/build/bin/fetch_kernel.rs delete mode 100755 hack/kernel/build.sh delete mode 100644 hack/kernel/common.sh delete mode 100755 hack/kernel/config.sh create mode 100755 hack/kernel/fetch.sh diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml index 3572a90..4292cbf 100644 --- a/.github/workflows/check.yml +++ b/.github/workflows/check.yml @@ -11,8 +11,7 @@ jobs: name: fmt runs-on: ubuntu-latest steps: - - name: Harden Runner - uses: step-security/harden-runner@a4aa98b93cab29d9b1101a6143fb8bce00e2eac4 # v2.7.1 + - uses: step-security/harden-runner@a4aa98b93cab29d9b1101a6143fb8bce00e2eac4 # v2.7.1 with: egress-policy: audit - uses: actions/checkout@44c2b7a8a4ea60a981eaca3cf939b5f4305c123b # v4.1.5 @@ -27,8 +26,7 @@ jobs: name: shellcheck runs-on: ubuntu-latest steps: - - name: Harden Runner - uses: step-security/harden-runner@a4aa98b93cab29d9b1101a6143fb8bce00e2eac4 # v2.7.1 + - uses: step-security/harden-runner@a4aa98b93cab29d9b1101a6143fb8bce00e2eac4 # v2.7.1 with: egress-policy: audit - uses: actions/checkout@44c2b7a8a4ea60a981eaca3cf939b5f4305c123b # v4.1.5 diff --git a/.github/workflows/client.yml b/.github/workflows/client.yml index 6dcee99..3022abf 100644 --- a/.github/workflows/client.yml +++ b/.github/workflows/client.yml @@ -27,8 +27,7 @@ jobs: run: shell: bash steps: - - name: Harden Runner - uses: step-security/harden-runner@a4aa98b93cab29d9b1101a6143fb8bce00e2eac4 # v2.7.1 + - uses: step-security/harden-runner@a4aa98b93cab29d9b1101a6143fb8bce00e2eac4 # v2.7.1 with: egress-policy: audit - run: git config --global core.autocrlf false && git config --global core.eol lf diff --git a/.github/workflows/kernel.yml b/.github/workflows/kernel.yml deleted file mode 100644 index 91ce1cd..0000000 --- a/.github/workflows/kernel.yml +++ /dev/null @@ -1,36 +0,0 @@ -name: kernel -on: - pull_request: - branches: - - main - paths: - - "kernel/**" - - "hack/ci/**" - merge_group: - branches: - - main -jobs: - build: - runs-on: ubuntu-latest - strategy: - fail-fast: false - matrix: - arch: - - x86_64 - - aarch64 - env: - TARGET_ARCH: "${{ matrix.arch }}" - name: kernel build ${{ matrix.arch }} - steps: - - name: Harden Runner - uses: step-security/harden-runner@a4aa98b93cab29d9b1101a6143fb8bce00e2eac4 # v2.7.1 - with: - egress-policy: audit - - uses: actions/checkout@44c2b7a8a4ea60a981eaca3cf939b5f4305c123b # v4.1.5 - with: - submodules: recursive - - uses: dtolnay/rust-toolchain@d388a4836fcdbde0e50e395dc79a2670ccdef13f # stable - - run: ./hack/ci/install-linux-deps.sh - - run: ./hack/kernel/build.sh - env: - KRATA_KERNEL_BUILD_JOBS: "5" diff --git a/.github/workflows/nightly.yml b/.github/workflows/nightly.yml index 8d8be9f..29a83da 100644 --- a/.github/workflows/nightly.yml +++ b/.github/workflows/nightly.yml @@ -16,11 +16,9 @@ jobs: TARGET_ARCH: "${{ matrix.arch }}" name: nightly server ${{ matrix.arch }} steps: - - name: Harden Runner - uses: step-security/harden-runner@a4aa98b93cab29d9b1101a6143fb8bce00e2eac4 # v2.7.1 + - uses: step-security/harden-runner@a4aa98b93cab29d9b1101a6143fb8bce00e2eac4 # v2.7.1 with: egress-policy: audit - - uses: actions/checkout@44c2b7a8a4ea60a981eaca3cf939b5f4305c123b # v4.1.5 with: submodules: recursive @@ -80,11 +78,9 @@ jobs: run: shell: bash steps: - - name: Harden Runner - uses: step-security/harden-runner@a4aa98b93cab29d9b1101a6143fb8bce00e2eac4 # v2.7.1 + - uses: step-security/harden-runner@a4aa98b93cab29d9b1101a6143fb8bce00e2eac4 # v2.7.1 with: egress-policy: audit - - run: git config --global core.autocrlf false && git config --global core.eol lf if: ${{ matrix.platform.os == 'windows' }} - uses: actions/checkout@44c2b7a8a4ea60a981eaca3cf939b5f4305c123b # v4.1.5 diff --git a/.github/workflows/os.yml b/.github/workflows/os.yml index 2ba176a..bce18cf 100644 --- a/.github/workflows/os.yml +++ b/.github/workflows/os.yml @@ -3,10 +3,6 @@ on: pull_request: branches: - main - paths: - - "os/**" - - "hack/os/**" - - "hack/ci/**" merge_group: branches: - main @@ -23,8 +19,7 @@ jobs: TARGET_ARCH: "${{ matrix.arch }}" name: os build ${{ matrix.arch }} steps: - - name: Harden Runner - uses: step-security/harden-runner@a4aa98b93cab29d9b1101a6143fb8bce00e2eac4 # v2.7.1 + - uses: step-security/harden-runner@a4aa98b93cab29d9b1101a6143fb8bce00e2eac4 # v2.7.1 with: egress-policy: audit - uses: actions/checkout@44c2b7a8a4ea60a981eaca3cf939b5f4305c123b # v4.1.5 @@ -35,8 +30,6 @@ jobs: targets: "${{ matrix.arch }}-unknown-linux-gnu,${{ matrix.arch }}-unknown-linux-musl" - run: ./hack/ci/install-linux-deps.sh - run: ./hack/os/build.sh - env: - KRATA_KERNEL_BUILD_JOBS: "5" - uses: actions/upload-artifact@65462800fd760344b1a7b4382951275a0abb4808 # v4.3.3 with: name: krata-os-${{ matrix.arch }} diff --git a/.github/workflows/release-binaries.yml b/.github/workflows/release-binaries.yml index 4a6ce5a..032ad96 100644 --- a/.github/workflows/release-binaries.yml +++ b/.github/workflows/release-binaries.yml @@ -25,8 +25,7 @@ jobs: TARGET_ARCH: "${{ matrix.arch }}" name: release-binaries server ${{ matrix.arch }} steps: - - name: Harden Runner - uses: step-security/harden-runner@a4aa98b93cab29d9b1101a6143fb8bce00e2eac4 # v2.7.1 + - uses: step-security/harden-runner@a4aa98b93cab29d9b1101a6143fb8bce00e2eac4 # v2.7.1 with: egress-policy: audit - uses: actions/checkout@44c2b7a8a4ea60a981eaca3cf939b5f4305c123b # v4.1.5 @@ -37,20 +36,12 @@ jobs: targets: "${{ matrix.arch }}-unknown-linux-gnu,${{ matrix.arch }}-unknown-linux-musl" - run: ./hack/ci/install-linux-deps.sh - run: ./hack/dist/bundle.sh - env: - KRATA_KERNEL_BUILD_JOBS: "5" - run: "./hack/ci/assemble-release-assets.sh bundle-systemd ${{ github.event.release.tag_name }} ${{ matrix.arch }} target/dist/bundle-systemd-${{ matrix.arch }}.tgz" - run: ./hack/dist/deb.sh - env: - KRATA_KERNEL_BUILD_SKIP: "1" - run: "./hack/ci/assemble-release-assets.sh debian ${{ github.event.release.tag_name }} ${{ matrix.arch }} target/dist/*.deb" - run: ./hack/dist/apk.sh - env: - KRATA_KERNEL_BUILD_SKIP: "1" - run: "./hack/ci/assemble-release-assets.sh alpine ${{ github.event.release.tag_name }} ${{ matrix.arch }} target/dist/*_${{ matrix.arch }}.apk" - run: ./hack/os/build.sh - env: - KRATA_KERNEL_BUILD_SKIP: "1" - run: "./hack/ci/assemble-release-assets.sh os ${{ github.event.release.tag_name }} ${{ matrix.arch }} target/os/krata-${{ matrix.arch }}.qcow2" - run: "./hack/ci/upload-release-assets.sh ${{ github.event.release.tag_name }}" env: @@ -76,8 +67,7 @@ jobs: shell: bash timeout-minutes: 60 steps: - - name: Harden Runner - uses: step-security/harden-runner@a4aa98b93cab29d9b1101a6143fb8bce00e2eac4 # v2.7.1 + - uses: step-security/harden-runner@a4aa98b93cab29d9b1101a6143fb8bce00e2eac4 # v2.7.1 with: egress-policy: audit - uses: actions/checkout@44c2b7a8a4ea60a981eaca3cf939b5f4305c123b # v4.1.5 diff --git a/.github/workflows/release-plz.yml b/.github/workflows/release-plz.yml index 888c827..0fddaca 100644 --- a/.github/workflows/release-plz.yml +++ b/.github/workflows/release-plz.yml @@ -14,24 +14,23 @@ jobs: name: release-plz runs-on: ubuntu-latest steps: - - name: Harden Runner - uses: step-security/harden-runner@a4aa98b93cab29d9b1101a6143fb8bce00e2eac4 # v2.7.1 - with: - egress-policy: audit - - uses: actions/create-github-app-token@a0de6af83968303c8c955486bf9739a57d23c7f1 # v1.10.0 - id: generate-token - with: - app-id: "${{ secrets.EDERA_CULTIVATION_APP_ID }}" - private-key: "${{ secrets.EDERA_CULTIVATION_APP_PRIVATE_KEY }}" - - uses: actions/checkout@44c2b7a8a4ea60a981eaca3cf939b5f4305c123b # v4.1.5 - with: - submodules: recursive - fetch-depth: 0 - token: "${{ steps.generate-token.outputs.token }}" - - uses: dtolnay/rust-toolchain@d388a4836fcdbde0e50e395dc79a2670ccdef13f # stable - - run: ./hack/ci/install-linux-deps.sh - - name: release-plz - uses: MarcoIeni/release-plz-action@a2904442184b59b09f10f6c7197cfa8e48bd2fc4 # v0.5.57 - env: - GITHUB_TOKEN: "${{ steps.generate-token.outputs.token }}" - CARGO_REGISTRY_TOKEN: "${{ secrets.KRATA_RELEASE_CARGO_TOKEN }}" + - uses: step-security/harden-runner@a4aa98b93cab29d9b1101a6143fb8bce00e2eac4 # v2.7.1 + with: + egress-policy: audit + - uses: actions/create-github-app-token@a0de6af83968303c8c955486bf9739a57d23c7f1 # v1.10.0 + id: generate-token + with: + app-id: "${{ secrets.EDERA_CULTIVATION_APP_ID }}" + private-key: "${{ secrets.EDERA_CULTIVATION_APP_PRIVATE_KEY }}" + - uses: actions/checkout@44c2b7a8a4ea60a981eaca3cf939b5f4305c123b # v4.1.5 + with: + submodules: recursive + fetch-depth: 0 + token: "${{ steps.generate-token.outputs.token }}" + - uses: dtolnay/rust-toolchain@d388a4836fcdbde0e50e395dc79a2670ccdef13f # stable + - run: ./hack/ci/install-linux-deps.sh + - name: release-plz + uses: MarcoIeni/release-plz-action@a2904442184b59b09f10f6c7197cfa8e48bd2fc4 # v0.5.57 + env: + GITHUB_TOKEN: "${{ steps.generate-token.outputs.token }}" + CARGO_REGISTRY_TOKEN: "${{ secrets.KRATA_RELEASE_CARGO_TOKEN }}" diff --git a/.github/workflows/server.yml b/.github/workflows/server.yml index cf6319f..9883d64 100644 --- a/.github/workflows/server.yml +++ b/.github/workflows/server.yml @@ -19,8 +19,7 @@ jobs: TARGET_ARCH: "${{ matrix.arch }}" name: server build ${{ matrix.arch }} steps: - - name: Harden Runner - uses: step-security/harden-runner@a4aa98b93cab29d9b1101a6143fb8bce00e2eac4 # v2.7.1 + - uses: step-security/harden-runner@a4aa98b93cab29d9b1101a6143fb8bce00e2eac4 # v2.7.1 with: egress-policy: audit - uses: actions/checkout@44c2b7a8a4ea60a981eaca3cf939b5f4305c123b # v4.1.5 @@ -40,11 +39,9 @@ jobs: TARGET_ARCH: "${{ matrix.arch }}" name: server test ${{ matrix.arch }} steps: - - name: Harden Runner - uses: step-security/harden-runner@a4aa98b93cab29d9b1101a6143fb8bce00e2eac4 # v2.7.1 + - uses: step-security/harden-runner@a4aa98b93cab29d9b1101a6143fb8bce00e2eac4 # v2.7.1 with: egress-policy: audit - - uses: actions/checkout@44c2b7a8a4ea60a981eaca3cf939b5f4305c123b # v4.1.5 with: submodules: recursive @@ -62,8 +59,7 @@ jobs: TARGET_ARCH: "${{ matrix.arch }}" name: server clippy ${{ matrix.arch }} steps: - - name: Harden Runner - uses: step-security/harden-runner@a4aa98b93cab29d9b1101a6143fb8bce00e2eac4 # v2.7.1 + - uses: step-security/harden-runner@a4aa98b93cab29d9b1101a6143fb8bce00e2eac4 # v2.7.1 with: egress-policy: audit - uses: actions/checkout@44c2b7a8a4ea60a981eaca3cf939b5f4305c123b # v4.1.5 @@ -85,8 +81,7 @@ jobs: TARGET_ARCH: "${{ matrix.arch }}" name: server initrd ${{ matrix.arch }} steps: - - name: Harden Runner - uses: step-security/harden-runner@a4aa98b93cab29d9b1101a6143fb8bce00e2eac4 # v2.7.1 + - uses: step-security/harden-runner@a4aa98b93cab29d9b1101a6143fb8bce00e2eac4 # v2.7.1 with: egress-policy: audit - uses: actions/checkout@44c2b7a8a4ea60a981eaca3cf939b5f4305c123b # v4.1.5 diff --git a/Cargo.lock b/Cargo.lock index 4f09cfd..c6a1a79 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1406,6 +1406,21 @@ dependencies = [ "serde", ] +[[package]] +name = "krata-buildtools" +version = "0.0.10" +dependencies = [ + "anyhow", + "env_logger", + "krata-oci", + "krata-tokio-tar", + "oci-spec", + "scopeguard", + "tokio", + "tokio-stream", + "uuid", +] + [[package]] name = "krata-ctl" version = "0.0.10" diff --git a/Cargo.toml b/Cargo.toml index 8d6445f..9997aba 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,5 +1,6 @@ [workspace] members = [ + "crates/build", "crates/krata", "crates/oci", "crates/guest", diff --git a/DEV.md b/DEV.md index dd761b2..103777e 100644 --- a/DEV.md +++ b/DEV.md @@ -64,10 +64,10 @@ $ git clone https://github.com/edera-dev/krata.git krata $ cd krata ``` -6. Build a guest kernel image: +6. Fetch the guest kernel image: ```sh -$ ./hack/kernel/build.sh +$ ./hack/kernel/fetch.sh -u ``` 7. Copy the guest kernel artifacts to `/var/lib/krata/guest/kernel` so it is automatically detected by kratad: diff --git a/crates/build/Cargo.toml b/crates/build/Cargo.toml new file mode 100644 index 0000000..5d614df --- /dev/null +++ b/crates/build/Cargo.toml @@ -0,0 +1,25 @@ +[package] +name = "krata-buildtools" +description = "Build tools for krata." +license.workspace = true +version.workspace = true +homepage.workspace = true +repository.workspace = true +edition = "2021" +resolver = "2" +publish = false + +[dependencies] +anyhow = { workspace = true } +env_logger = { workspace = true } +oci-spec = { workspace = true } +scopeguard = { workspace = true } +tokio = { workspace = true } +tokio-stream = { workspace = true } +krata-oci = { path = "../oci", version = "^0.0.10" } +krata-tokio-tar = { workspace = true } +uuid = { workspace = true } + +[[bin]] +name = "build-fetch-kernel" +path = "bin/fetch_kernel.rs" diff --git a/crates/build/bin/fetch_kernel.rs b/crates/build/bin/fetch_kernel.rs new file mode 100644 index 0000000..79c673c --- /dev/null +++ b/crates/build/bin/fetch_kernel.rs @@ -0,0 +1,120 @@ +use std::{ + env::{self, args}, + path::PathBuf, +}; + +use anyhow::{anyhow, Result}; +use env_logger::Env; +use krataoci::{ + name::ImageName, + packer::{service::OciPackerService, OciPackedFormat}, + progress::OciProgressContext, + registry::OciPlatform, +}; +use oci_spec::image::{Arch, Os}; +use tokio::{ + fs::{self, File}, + io::BufReader, +}; +use tokio_stream::StreamExt; +use tokio_tar::Archive; +use uuid::Uuid; + +#[tokio::main] +async fn main() -> Result<()> { + env_logger::Builder::from_env(Env::default().default_filter_or("warn")).init(); + fs::create_dir_all("target/kernel").await?; + + let arch = env::var("TARGET_ARCH").map_err(|_| anyhow!("missing TARGET_ARCH env var"))?; + let platform = OciPlatform::new( + Os::Linux, + match arch.as_str() { + "x86_64" => Arch::Amd64, + "aarch64" => Arch::ARM64, + _ => { + return Err(anyhow!("unknown architecture '{}'", arch)); + } + }, + ); + + let image = ImageName::parse(&args().nth(1).unwrap())?; + let mut cache_dir = std::env::temp_dir().clone(); + cache_dir.push(format!("krata-cache-{}", Uuid::new_v4())); + fs::create_dir_all(&cache_dir).await?; + + let _delete_cache_dir = scopeguard::guard(cache_dir.clone(), |dir| { + let _ = std::fs::remove_dir_all(dir); + }); + + let (context, _) = OciProgressContext::create(); + let service = OciPackerService::new(None, &cache_dir, platform).await?; + let packed = service + .request(image.clone(), OciPackedFormat::Tar, false, context) + .await?; + let annotations = packed + .manifest + .item() + .annotations() + .clone() + .unwrap_or_default(); + let Some(format) = annotations.get("dev.edera.kernel.format") else { + return Err(anyhow!( + "image manifest missing 'dev.edera.kernel.format' annotation" + )); + }; + let Some(version) = annotations.get("dev.edera.kernel.version") else { + return Err(anyhow!( + "image manifest missing 'dev.edera.kernel.version' annotation" + )); + }; + let Some(flavor) = annotations.get("dev.edera.kernel.flavor") else { + return Err(anyhow!( + "image manifest missing 'dev.edera.kernel.flavor' annotation" + )); + }; + + if format != "1" { + return Err(anyhow!("kernel format version '{}' is unknown", format)); + } + + let file = BufReader::new(File::open(packed.path).await?); + let mut archive = Archive::new(file); + let mut entries = archive.entries()?; + + let kernel_image_tar_path = PathBuf::from("kernel/image"); + let kernel_addons_tar_path = PathBuf::from("kernel/addons.squashfs"); + let kernel_image_out_path = PathBuf::from(format!("target/kernel/kernel-{}", arch)); + let kernel_addons_out_path = PathBuf::from(format!("target/kernel/addons-{}.squashfs", arch)); + + if kernel_image_out_path.exists() { + fs::remove_file(&kernel_image_out_path).await?; + } + + if kernel_addons_out_path.exists() { + fs::remove_file(&kernel_addons_out_path).await?; + } + + while let Some(entry) = entries.next().await { + let mut entry = entry?; + let path = entry.path()?.to_path_buf(); + + if !entry.header().entry_type().is_file() { + continue; + } + + if path == kernel_image_tar_path { + entry.unpack(&kernel_image_out_path).await?; + } else if path == kernel_addons_tar_path { + entry.unpack(&kernel_addons_out_path).await?; + } + } + + if !kernel_image_out_path.exists() { + return Err(anyhow!("image did not contain a file named /kernel/image")); + } + + println!("kernel version: v{}", version); + println!("kernel flavor: {}", flavor); + + Ok(()) +} diff --git a/hack/dist/bundle.sh b/hack/dist/bundle.sh index fd33755..b3838b4 100755 --- a/hack/dist/bundle.sh +++ b/hack/dist/bundle.sh @@ -24,10 +24,7 @@ do cp "${KRATA_DIR}/target/${RUST_TARGET}/release/${X}" "${BUNDLE_DIR}/${X}" done ./hack/initrd/build.sh -if [ "${KRATA_KERNEL_BUILD_SKIP}" != "1" ] -then - ./hack/kernel/build.sh "-j${KRATA_KERNEL_BUILD_JOBS}" -fi +./hack/kernel/fetch.sh cd "${BUNDLE_DIR}" diff --git a/hack/kernel/build.sh b/hack/kernel/build.sh deleted file mode 100755 index 589dae5..0000000 --- a/hack/kernel/build.sh +++ /dev/null @@ -1,36 +0,0 @@ -#!/bin/sh -set -e - -REAL_SCRIPT="$(realpath "${0}")" -cd "$(dirname "${REAL_SCRIPT}")/../.." -KRATA_DIR="$(realpath "${PWD}")" - -# shellcheck source-path=SCRIPTDIR source=common.sh -. "${KRATA_DIR}/hack/kernel/common.sh" - -make -C "${KERNEL_SRC}" ARCH="${TARGET_ARCH_KERNEL}" -j"${KRATA_KERNEL_BUILD_JOBS}" "${CROSS_COMPILE_MAKE}" "${IMAGE_TARGET}" modules - -rm -rf "${MODULES_INSTALL_PATH}" -rm -rf "${ADDONS_OUTPUT_PATH}" -rm -rf "${ADDONS_SQUASHFS_PATH}" - -make -C "${KERNEL_SRC}" ARCH="${TARGET_ARCH_KERNEL}" -j"${KRATA_KERNEL_BUILD_JOBS}" "${CROSS_COMPILE_MAKE}" INSTALL_MOD_PATH="${MODULES_INSTALL_PATH}" modules_install -KERNEL_MODULES_VER="$(ls "${MODULES_INSTALL_PATH}/lib/modules")" - -mkdir -p "${ADDONS_OUTPUT_PATH}" -mv "${MODULES_INSTALL_PATH}/lib/modules/${KERNEL_MODULES_VER}" "${MODULES_OUTPUT_PATH}" -rm -rf "${MODULES_INSTALL_PATH}" -[ -L "${MODULES_OUTPUT_PATH}/build" ] && unlink "${MODULES_OUTPUT_PATH}/build" - -mksquashfs "${ADDONS_OUTPUT_PATH}" "${ADDONS_SQUASHFS_PATH}" -all-root - -if [ "${TARGET_ARCH_STANDARD}" = "x86_64" ] -then - cp "${KERNEL_SRC}/arch/x86/boot/bzImage" "${OUTPUT_DIR}/kernel-${TARGET_ARCH_STANDARD}" -elif [ "${TARGET_ARCH_STANDARD}" = "aarch64" ] -then - cp "${KERNEL_SRC}/arch/arm64/boot/Image.gz" "${OUTPUT_DIR}/kernel-${TARGET_ARCH_STANDARD}" -else - echo "ERROR: unable to determine what file is the vmlinuz for ${TARGET_ARCH_STANDARD}" > /dev/stderr - exit 1 -fi diff --git a/hack/kernel/common.sh b/hack/kernel/common.sh deleted file mode 100644 index 0f5b5b1..0000000 --- a/hack/kernel/common.sh +++ /dev/null @@ -1,75 +0,0 @@ -#!/bin/sh -set -e - -REAL_SCRIPT="$(realpath "${0}")" -cd "$(dirname "${REAL_SCRIPT}")/../.." -KRATA_DIR="$(realpath "${PWD}")" -KERNEL_DIR="${KRATA_DIR}/kernel" - -cd "${KRATA_DIR}" - -TARGET_ARCH_STANDARD="$(KRATA_ARCH_KERNEL_NAME=0 ./hack/build/arch.sh)" -TARGET_ARCH_KERNEL="$(KRATA_ARCH_KERNEL_NAME=1 ./hack/build/arch.sh)" -C_TARGET="$(KRATA_TARGET_C_MODE=1 KRATA_TARGET_IGNORE_LIBC=1 ./hack/build/target.sh)" -IS_CROSS_COMPILE="$(./hack/build/cross-compile.sh)" - -if [ "${IS_CROSS_COMPILE}" = "1" ] -then - CROSS_COMPILE_MAKE="CROSS_COMPILE=${C_TARGET}-" -else - CROSS_COMPILE_MAKE="CROSS_COMPILE=" -fi - -# shellcheck source-path=SCRIPTDIR source=../../kernel/config.sh -. "${KERNEL_DIR}/config.sh" -KERNEL_SRC="${KERNEL_DIR}/linux-${KERNEL_VERSION}-${TARGET_ARCH_STANDARD}" - -if [ -z "${KRATA_KERNEL_BUILD_JOBS}" ] -then - KRATA_KERNEL_BUILD_JOBS="$(nproc)" -fi - -if [ ! -f "${KERNEL_SRC}/Makefile" ] -then - rm -rf "${KERNEL_SRC}" - mkdir -p "${KERNEL_SRC}" - curl --progress-bar -L -o "${KERNEL_SRC}.txz" "${KERNEL_SRC_URL}" - tar xf "${KERNEL_SRC}.txz" --strip-components 1 -C "${KERNEL_SRC}" - rm "${KERNEL_SRC}.txz" -fi - -OUTPUT_DIR="${KRATA_DIR}/target/kernel" -mkdir -p "${OUTPUT_DIR}" - -KERNEL_CONFIG_FILE="${KERNEL_DIR}/krata-${TARGET_ARCH_STANDARD}.config" - -if [ ! -f "${KERNEL_CONFIG_FILE}" ] -then - echo "ERROR: kernel config file not found for ${TARGET_ARCH_STANDARD}" > /dev/stderr - exit 1 -fi - -cp "${KERNEL_CONFIG_FILE}" "${KERNEL_SRC}/.config" -make -C "${KERNEL_SRC}" ARCH="${TARGET_ARCH_KERNEL}" "${CROSS_COMPILE_MAKE}" olddefconfig - -# shellcheck disable=SC2034 -IMAGE_TARGET="bzImage" - -if [ "${TARGET_ARCH_STANDARD}" = "x86_64" ] -then - # shellcheck disable=SC2034 - IMAGE_TARGET="bzImage" -elif [ "${TARGET_ARCH_STANDARD}" = "aarch64" ] -then - # shellcheck disable=SC2034 - IMAGE_TARGET="Image.gz" -fi - -# shellcheck disable=SC2034 -MODULES_INSTALL_PATH="${OUTPUT_DIR}/modules-install-${TARGET_ARCH_STANDARD}" -# shellcheck disable=SC2034 -ADDONS_OUTPUT_PATH="${OUTPUT_DIR}/addons-${TARGET_ARCH_STANDARD}" -# shellcheck disable=SC2034 -MODULES_OUTPUT_PATH="${ADDONS_OUTPUT_PATH}/modules" -# shellcheck disable=SC2034 -ADDONS_SQUASHFS_PATH="${OUTPUT_DIR}/addons-${TARGET_ARCH_STANDARD}.squashfs" diff --git a/hack/kernel/config.sh b/hack/kernel/config.sh deleted file mode 100755 index 3fce5d7..0000000 --- a/hack/kernel/config.sh +++ /dev/null @@ -1,16 +0,0 @@ -#!/bin/sh -set -e - -REAL_SCRIPT="$(realpath "${0}")" -cd "$(dirname "${REAL_SCRIPT}")/../.." -KRATA_DIR="$(realpath "${PWD}")" - -# shellcheck source-path=SCRIPTDIR source=common.sh -. "${KRATA_DIR}/hack/kernel/common.sh" - -rm -rf "${MODULES_INSTALL_PATH}" -rm -rf "${ADDONS_OUTPUT_PATH}" -rm -rf "${ADDONS_SQUASHFS_PATH}" - -make -C "${KERNEL_SRC}" ARCH="${TARGET_ARCH_KERNEL}" "${CROSS_COMPILE_MAKE}" INSTALL_MOD_PATH="${MODULES_INSTALL_PATH}" nconfig -cp "${KERNEL_SRC}/.config" "${KERNEL_CONFIG_FILE}" diff --git a/hack/kernel/fetch.sh b/hack/kernel/fetch.sh new file mode 100755 index 0000000..83bbf3c --- /dev/null +++ b/hack/kernel/fetch.sh @@ -0,0 +1,17 @@ +#!/bin/sh +set -e + +REAL_SCRIPT="$(realpath "${0}")" +cd "$(dirname "${REAL_SCRIPT}")/../.." +KRATA_DIR="${PWD}" +cd "${KRATA_DIR}" + +TARGET_ARCH="$(./hack/build/arch.sh)" + +if [ "${1}" != "-u" ] && [ -f "target/kernel/kernel-${TARGET_ARCH}" ] +then + exit 0 +fi + +export TARGET_ARCH +exec ./hack/build/cargo.sh run -q --bin build-fetch-kernel ghcr.io/edera-dev/kernels:latest