diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml index b1fc2ec..ddc1073 100644 --- a/.github/workflows/check.yml +++ b/.github/workflows/check.yml @@ -7,16 +7,16 @@ jobs: steps: - uses: actions/checkout@v4 - uses: dtolnay/rust-toolchain@stable - - run: ./scripts/ci/install-deps.sh - - run: ./scripts/build/cargo.sh build + - run: ./hack/ci/install-deps.sh + - run: ./hack/build/cargo.sh build test: name: cargo test runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - uses: dtolnay/rust-toolchain@stable - - run: ./scripts/ci/install-deps.sh - - run: ./scripts/build/cargo.sh test + - run: ./hack/ci/install-deps.sh + - run: ./hack/build/cargo.sh test clippy: name: cargo clippy runs-on: ubuntu-latest @@ -25,8 +25,8 @@ jobs: - uses: dtolnay/rust-toolchain@stable with: components: clippy - - run: ./scripts/ci/install-deps.sh - - run: ./scripts/build/cargo.sh clippy + - run: ./hack/ci/install-deps.sh + - run: ./hack/build/cargo.sh clippy fmt: name: cargo fmt runs-on: ubuntu-latest @@ -35,8 +35,8 @@ jobs: - uses: dtolnay/rust-toolchain@stable with: components: rustfmt - - run: ./scripts/ci/install-deps.sh - - run: ./scripts/build/cargo.sh fmt --all -- --check + - run: ./hack/ci/install-deps.sh + - run: ./hack/build/cargo.sh fmt --all -- --check initrd: name: initrd runs-on: ubuntu-latest @@ -45,5 +45,5 @@ jobs: - uses: dtolnay/rust-toolchain@stable with: targets: "x86_64-unknown-linux-gnu,x86_64-unknown-linux-musl" - - run: ./scripts/ci/install-deps.sh - - run: ./scripts/initrd/build.sh + - run: ./hack/ci/install-deps.sh + - run: ./hack/initrd/build.sh diff --git a/.github/workflows/kernel.yml b/.github/workflows/kernel.yml index 35b31df..51f5196 100644 --- a/.github/workflows/kernel.yml +++ b/.github/workflows/kernel.yml @@ -12,5 +12,5 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - - run: ./scripts/ci/install-deps.sh - - run: ./scripts/kernel/build.sh -j5 + - run: ./hack/ci/install-deps.sh + - run: ./hack/kernel/build.sh -j5 diff --git a/.github/workflows/nightly.yml b/.github/workflows/nightly.yml index 4a78955..ca59134 100644 --- a/.github/workflows/nightly.yml +++ b/.github/workflows/nightly.yml @@ -12,11 +12,11 @@ jobs: - uses: dtolnay/rust-toolchain@stable with: targets: "x86_64-unknown-linux-gnu,x86_64-unknown-linux-musl" - - run: ./scripts/ci/install-deps.sh - - run: ./scripts/dist/bundle.sh + - run: ./hack/ci/install-deps.sh + - run: ./hack/dist/bundle.sh env: KRATA_KERNEL_BUILD_JOBS: "5" - - run: ./scripts/dist/deb.sh + - run: ./hack/dist/deb.sh env: KRATA_BUNDLE_SKIP_KERNEL_BUILD: "1" - uses: actions/upload-artifact@v4 diff --git a/README.md b/README.md index 6c9dcec..0ae8098 100644 --- a/README.md +++ b/README.md @@ -42,12 +42,12 @@ Edera is building a company to compete in the hypervisor space with open-source krata is composed of three major executables: -| Executable | Runs On | User Interaction | Dev Runner | Code Path | -| ---------- | ------- | ---------------- | --------------------------- | ----------- | -| kratad | host | backend daemon | ./scripts/debug/kratad.sh | daemon | -| kratanet | host | backend daemon | ./scripts/debug/kratanet.sh | network | -| kratactl | host | CLI tool | ./scripts/debug/kratactl.sh | controller | -| krataguest | guest | none, guest init | N/A | guest | +| Executable | Runs On | User Interaction | Dev Runner | Code Path | +| ---------- | ------- | ---------------- | ------------------------ | ----------- | +| kratad | host | backend daemon | ./hack/debug/kratad.sh | daemon | +| kratanet | host | backend daemon | ./hack/debug/kratanet.sh | network | +| kratactl | host | CLI tool | ./hack/debug/kratactl.sh | controller | +| krataguest | guest | none, guest init | N/A | guest | You will find the code to each executable available in the bin/ and src/ directories inside it's corresponding code path from the above table. @@ -92,26 +92,26 @@ $ cd krata 6. Build a guest kernel image: ```sh -$ ./scripts/kernel/build.sh -j4 +$ ./hack/kernel/build.sh -j4 ``` 7. Copy the guest kernel image at `target/kernel/kernel` to `/var/lib/krata/guest/kernel` to have it automatically detected by kratad. -8. Launch `./scripts/debug/kratanet.sh` and keep it running in the foreground. -9. Launch `./scripts/debug/kratad.sh` and keep it running in the foreground. +8. Launch `./hack/debug/kratanet.sh` and keep it running in the foreground. +9. Launch `./hack/debug/kratad.sh` and keep it running in the foreground. 10. Run kratactl to launch a guest: ```sh -$ ./scripts/debug/kratactl.sh launch --attach alpine:latest +$ ./hack/debug/kratactl.sh launch --attach alpine:latest ``` To detach from the guest console, use `Ctrl + ]` on your keyboard. To list the running guests, run: ```sh -$ ./scripts/debug/kratactl.sh list +$ ./hack/debug/kratactl.sh list ``` To destroy a running guest, copy it's UUID from either the launch command or the guest list and run: ```sh -$ ./scripts/debug/kratactl.sh destroy GUEST_UUID +$ ./hack/debug/kratactl.sh destroy GUEST_UUID ``` diff --git a/scripts/build/arch.sh b/hack/build/arch.sh similarity index 100% rename from scripts/build/arch.sh rename to hack/build/arch.sh diff --git a/scripts/build/cargo.sh b/hack/build/cargo.sh similarity index 100% rename from scripts/build/cargo.sh rename to hack/build/cargo.sh diff --git a/scripts/build/target.sh b/hack/build/target.sh similarity index 100% rename from scripts/build/target.sh rename to hack/build/target.sh diff --git a/scripts/ci/install-deps.sh b/hack/ci/install-deps.sh similarity index 100% rename from scripts/ci/install-deps.sh rename to hack/ci/install-deps.sh diff --git a/hack/code/autofix.sh b/hack/code/autofix.sh new file mode 100755 index 0000000..f736388 --- /dev/null +++ b/hack/code/autofix.sh @@ -0,0 +1,8 @@ +#!/bin/sh +set -e + +REAL_SCRIPT="$(realpath "${0}")" +cd "$(dirname "${REAL_SCRIPT}")/../.." + +./hack/build/cargo.sh clippy --fix --allow-dirty --allow-staged +cargo fmt --all diff --git a/hack/code/shellcheck.sh b/hack/code/shellcheck.sh new file mode 100755 index 0000000..559448e --- /dev/null +++ b/hack/code/shellcheck.sh @@ -0,0 +1,7 @@ +#!/bin/sh +set -e + +REAL_SCRIPT="$(realpath "${0}")" +cd "$(dirname "${REAL_SCRIPT}")/../.." + +find hack -type f -name '*.sh' -print0 | xargs -0 shellcheck -x diff --git a/scripts/debug/common.sh b/hack/debug/common.sh similarity index 77% rename from scripts/debug/common.sh rename to hack/debug/common.sh index 8342db8..e935ef5 100644 --- a/scripts/debug/common.sh +++ b/hack/debug/common.sh @@ -22,10 +22,10 @@ build_and_run() { sudo mkdir -p /var/lib/krata/guest if [ "${KRATA_BUILD_INITRD}" = "1" ] then - ./scripts/initrd/build.sh -q + ./hack/initrd/build.sh -q sudo cp "target/initrd/initrd" "/var/lib/krata/guest/initrd" fi - RUST_TARGET="$(./scripts/build/target.sh)" - ./scripts/build/cargo.sh build ${CARGO_BUILD_FLAGS} --bin "${EXE_TARGET}" + RUST_TARGET="$(./hack/build/target.sh)" + ./hack/build/cargo.sh build ${CARGO_BUILD_FLAGS} --bin "${EXE_TARGET}" exec sudo RUST_LOG="${RUST_LOG}" "target/${RUST_TARGET}/debug/${EXE_TARGET}" "${@}" } diff --git a/scripts/debug/kratactl.sh b/hack/debug/kratactl.sh similarity index 74% rename from scripts/debug/kratactl.sh rename to hack/debug/kratactl.sh index 9a6c615..d0dd7f4 100755 --- a/scripts/debug/kratactl.sh +++ b/hack/debug/kratactl.sh @@ -3,7 +3,7 @@ set -e REAL_SCRIPT="$(realpath "${0}")" DEBUG_DIR="$(dirname "${REAL_SCRIPT}")" -# shellcheck source=common.sh +# shellcheck source-path=SCRIPTDIR source=common.sh . "${DEBUG_DIR}/common.sh" build_and_run kratactl "${@}" diff --git a/scripts/debug/kratad.sh b/hack/debug/kratad.sh similarity index 76% rename from scripts/debug/kratad.sh rename to hack/debug/kratad.sh index 0007880..8b94fe6 100755 --- a/scripts/debug/kratad.sh +++ b/hack/debug/kratad.sh @@ -3,7 +3,7 @@ set -e REAL_SCRIPT="$(realpath "${0}")" DEBUG_DIR="$(dirname "${REAL_SCRIPT}")" -# shellcheck source=common.sh +# shellcheck source-path=SCRIPTDIR source=common.sh . "${DEBUG_DIR}/common.sh" KRATA_BUILD_INITRD=1 build_and_run kratad "${@}" diff --git a/scripts/debug/kratanet.sh b/hack/debug/kratanet.sh similarity index 74% rename from scripts/debug/kratanet.sh rename to hack/debug/kratanet.sh index 0b2fc6d..3fdb621 100755 --- a/scripts/debug/kratanet.sh +++ b/hack/debug/kratanet.sh @@ -3,7 +3,7 @@ set -e REAL_SCRIPT="$(realpath "${0}")" DEBUG_DIR="$(dirname "${REAL_SCRIPT}")" -# shellcheck source=common.sh +# shellcheck source-path=SCRIPTDIR source=common.sh . "${DEBUG_DIR}/common.sh" build_and_run kratanet "${@}" diff --git a/scripts/debug/session.sh b/hack/debug/session.sh similarity index 100% rename from scripts/debug/session.sh rename to hack/debug/session.sh diff --git a/hack/debug/session.yml b/hack/debug/session.yml new file mode 100644 index 0000000..e026bf6 --- /dev/null +++ b/hack/debug/session.yml @@ -0,0 +1,11 @@ +session_name: krata-dev +start_directory: ../.. +sleep_after: 3 +windows: +- window_name: live + layout: tiled + panes: + - shell_command: ./hack/debug/kratad.sh + - shell_command: ./hack/debug/kratanet.sh + - focus: true + shell_command: "alias kratactl=./hack/debug/kratactl.sh" diff --git a/scripts/dist/bundle.sh b/hack/dist/bundle.sh similarity index 81% rename from scripts/dist/bundle.sh rename to hack/dist/bundle.sh index b55d9b9..645d7a8 100755 --- a/scripts/dist/bundle.sh +++ b/hack/dist/bundle.sh @@ -1,7 +1,7 @@ #!/bin/sh set -e -# shellcheck source=common.sh +# shellcheck source-path=SCRIPTDIR source=common.sh . "$(dirname "${0}")/common.sh" if [ -z "${KRATA_KERNEL_BUILD_JOBS}" ] @@ -16,14 +16,14 @@ BUNDLE_DIR="${BUNDLE_DIR}/krata" mkdir -p "${BUNDLE_DIR}" for X in kratad kratanet kratactl do - ./scripts/build/cargo.sh build --release --bin "${X}" - RUST_TARGET="$(./scripts/build/target.sh)" + ./hack/build/cargo.sh build --release --bin "${X}" + RUST_TARGET="$(./hack/build/target.sh)" cp "${KRATA_DIR}/target/${RUST_TARGET}/release/${X}" "${BUNDLE_DIR}/${X}" done -./scripts/initrd/build.sh +./hack/initrd/build.sh if [ "${KRATA_BUNDLE_SKIP_KERNEL_BUILD}" != "1" ] then - ./scripts/kernel/build.sh "-j${KRATA_KERNEL_BUILD_JOBS}" + ./hack/kernel/build.sh "-j${KRATA_KERNEL_BUILD_JOBS}" fi cd "${BUNDLE_DIR}" diff --git a/scripts/dist/common.sh b/hack/dist/common.sh similarity index 100% rename from scripts/dist/common.sh rename to hack/dist/common.sh diff --git a/scripts/dist/deb.sh b/hack/dist/deb.sh similarity index 75% rename from scripts/dist/deb.sh rename to hack/dist/deb.sh index f0892d9..45218c9 100755 --- a/scripts/dist/deb.sh +++ b/hack/dist/deb.sh @@ -1,13 +1,13 @@ #!/bin/sh set -e -# shellcheck source=common.sh +# shellcheck source-path=SCRIPTDIR source=common.sh . "$(dirname "${0}")/common.sh" -"${KRATA_DIR}/scripts/dist/systar.sh" +"${KRATA_DIR}/hack/dist/systar.sh" -KRATA_VERSION="$("${KRATA_DIR}/scripts/dist/version.sh")" -TARGET_ARCH="$(KRATA_ARCH_ALT_NAME=1 "${KRATA_DIR}/scripts/build/arch.sh")" +KRATA_VERSION="$("${KRATA_DIR}/hack/dist/version.sh")" +TARGET_ARCH="$(KRATA_ARCH_ALT_NAME=1 "${KRATA_DIR}/hack/build/arch.sh")" cd "${OUTPUT_DIR}" diff --git a/scripts/dist/systar.sh b/hack/dist/systar.sh similarity index 87% rename from scripts/dist/systar.sh rename to hack/dist/systar.sh index d1be503..3853fcf 100755 --- a/scripts/dist/systar.sh +++ b/hack/dist/systar.sh @@ -1,10 +1,10 @@ #!/bin/sh set -e -# shellcheck source=common.sh +# shellcheck source-path=SCRIPTDIR source=common.sh . "$(dirname "${0}")/common.sh" -"${KRATA_DIR}/scripts/dist/bundle.sh" +"${KRATA_DIR}/hack/dist/bundle.sh" SYSTAR="${OUTPUT_DIR}/system.tgz" rm -f "${SYSTAR}" diff --git a/scripts/dist/version.sh b/hack/dist/version.sh similarity index 85% rename from scripts/dist/version.sh rename to hack/dist/version.sh index 6107ae8..246eff9 100755 --- a/scripts/dist/version.sh +++ b/hack/dist/version.sh @@ -1,7 +1,7 @@ #!/bin/sh set -e -# shellcheck source=common.sh +# shellcheck source-path=SCRIPTDIR source=common.sh . "$(dirname "${0}")/common.sh" cd "${KRATA_DIR}" diff --git a/scripts/initrd/build.sh b/hack/initrd/build.sh similarity index 83% rename from scripts/initrd/build.sh rename to hack/initrd/build.sh index 6e616b7..fad9dd2 100755 --- a/scripts/initrd/build.sh +++ b/hack/initrd/build.sh @@ -7,10 +7,10 @@ KRATA_DIR="${PWD}" cd "${KRATA_DIR}" export RUST_LIBC="musl" -RUST_TARGET="$(./scripts/build/target.sh)" +RUST_TARGET="$(./hack/build/target.sh)" export RUSTFLAGS="-Ctarget-feature=+crt-static" -./scripts/build/cargo.sh build "${@}" --release --bin krataguest +./hack/build/cargo.sh build "${@}" --release --bin krataguest INITRD_DIR="$(mktemp -d /tmp/krata-initrd.XXXXXXXXXXXXX)" cp "target/${RUST_TARGET}/release/krataguest" "${INITRD_DIR}/init" chmod +x "${INITRD_DIR}/init" diff --git a/scripts/kernel/build.sh b/hack/kernel/build.sh similarity index 91% rename from scripts/kernel/build.sh rename to hack/kernel/build.sh index 76b556b..9d489eb 100755 --- a/scripts/kernel/build.sh +++ b/hack/kernel/build.sh @@ -8,7 +8,7 @@ KERNEL_DIR="${KRATA_DIR}/kernel" cd "${KRATA_DIR}" -# shellcheck source=../../kernel/config.sh +# shellcheck source-path=SCRIPTDIR source=../../kernel/config.sh . "${KERNEL_DIR}/config.sh" KERNEL_SRC="${KERNEL_DIR}/linux-${KERNEL_VERSION}" @@ -23,7 +23,7 @@ fi OUTPUT_DIR="${KRATA_DIR}/target/kernel" mkdir -p "${OUTPUT_DIR}" -TARGET_ARCH="$(KRATA_ARCH_KERNEL_NAME=1 ./scripts/build/arch.sh)" +TARGET_ARCH="$(KRATA_ARCH_KERNEL_NAME=1 ./hack/build/arch.sh)" KERNEL_CONFIG_FILE="${KERNEL_DIR}/krata-${TARGET_ARCH}.config" diff --git a/scripts/kernel/clean.sh b/hack/kernel/clean.sh similarity index 100% rename from scripts/kernel/clean.sh rename to hack/kernel/clean.sh diff --git a/lefthook.toml b/lefthook.toml index be06003..63480b1 100644 --- a/lefthook.toml +++ b/lefthook.toml @@ -2,13 +2,13 @@ parallel = true [pre-commit.commands.build] -run = "./scripts/build/cargo.sh build" +run = "./hack/build/cargo.sh build" [pre-commit.commands.test] -run = "./scripts/build/cargo.sh test" +run = "./hack/build/cargo.sh test" [pre-commit.commands.fmt] -run = "./scripts/build/cargo.sh fmt --all -- --check" +run = "./hack/build/cargo.sh fmt --all -- --check" [pre-commit.commands.clippy] -run = "./scripts/build/cargo.sh clippy" +run = "./hack/build/cargo.sh clippy" diff --git a/scripts/code/fix.sh b/scripts/code/fix.sh deleted file mode 100755 index 13623f9..0000000 --- a/scripts/code/fix.sh +++ /dev/null @@ -1,6 +0,0 @@ -#!/bin/sh -set -e - -cd "$(dirname "${0}")/../.." -./scripts/build/cargo.sh clippy --fix --allow-dirty --allow-staged -cargo fmt --all diff --git a/scripts/debug/session.yml b/scripts/debug/session.yml deleted file mode 100644 index ccd3af4..0000000 --- a/scripts/debug/session.yml +++ /dev/null @@ -1,11 +0,0 @@ -session_name: krata-dev -start_directory: ../.. -sleep_after: 3 -windows: -- window_name: live - layout: tiled - panes: - - shell_command: ./scripts/debug/kratad.sh - - shell_command: ./scripts/debug/kratanet.sh - - focus: true - shell_command: "alias kratactl=./scripts/debug/kratactl.sh"