diff options
Diffstat
41 files changed, 586 insertions, 1494 deletions
diff --git a/.dockerignore b/.dockerignore deleted file mode 100644 --- a/.dockerignore +++ /dev/null @@ -1,9 +0,0 @@ -# SPDX-FileCopyrightText: 2026 Nikolay Govorov -# SPDX-License-Identifier: Apache-2.0 - -.git -.github -.recluse-state -dist -target -*.lcov diff --git a/.editorconfig b/.editorconfig index 86ea420..d957269 100644 --- a/.editorconfig +++ b/.editorconfig @@ -1,4 +1,4 @@ -# SPDX-FileCopyrightText: 2026 Nikolay Govorov +# SPDX-FileCopyrightText: 2026 Nikolay Govorov # SPDX-License-Identifier: Apache-2.0 root = true diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index be7c3ff..17a282e 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -6,20 +6,14 @@ name: Build on: push: branches: [main] - tags: ["v*"] pull_request: branches: [main] permissions: contents: read -concurrency: - group: hule-build-${{ github.ref }} - cancel-in-progress: true - env: CARGO_TERM_COLOR: always - RELEASE_TAG: nightly jobs: lint: @@ -28,22 +22,15 @@ jobs: steps: - uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1 - - uses: jdx/mise-action@5228313ee0372e111a38da051671ca30fc5a96db # v3 + - uses: dtolnay/rust-toolchain@4be9e76fd7c4901c61fb841f559994984270fce7 # stable with: - version: 2026.7.5 - experimental: true - install: false - - name: Install dependencies - run: mise bootstrap --locked --yes --update + components: clippy, rustfmt - uses: Swatinem/rust-cache@779680da715d629ac1d338a641029a2f4372abb5 # v2.8.2 - - name: formatting + - name: Check formatting run: cargo fmt --all --check - - name: shellcheck - run: shellcheck images/*/genimg - - - name: clippy + - name: Run Clippy run: cargo clippy --workspace --all-targets --all-features --release --locked -- -D warnings build: @@ -61,13 +48,7 @@ jobs: steps: - uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1 - - uses: jdx/mise-action@5228313ee0372e111a38da051671ca30fc5a96db # v3 - with: - version: 2026.7.5 - experimental: true - install: false - - name: Install dependencies - run: mise bootstrap --locked --yes + - uses: dtolnay/rust-toolchain@4be9e76fd7c4901c61fb841f559994984270fce7 # stable - uses: Swatinem/rust-cache@779680da715d629ac1d338a641029a2f4372abb5 # v2.8.2 - name: Build diff --git a/.github/workflows/legal.yml b/.github/workflows/legal.yml index b5a2fad..6d3cb53 100644 --- a/.github/workflows/legal.yml +++ b/.github/workflows/legal.yml @@ -6,7 +6,6 @@ name: Legal on: push: branches: [main] - tags: ["v*"] pull_request: branches: [main] @@ -22,14 +21,13 @@ jobs: with: fetch-depth: 0 - - uses: jdx/mise-action@5228313ee0372e111a38da051671ca30fc5a96db # v3 - with: - version: 2026.7.5 - experimental: true - install: false + - name: Check contributor agreement + run: ./scripts/check-signoff - - name: Check contribution sign-off - run: mise run signoff + - name: Check repository licensing + uses: fsfe/reuse-action@676e2d560c9a403aa252096d99fcab3e1132b0f5 # v6.0.0 - - name: Check licensing policy - run: mise run licenses + - name: Check dependency licenses + uses: EmbarkStudios/cargo-deny-action@3fd3802e88374d3fe9159b834c7714ec57d6c979 # 0.19.0 + with: + command: check licenses diff --git a/.gitignore b/.gitignore index ea96d7d..4af8e00 100644 --- a/.gitignore +++ b/.gitignore @@ -1,10 +1,8 @@ -# SPDX-FileCopyrightText: 2026 Nikolay Govorov +# Copyright (c) 2026 Nikolay Govorov # SPDX-License-Identifier: Apache-2.0 -/dist /target -mise.local.toml -mise.*.local.toml +/dist __pycache__ *.qcow2 diff --git a/.mailmap b/.mailmap index d364a7b..d8e0402 100644 --- a/.mailmap +++ b/.mailmap @@ -1,6 +1,3 @@ -# SPDX-FileCopyrightText: 2026 Nikolay Govorov -# SPDX-License-Identifier: Apache-2.0 -# # Add new entries in alphabetical order Nikolay Govorov <me@govorov.online> diff --git a/CLA.md b/CLA.md index 0560aa4..ec68d64 100644 --- a/CLA.md +++ b/CLA.md @@ -1,45 +1,43 @@ -# Hule Individual Contributor License Agreement +# Hule Grant and Contributor License Agreement -Version 1.0 +> This agreement is based on the Harmony Combined Contributor Agreement +> Version 1.0 licensed under a [Creative Commons Attribution 3.0 Unported License](http://creativecommons.org/licenses/by/3.0/). -> This agreement is based on the Harmony Individual Contributor License -> Agreement Version 1.0 licensed under a -> [Creative Commons Attribution 3.0 Unported License](https://creativecommons.org/licenses/by/3.0/). - -Thank you for your interest in contributing to Hule (the "Project"). In this -Agreement, "We" and "Us" mean Nikolay Govorov. - -This contributor agreement ("Agreement") documents the rights granted by -contributors to Us. To make this document effective, You must personally add -the following trailers to every commit You Submit: - -```text -CLA-Version: 1.0 -Signed-off-by: Your Name <your.email@example.com> -``` - -The name and email address in `Signed-off-by` must identify You and match the -commit author. By Submitting a commit containing these trailers, You -electronically sign and accept this Agreement. No other person or automated -system may add the `Signed-off-by` trailer on Your behalf. This is a legally -binding document, so please read it carefully before agreeing to it. +Thank you for your interest in contributing to Hule ("We" or "Us"). In order +to clarify the intellectual property license granted with Contributions from any +person or entity, We must have a Contributor License Agreement ("CLA") on file +that has been signed, accepted or otherwise agreed to by each contributor, +indicating agreement to the license terms below. This license is for your +protection as a contributor as well as the protection of the Us and our users; +it does not change your rights to use your own Contributions for any other +purpose. ## 1. Definitions -"You" means the individual who Submits a Contribution to Us. +"You" (Individual) means the individual who Submits a Contribution to Us. + +"You" (Entity) means any Legal Entity on behalf of whom a Contribution has been +received by Us. "Legal Entity" means an entity which is not a natural person. +"Affiliates" means other Legal Entities that control, are controlled by, or +under common control with that Legal Entity. For the purposes of this +definition, "control" means (i) the power, direct or indirect, to cause the +direction or management of such Legal Entity, whether by contract or otherwise, +(ii) ownership of fifty percent (50%) or more of the outstanding shares or +securities which vote to elect the management or other persons who direct such +Legal Entity or (iii) beneficial ownership of such entity. "Contribution" means any work of authorship that is Submitted by You to Us in -which You own or assert ownership of the Copyright. If You do not own the -Copyright in the entire work of authorship, please follow the instructions in -Section 3(d). +which You own or assert ownership of the Copyright. "Copyright" means all rights protecting works of authorship owned or controlled -by You, including copyright, moral and neighboring rights, as appropriate, for -the full term of their existence including any extensions by You. +by You [or Your Affiliates], including copyright, moral and neighboring rights, +as appropriate, for the full term of their existence including any extensions by +You. "Material" means the work of authorship which is made available by Us to third -parties as part of the Project. After You Submit the Contribution, it may be -included in the Material. +parties. When this Agreement covers more than one software project, the Material +means the work of authorship to which the Contribution was Submitted. After You +Submit the Contribution, it may be included in the Material. "Submit" means any form of electronic, verbal, or written communication sent to Us or our representatives, including but not limited to electronic mailing @@ -71,10 +69,40 @@ modify, display, perform and distribute the Contribution as part of the Material; provided that this license is conditioned upon compliance with Section 2.3. +### 2.1 Copyright Assignment + +(a) At the time the Contribution is Submitted, You assign to Us all right, +title, and interest worldwide in all Copyright covering the Contribution; +provided that this transfer is conditioned upon compliance with Section 2.3. + +(b) To the extent that any of the rights in Section 2.1(a) cannot be assigned by +You to Us, You grant to Us a perpetual, worldwide, exclusive, royalty-free, +transferable, irrevocable license under such non-assigned rights, with rights to +sublicense through multiple tiers of sublicensees, to practice such non-assigned +rights, including, but not limited to, the right to reproduce, modify, display, +perform and distribute the Contribution; provided that this license is +conditioned upon compliance with Section 2.3. + +(c) To the extent that any of the rights in Section 2.1(a) can neither be +assigned nor licensed by You to Us, You irrevocably waive and agree never to +assert such rights against Us, any of our successors in interest, or any of our +licensees, either direct or indirect; provided that this agreement not to assert +is conditioned upon compliance with Section 2.3. + +(d) Upon such transfer of rights to Us, to the maximum extent possible, We +immediately grant to You a perpetual, worldwide, non-exclusive, royalty-free, +transferable, irrevocable license under such rights covering the Contribution, +with rights to sublicense through multiple tiers of sublicensees, to reproduce, +modify, display, perform, and distribute the Contribution. The intention of the +parties is that this license will be as broad as possible and to provide You +with rights as similar as possible to the owner of the rights that You +transferred. This license back is limited to the Contribution and does not +provide any rights to the Material. + ### 2.2 Patent License For patent claims including, without limitation, method, process, and apparatus -claims which You own, control or have the right to grant, +claims which You [or Your Affiliates] own, control or have the right to grant, now or in the future, You grant to Us a perpetual, worldwide, non-exclusive, transferable, royalty-free, irrevocable patent license, with the right to sublicense these rights to multiple tiers of sublicensees, to make, have made, @@ -106,7 +134,7 @@ the Material and may decide to include any Contribution We consider appropriate. ### 2.6 Reservation of Rights -Any rights not expressly licensed under this section are expressly +Any rights not expressly [assigned or] licensed under this section are expressly reserved by You. ## 3. Agreement @@ -115,32 +143,31 @@ You confirm that: (a) You have the legal authority to enter into this Agreement. -(b) You own the Copyright and patent claims covering the +(b) You [or Your Affiliates] own the Copyright and patent claims covering the Contribution which are required to grant the rights under Section 2. -(c) The grant of rights under Section 2 does not violate any grant +(c) (Individual) The grant of rights under Section 2 does not violate any grant of rights which You have made to third parties, including Your employer. If You are an employee, You have had Your employer approve this Agreement or sign the Entity version of this document. If You are less than eighteen years old, please have Your parents or guardian sign the Agreement. -(d) If You do not own the Copyright in the entire work of authorship Submitted, -You have clearly identified the third-party work, its source, and its license in -the Submission. +(c) (Entity) The grant of rights under Section 2 does not violate any grant of +rights which You or Your Affiliates have made to third parties. ## 4. Disclaimer EXCEPT FOR THE EXPRESS WARRANTIES IN SECTION 3, THE CONTRIBUTION IS PROVIDED "AS IS". MORE PARTICULARLY, ALL EXPRESS OR IMPLIED WARRANTIES INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR -PURPOSE AND NON-INFRINGEMENT ARE EXPRESSLY DISCLAIMED BY YOU TO US. -TO THE EXTENT THAT ANY SUCH WARRANTIES CANNOT BE DISCLAIMED, SUCH WARRANTY +PURPOSE AND NON-INFRINGEMENT ARE EXPRESSLY DISCLAIMED BY YOU TO US [AND BY US TO +YOU]. TO THE EXTENT THAT ANY SUCH WARRANTIES CANNOT BE DISCLAIMED, SUCH WARRANTY IS LIMITED IN DURATION TO THE MINIMUM PERIOD PERMITTED BY LAW. ## 5. Consequential Damage Waiver -TO THE MAXIMUM EXTENT PERMITTED BY APPLICABLE LAW, IN NO EVENT WILL YOU BE -LIABLE FOR ANY LOSS OF PROFITS, LOSS OF ANTICIPATED SAVINGS, LOSS OF DATA, +TO THE MAXIMUM EXTENT PERMITTED BY APPLICABLE LAW, IN NO EVENT WILL YOU [OR US] +BE LIABLE FOR ANY LOSS OF PROFITS, LOSS OF ANTICIPATED SAVINGS, LOSS OF DATA, INDIRECT, SPECIAL, INCIDENTAL, CONSEQUENTIAL AND EXEMPLARY DAMAGES ARISING OUT OF THIS AGREEMENT REGARDLESS OF THE LEGAL OR EQUITABLE THEORY (CONTRACT, TORT OR OTHERWISE) UPON WHICH THE CLAIM IS BASED. diff --git a/CODEOWNERS b/CODEOWNERS index 60d94a3..595b53f 100644 --- a/CODEOWNERS +++ b/CODEOWNERS @@ -1,4 +1,4 @@ -# SPDX-FileCopyrightText: 2026 Nikolay Govorov +# SPDX-FileCopyrightText: 2026 Nikolay Govorov # SPDX-License-Identifier: Apache-2.0 * @mrdimidium diff --git a/Cargo.lock b/Cargo.lock index d2d38d6..38d3abe 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -21,56 +21,6 @@ dependencies = [ ] [[package]] -name = "anstream" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "824a212faf96e9acacdbd09febd34438f8f711fb84e09a8916013cd7815ca28d" -dependencies = [ - "anstyle", - "anstyle-parse", - "anstyle-query", - "anstyle-wincon", - "colorchoice", - "is_terminal_polyfill", - "utf8parse", -] - -[[package]] -name = "anstyle" -version = "1.0.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "940b3a0ca603d1eade50a4846a2afffd5ef57a9feac2c0e2ec2e14f9ead76000" - -[[package]] -name = "anstyle-parse" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "52ce7f38b242319f7cabaa6813055467063ecdc9d355bbb4ce0c68908cd8130e" -dependencies = [ - "utf8parse", -] - -[[package]] -name = "anstyle-query" -version = "1.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "40c48f72fd53cd289104fc64099abca73db4166ad86ea0b4341abe65af83dadc" -dependencies = [ - "windows-sys 0.61.2", -] - -[[package]] -name = "anstyle-wincon" -version = "3.0.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "291e6a250ff86cd4a820112fb8898808a366d8f9f58ce16d1f538353ad55747d" -dependencies = [ - "anstyle", - "once_cell_polyfill", - "windows-sys 0.61.2", -] - -[[package]] name = "async-trait" version = "0.1.89" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -209,46 +159,6 @@ dependencies = [ ] [[package]] -name = "clap" -version = "4.6.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1ddb117e43bbf7dacf0a4190fef4d345b9bad68dfc649cb349e7d17d28428e51" -dependencies = [ - "clap_builder", - "clap_derive", -] - -[[package]] -name = "clap_builder" -version = "4.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "714a53001bf66416adb0e2ef5ac857140e7dc3a0c48fb28b2f10762fc4b5069f" -dependencies = [ - "anstream", - "anstyle", - "clap_lex", - "strsim", -] - -[[package]] -name = "clap_derive" -version = "4.6.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f2ce8604710f6733aa641a2b3731eaa1e8b3d9973d5e3565da11800813f997a9" -dependencies = [ - "heck", - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "clap_lex" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c8d4a3bb8b1e0c1050499d1815f5ab16d04f0959b233085fb31653fbfc9d98f9" - -[[package]] name = "cmake" version = "0.1.58" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -258,12 +168,6 @@ dependencies = [ ] [[package]] -name = "colorchoice" -version = "1.0.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1d07550c9036bf2ae0c684c4297d503f838287c83c53686d05370d0e139ae570" - -[[package]] name = "combine" version = "4.6.7" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -666,7 +570,6 @@ checksum = "6dbf3de79e51f3d586ab4cb9d5c3e2c14aa28ed23d180cf89b4df0454a69cc87" name = "hule" version = "0.1.0" dependencies = [ - "clap", "hule-hmi", "hule-oci", "hule-vmm", @@ -690,7 +593,6 @@ dependencies = [ "oci-client", "serde_json", "sha2 0.10.9", - "tokio", "zstd", ] @@ -914,12 +816,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d98f6fed1fde3f8c21bc40a1abb88dd75e67924f9cffc3ef95607bad8017f8e2" [[package]] -name = "is_terminal_polyfill" -version = "1.70.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a6cb138bb79a146c1bd460005623e142ef0181e3d0219cb493e02f7d08a35695" - -[[package]] name = "itoa" version = "1.0.18" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -1144,12 +1040,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9f7c3e4beb33f85d45ae3e3a1792185706c8e16d043238c593331cc7cd313b50" [[package]] -name = "once_cell_polyfill" -version = "1.70.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "384b8ab6d37215f3c5301a95a4accb5d64aa607f1fcb26a11b5303878451b4fe" - -[[package]] name = "openssl-probe" version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -1980,12 +1870,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b6c140620e7ffbb22c2dee59cafe6084a59b5ffc27a8859a5f0d494b5d52b6be" [[package]] -name = "utf8parse" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821" - -[[package]] name = "uuid" version = "1.23.4" source = "registry+https://github.com/rust-lang/crates.io-index" diff --git a/Cargo.toml b/Cargo.toml index 825ad03..7710d06 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,4 +1,4 @@ -# SPDX-FileCopyrightText: 2026 Nikolay Govorov +# SPDX-FileCopyrightText: 2026 Nikolay Govorov # SPDX-License-Identifier: Apache-2.0 [workspace] @@ -11,7 +11,7 @@ edition = "2024" version = "0.1.0" license = "Apache-2.0" authors = ["Nikolay Govorov <me@govorov.online>"] -repository = "https://git.dimidiumlabs.io/hule" +repository = "https://github.com/dimidiumlabs/hule" [workspace.dependencies] # local dependencies diff --git a/LICENSES/CC-BY-3.0.txt b/LICENSES/CC-BY-3.0.txt deleted file mode 100644 --- a/LICENSES/CC-BY-3.0.txt +++ /dev/null @@ -1,319 +0,0 @@ -Creative Commons Legal Code - -Attribution 3.0 Unported - - CREATIVE COMMONS CORPORATION IS NOT A LAW FIRM AND DOES NOT PROVIDE - LEGAL SERVICES. DISTRIBUTION OF THIS LICENSE DOES NOT CREATE AN - ATTORNEY-CLIENT RELATIONSHIP. CREATIVE COMMONS PROVIDES THIS - INFORMATION ON AN "AS-IS" BASIS. CREATIVE COMMONS MAKES NO WARRANTIES - REGARDING THE INFORMATION PROVIDED, AND DISCLAIMS LIABILITY FOR - DAMAGES RESULTING FROM ITS USE. - -License - -THE WORK (AS DEFINED BELOW) IS PROVIDED UNDER THE TERMS OF THIS CREATIVE -COMMONS PUBLIC LICENSE ("CCPL" OR "LICENSE"). THE WORK IS PROTECTED BY -COPYRIGHT AND/OR OTHER APPLICABLE LAW. ANY USE OF THE WORK OTHER THAN AS -AUTHORIZED UNDER THIS LICENSE OR COPYRIGHT LAW IS PROHIBITED. - -BY EXERCISING ANY RIGHTS TO THE WORK PROVIDED HERE, YOU ACCEPT AND AGREE -TO BE BOUND BY THE TERMS OF THIS LICENSE. TO THE EXTENT THIS LICENSE MAY -BE CONSIDERED TO BE A CONTRACT, THE LICENSOR GRANTS YOU THE RIGHTS -CONTAINED HERE IN CONSIDERATION OF YOUR ACCEPTANCE OF SUCH TERMS AND -CONDITIONS. - -1. Definitions - - a. "Adaptation" means a work based upon the Work, or upon the Work and - other pre-existing works, such as a translation, adaptation, - derivative work, arrangement of music or other alterations of a - literary or artistic work, or phonogram or performance and includes - cinematographic adaptations or any other form in which the Work may be - recast, transformed, or adapted including in any form recognizably - derived from the original, except that a work that constitutes a - Collection will not be considered an Adaptation for the purpose of - this License. For the avoidance of doubt, where the Work is a musical - work, performance or phonogram, the synchronization of the Work in - timed-relation with a moving image ("synching") will be considered an - Adaptation for the purpose of this License. - b. "Collection" means a collection of literary or artistic works, such as - encyclopedias and anthologies, or performances, phonograms or - broadcasts, or other works or subject matter other than works listed - in Section 1(f) below, which, by reason of the selection and - arrangement of their contents, constitute intellectual creations, in - which the Work is included in its entirety in unmodified form along - with one or more other contributions, each constituting separate and - independent works in themselves, which together are assembled into a - collective whole. A work that constitutes a Collection will not be - considered an Adaptation (as defined above) for the purposes of this - License. - c. "Distribute" means to make available to the public the original and - copies of the Work or Adaptation, as appropriate, through sale or - other transfer of ownership. - d. "Licensor" means the individual, individuals, entity or entities that - offer(s) the Work under the terms of this License. - e. "Original Author" means, in the case of a literary or artistic work, - the individual, individuals, entity or entities who created the Work - or if no individual or entity can be identified, the publisher; and in - addition (i) in the case of a performance the actors, singers, - musicians, dancers, and other persons who act, sing, deliver, declaim, - play in, interpret or otherwise perform literary or artistic works or - expressions of folklore; (ii) in the case of a phonogram the producer - being the person or legal entity who first fixes the sounds of a - performance or other sounds; and, (iii) in the case of broadcasts, the - organization that transmits the broadcast. - f. "Work" means the literary and/or artistic work offered under the terms - of this License including without limitation any production in the - literary, scientific and artistic domain, whatever may be the mode or - form of its expression including digital form, such as a book, - pamphlet and other writing; a lecture, address, sermon or other work - of the same nature; a dramatic or dramatico-musical work; a - choreographic work or entertainment in dumb show; a musical - composition with or without words; a cinematographic work to which are - assimilated works expressed by a process analogous to cinematography; - a work of drawing, painting, architecture, sculpture, engraving or - lithography; a photographic work to which are assimilated works - expressed by a process analogous to photography; a work of applied - art; an illustration, map, plan, sketch or three-dimensional work - relative to geography, topography, architecture or science; a - performance; a broadcast; a phonogram; a compilation of data to the - extent it is protected as a copyrightable work; or a work performed by - a variety or circus performer to the extent it is not otherwise - considered a literary or artistic work. - g. "You" means an individual or entity exercising rights under this - License who has not previously violated the terms of this License with - respect to the Work, or who has received express permission from the - Licensor to exercise rights under this License despite a previous - violation. - h. "Publicly Perform" means to perform public recitations of the Work and - to communicate to the public those public recitations, by any means or - process, including by wire or wireless means or public digital - performances; to make available to the public Works in such a way that - members of the public may access these Works from a place and at a - place individually chosen by them; to perform the Work to the public - by any means or process and the communication to the public of the - performances of the Work, including by public digital performance; to - broadcast and rebroadcast the Work by any means including signs, - sounds or images. - i. "Reproduce" means to make copies of the Work by any means including - without limitation by sound or visual recordings and the right of - fixation and reproducing fixations of the Work, including storage of a - protected performance or phonogram in digital form or other electronic - medium. - -2. Fair Dealing Rights. Nothing in this License is intended to reduce, -limit, or restrict any uses free from copyright or rights arising from -limitations or exceptions that are provided for in connection with the -copyright protection under copyright law or other applicable laws. - -3. License Grant. Subject to the terms and conditions of this License, -Licensor hereby grants You a worldwide, royalty-free, non-exclusive, -perpetual (for the duration of the applicable copyright) license to -exercise the rights in the Work as stated below: - - a. to Reproduce the Work, to incorporate the Work into one or more - Collections, and to Reproduce the Work as incorporated in the - Collections; - b. to create and Reproduce Adaptations provided that any such Adaptation, - including any translation in any medium, takes reasonable steps to - clearly label, demarcate or otherwise identify that changes were made - to the original Work. For example, a translation could be marked "The - original work was translated from English to Spanish," or a - modification could indicate "The original work has been modified."; - c. to Distribute and Publicly Perform the Work including as incorporated - in Collections; and, - d. to Distribute and Publicly Perform Adaptations. - e. For the avoidance of doubt: - - i. Non-waivable Compulsory License Schemes. In those jurisdictions in - which the right to collect royalties through any statutory or - compulsory licensing scheme cannot be waived, the Licensor - reserves the exclusive right to collect such royalties for any - exercise by You of the rights granted under this License; - ii. Waivable Compulsory License Schemes. In those jurisdictions in - which the right to collect royalties through any statutory or - compulsory licensing scheme can be waived, the Licensor waives the - exclusive right to collect such royalties for any exercise by You - of the rights granted under this License; and, - iii. Voluntary License Schemes. The Licensor waives the right to - collect royalties, whether individually or, in the event that the - Licensor is a member of a collecting society that administers - voluntary licensing schemes, via that society, from any exercise - by You of the rights granted under this License. - -The above rights may be exercised in all media and formats whether now -known or hereafter devised. The above rights include the right to make -such modifications as are technically necessary to exercise the rights in -other media and formats. Subject to Section 8(f), all rights not expressly -granted by Licensor are hereby reserved. - -4. Restrictions. The license granted in Section 3 above is expressly made -subject to and limited by the following restrictions: - - a. You may Distribute or Publicly Perform the Work only under the terms - of this License. You must include a copy of, or the Uniform Resource - Identifier (URI) for, this License with every copy of the Work You - Distribute or Publicly Perform. You may not offer or impose any terms - on the Work that restrict the terms of this License or the ability of - the recipient of the Work to exercise the rights granted to that - recipient under the terms of the License. You may not sublicense the - Work. You must keep intact all notices that refer to this License and - to the disclaimer of warranties with every copy of the Work You - Distribute or Publicly Perform. When You Distribute or Publicly - Perform the Work, You may not impose any effective technological - measures on the Work that restrict the ability of a recipient of the - Work from You to exercise the rights granted to that recipient under - the terms of the License. This Section 4(a) applies to the Work as - incorporated in a Collection, but this does not require the Collection - apart from the Work itself to be made subject to the terms of this - License. If You create a Collection, upon notice from any Licensor You - must, to the extent practicable, remove from the Collection any credit - as required by Section 4(b), as requested. If You create an - Adaptation, upon notice from any Licensor You must, to the extent - practicable, remove from the Adaptation any credit as required by - Section 4(b), as requested. - b. If You Distribute, or Publicly Perform the Work or any Adaptations or - Collections, You must, unless a request has been made pursuant to - Section 4(a), keep intact all copyright notices for the Work and - provide, reasonable to the medium or means You are utilizing: (i) the - name of the Original Author (or pseudonym, if applicable) if supplied, - and/or if the Original Author and/or Licensor designate another party - or parties (e.g., a sponsor institute, publishing entity, journal) for - attribution ("Attribution Parties") in Licensor's copyright notice, - terms of service or by other reasonable means, the name of such party - or parties; (ii) the title of the Work if supplied; (iii) to the - extent reasonably practicable, the URI, if any, that Licensor - specifies to be associated with the Work, unless such URI does not - refer to the copyright notice or licensing information for the Work; - and (iv) , consistent with Section 3(b), in the case of an Adaptation, - a credit identifying the use of the Work in the Adaptation (e.g., - "French translation of the Work by Original Author," or "Screenplay - based on original Work by Original Author"). The credit required by - this Section 4 (b) may be implemented in any reasonable manner; - provided, however, that in the case of a Adaptation or Collection, at - a minimum such credit will appear, if a credit for all contributing - authors of the Adaptation or Collection appears, then as part of these - credits and in a manner at least as prominent as the credits for the - other contributing authors. For the avoidance of doubt, You may only - use the credit required by this Section for the purpose of attribution - in the manner set out above and, by exercising Your rights under this - License, You may not implicitly or explicitly assert or imply any - connection with, sponsorship or endorsement by the Original Author, - Licensor and/or Attribution Parties, as appropriate, of You or Your - use of the Work, without the separate, express prior written - permission of the Original Author, Licensor and/or Attribution - Parties. - c. Except as otherwise agreed in writing by the Licensor or as may be - otherwise permitted by applicable law, if You Reproduce, Distribute or - Publicly Perform the Work either by itself or as part of any - Adaptations or Collections, You must not distort, mutilate, modify or - take other derogatory action in relation to the Work which would be - prejudicial to the Original Author's honor or reputation. Licensor - agrees that in those jurisdictions (e.g. Japan), in which any exercise - of the right granted in Section 3(b) of this License (the right to - make Adaptations) would be deemed to be a distortion, mutilation, - modification or other derogatory action prejudicial to the Original - Author's honor and reputation, the Licensor will waive or not assert, - as appropriate, this Section, to the fullest extent permitted by the - applicable national law, to enable You to reasonably exercise Your - right under Section 3(b) of this License (right to make Adaptations) - but not otherwise. - -5. Representations, Warranties and Disclaimer - -UNLESS OTHERWISE MUTUALLY AGREED TO BY THE PARTIES IN WRITING, LICENSOR -OFFERS THE WORK AS-IS AND MAKES NO REPRESENTATIONS OR WARRANTIES OF ANY -KIND CONCERNING THE WORK, EXPRESS, IMPLIED, STATUTORY OR OTHERWISE, -INCLUDING, WITHOUT LIMITATION, WARRANTIES OF TITLE, MERCHANTIBILITY, -FITNESS FOR A PARTICULAR PURPOSE, NONINFRINGEMENT, OR THE ABSENCE OF -LATENT OR OTHER DEFECTS, ACCURACY, OR THE PRESENCE OF ABSENCE OF ERRORS, -WHETHER OR NOT DISCOVERABLE. SOME JURISDICTIONS DO NOT ALLOW THE EXCLUSION -OF IMPLIED WARRANTIES, SO SUCH EXCLUSION MAY NOT APPLY TO YOU. - -6. Limitation on Liability. EXCEPT TO THE EXTENT REQUIRED BY APPLICABLE -LAW, IN NO EVENT WILL LICENSOR BE LIABLE TO YOU ON ANY LEGAL THEORY FOR -ANY SPECIAL, INCIDENTAL, CONSEQUENTIAL, PUNITIVE OR EXEMPLARY DAMAGES -ARISING OUT OF THIS LICENSE OR THE USE OF THE WORK, EVEN IF LICENSOR HAS -BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. - -7. Termination - - a. This License and the rights granted hereunder will terminate - automatically upon any breach by You of the terms of this License. - Individuals or entities who have received Adaptations or Collections - from You under this License, however, will not have their licenses - terminated provided such individuals or entities remain in full - compliance with those licenses. Sections 1, 2, 5, 6, 7, and 8 will - survive any termination of this License. - b. Subject to the above terms and conditions, the license granted here is - perpetual (for the duration of the applicable copyright in the Work). - Notwithstanding the above, Licensor reserves the right to release the - Work under different license terms or to stop distributing the Work at - any time; provided, however that any such election will not serve to - withdraw this License (or any other license that has been, or is - required to be, granted under the terms of this License), and this - License will continue in full force and effect unless terminated as - stated above. - -8. Miscellaneous - - a. Each time You Distribute or Publicly Perform the Work or a Collection, - the Licensor offers to the recipient a license to the Work on the same - terms and conditions as the license granted to You under this License. - b. Each time You Distribute or Publicly Perform an Adaptation, Licensor - offers to the recipient a license to the original Work on the same - terms and conditions as the license granted to You under this License. - c. If any provision of this License is invalid or unenforceable under - applicable law, it shall not affect the validity or enforceability of - the remainder of the terms of this License, and without further action - by the parties to this agreement, such provision shall be reformed to - the minimum extent necessary to make such provision valid and - enforceable. - d. No term or provision of this License shall be deemed waived and no - breach consented to unless such waiver or consent shall be in writing - and signed by the party to be charged with such waiver or consent. - e. This License constitutes the entire agreement between the parties with - respect to the Work licensed here. There are no understandings, - agreements or representations with respect to the Work not specified - here. Licensor shall not be bound by any additional provisions that - may appear in any communication from You. This License may not be - modified without the mutual written agreement of the Licensor and You. - f. The rights granted under, and the subject matter referenced, in this - License were drafted utilizing the terminology of the Berne Convention - for the Protection of Literary and Artistic Works (as amended on - September 28, 1979), the Rome Convention of 1961, the WIPO Copyright - Treaty of 1996, the WIPO Performances and Phonograms Treaty of 1996 - and the Universal Copyright Convention (as revised on July 24, 1971). - These rights and subject matter take effect in the relevant - jurisdiction in which the License terms are sought to be enforced - according to the corresponding provisions of the implementation of - those treaty provisions in the applicable national law. If the - standard suite of rights granted under applicable copyright law - includes additional rights not granted under this License, such - additional rights are deemed to be included in the License; this - License is not intended to restrict the license of any rights under - applicable law. - - -Creative Commons Notice - - Creative Commons is not a party to this License, and makes no warranty - whatsoever in connection with the Work. Creative Commons will not be - liable to You or any party on any legal theory for any damages - whatsoever, including without limitation any general, special, - incidental or consequential damages arising in connection to this - license. Notwithstanding the foregoing two (2) sentences, if Creative - Commons has expressly identified itself as the Licensor hereunder, it - shall have all rights and obligations of Licensor. - - Except for the limited purpose of indicating to the public that the - Work is licensed under the CCPL, Creative Commons does not authorize - the use by either party of the trademark "Creative Commons" or any - related trademark or logo of Creative Commons without the prior - written consent of Creative Commons. Any permitted use will be in - compliance with Creative Commons' then-current trademark usage - guidelines, as may be published on its website or otherwise made - available upon request from time to time. For the avoidance of doubt, - this trademark restriction does not form part of this License. - - Creative Commons may be contacted at https://creativecommons.org/. diff --git a/README.md b/README.md index f335062..2eafb48 100644 --- a/README.md +++ b/README.md @@ -10,13 +10,13 @@ stories. If you are making a contribution for the first time or from a new email, please add yourself to the `.mailmap`. -### Signoff +### Contributor License Agreement To include your code, we ask that you read and agree to the [CLA](./CLA.md). To -sign, add a `CLA-Version: 1.0` and a `Signed-off-by` trailer to every commit -(`git commit -s --trailer "CLA-Version: 1.0"`). Each commit in a pull request -must carry a valid `Signed-off-by` line matching the commit author. Please use -your real name. We cannot include code from anonymous contributors. +sign, add a `Signed-off-by` trailer to every commit (`git commit -s`). Each +commit in a pull request must carry a valid `Signed-off-by` line matching the +commit author. Please use your real name or your public nickname. We cannot +include code from anonymous contributors. AI agents MUST NOT add Signed-off-by tags. Only humans can legally certify the Contributor License Agreement. @@ -36,8 +36,8 @@ Remember, AI agents should make software better, not worse. ## Licensing -Hule source code is licensed under Apache-2.0. Documentation is licensed under -CC-BY-4.0. +Hule source code is licensed under the Apache License 2.0. Documentation is +licensed under CC BY 4.0. The image-generation scripts in `images/*/genimg` are derived from code originally published by Drew DeVault as part of [SourceHut](https://sr.ht) and diff --git a/REUSE.toml b/REUSE.toml index 9ad56a8..5c2aeed 100644 --- a/REUSE.toml +++ b/REUSE.toml @@ -1,4 +1,4 @@ -# SPDX-FileCopyrightText: 2026 Nikolay Govorov +# SPDX-FileCopyrightText: 2026 Nikolay Govorov # SPDX-License-Identifier: Apache-2.0 version = 1 @@ -7,7 +7,6 @@ version = 1 path = [ "Cargo.toml", "Cargo.lock", - "mise.lock", ] SPDX-FileCopyrightText = "2026 Nikolay Govorov" SPDX-License-Identifier = "Apache-2.0" @@ -15,16 +14,10 @@ SPDX-License-Identifier = "Apache-2.0" [[annotations]] path = [ ".mailmap", -] -SPDX-FileCopyrightText = "2026 Nikolay Govorov" -SPDX-License-Identifier = "Apache-2.0" - -[[annotations]] -path = [ "CLA.md", ] SPDX-FileCopyrightText = "2026 Nikolay Govorov" -SPDX-License-Identifier = "CC-BY-3.0" +SPDX-License-Identifier = "Apache-2.0" [[annotations]] path = [ diff --git a/crates/hule-hmi/Cargo.toml b/crates/hule-hmi/Cargo.toml index e315d00..d2b03e7 100644 --- a/crates/hule-hmi/Cargo.toml +++ b/crates/hule-hmi/Cargo.toml @@ -1,4 +1,4 @@ -# SPDX-FileCopyrightText: 2026 Nikolay Govorov +# SPDX-FileCopyrightText: 2026 Nikolay Govorov # SPDX-License-Identifier: Apache-2.0 [package] diff --git a/crates/hule-hmi/src/lib.rs b/crates/hule-hmi/src/lib.rs index dd78afc..6165294 100644 --- a/crates/hule-hmi/src/lib.rs +++ b/crates/hule-hmi/src/lib.rs @@ -1,4 +1,4 @@ -// SPDX-FileCopyrightText: 2026 Nikolay Govorov +// SPDX-FileCopyrightText: 2026 Nikolay Govorov // SPDX-License-Identifier: Apache-2.0 //! Types and validation for a Hule machine image `config.json`. diff --git a/crates/hule-oci/Cargo.toml b/crates/hule-oci/Cargo.toml index 6b05ea5..9fa92a9 100644 --- a/crates/hule-oci/Cargo.toml +++ b/crates/hule-oci/Cargo.toml @@ -1,4 +1,4 @@ -# SPDX-FileCopyrightText: 2026 Nikolay Govorov +# SPDX-FileCopyrightText: 2026 Nikolay Govorov # SPDX-License-Identifier: Apache-2.0 [package] @@ -15,7 +15,6 @@ repository.workspace = true [dependencies] hule-hmi.workspace = true serde_json.workspace = true -tokio = { workspace = true, features = ["fs", "io-util", "rt"] } oci-client = "0.17" zstd = "0.13" sha2 = "0.10" diff --git a/crates/hule-oci/src/error.rs b/crates/hule-oci/src/error.rs deleted file mode 100644 --- a/crates/hule-oci/src/error.rs +++ /dev/null @@ -1,119 +0,0 @@ -// SPDX-FileCopyrightText: 2026 Nikolay Govorov -// SPDX-License-Identifier: Apache-2.0 - -use oci_client::errors::OciDistributionError; -use std::fmt; -use std::path::PathBuf; - -#[derive(Debug)] -pub enum Error { - Io(std::io::Error), - Json(serde_json::Error), - InvalidImage(hule_hmi::ParseError), - InvalidReference { - reference: String, - source: oci_client::ParseError, - }, - Registry(OciDistributionError), - Task(tokio::task::JoinError), - InvalidImagePath(PathBuf), - MissingConfig(PathBuf), - ImageNotFound(String), - MissingManifest, - InvalidLayer(&'static str), - InvalidAnnotation { - name: &'static str, - value: String, - }, - EmptyImageFile(PathBuf), - InvalidStoragePath { - kind: &'static str, - value: String, - }, -} - -impl fmt::Display for Error { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - match self { - Self::Io(error) => error.fmt(f), - Self::Json(error) => error.fmt(f), - Self::InvalidImage(error) => error.fmt(f), - Self::InvalidReference { reference, source } => { - write!(f, "invalid reference '{reference}': {source}") - } - Self::Registry(error) => error.fmt(f), - Self::Task(error) => write!(f, "background task failed: {error}"), - Self::InvalidImagePath(path) => { - write!(f, "{} has no file name", path.display()) - } - Self::MissingConfig(path) => { - write!(f, "{} does not contain config.json", path.display()) - } - Self::ImageNotFound(reference) => { - write!(f, "no local image tagged '{reference}'") - } - Self::MissingManifest => f.write_str("registry returned no image manifest"), - Self::InvalidLayer(reason) => write!(f, "invalid chunk layer: {reason}"), - Self::InvalidAnnotation { name, value } => { - write!(f, "invalid chunk {name} annotation '{value}'") - } - Self::EmptyImageFile(path) => write!(f, "{} is empty", path.display()), - Self::InvalidStoragePath { kind, value } => { - write!(f, "invalid {kind} '{value}'") - } - } - } -} - -impl std::error::Error for Error { - fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { - match self { - Self::Io(error) => Some(error), - Self::Json(error) => Some(error), - Self::InvalidImage(error) => Some(error), - Self::InvalidReference { source, .. } => Some(source), - Self::Registry(error) => Some(error), - Self::Task(error) => Some(error), - Self::InvalidImagePath(_) - | Self::MissingConfig(_) - | Self::ImageNotFound(_) - | Self::MissingManifest - | Self::InvalidLayer(_) - | Self::InvalidAnnotation { .. } - | Self::EmptyImageFile(_) - | Self::InvalidStoragePath { .. } => None, - } - } -} - -impl From<std::io::Error> for Error { - fn from(error: std::io::Error) -> Self { - Self::Io(error) - } -} - -impl From<serde_json::Error> for Error { - fn from(error: serde_json::Error) -> Self { - Self::Json(error) - } -} - -impl From<hule_hmi::ParseError> for Error { - fn from(error: hule_hmi::ParseError) -> Self { - Self::InvalidImage(error) - } -} - -impl From<OciDistributionError> for Error { - fn from(error: OciDistributionError) -> Self { - Self::Registry(error) - } -} - -impl From<tokio::task::JoinError> for Error { - fn from(error: tokio::task::JoinError) -> Self { - Self::Task(error) - } -} - -pub type Result<T> = std::result::Result<T, Error>; diff --git a/crates/hule-oci/src/lib.rs b/crates/hule-oci/src/lib.rs index 819e05b..e53615b 100644 --- a/crates/hule-oci/src/lib.rs +++ b/crates/hule-oci/src/lib.rs @@ -1,11 +1,8 @@ -// SPDX-FileCopyrightText: 2026 Nikolay Govorov +// SPDX-FileCopyrightText: 2026 Nikolay Govorov // SPDX-License-Identifier: Apache-2.0 //! OCI image storage and registry operations for Hule machine images. -mod error; -mod storage; - use hule_hmi::MachineImage; use oci_client::annotations::{ORG_OPENCONTAINERS_IMAGE_REF_NAME, ORG_OPENCONTAINERS_IMAGE_TITLE}; use oci_client::client::{ClientConfig, ClientProtocol, Config, ImageLayer}; @@ -15,14 +12,9 @@ use oci_client::manifest::{ use oci_client::secrets::RegistryAuth; use oci_client::{Client, Reference}; use std::collections::{BTreeMap, BTreeSet}; +use std::io::Read; use std::path::{Path, PathBuf}; -use tokio::fs::{self, File}; -use tokio::io::AsyncReadExt; -use tokio::task; - -pub use error::{Error, Result}; -pub use storage::Storage; - +pub type Result<T> = std::result::Result<T, String>; type R<T> = Result<T>; // ---- local OCI-layout store ------------------------------------------- @@ -33,6 +25,82 @@ const HULE_CONFIG_MEDIA_TYPE: &str = "application/vnd.hule.machine.config.v1+jso const ANNOTATION_CHUNK_OFFSET: &str = "io.hule.chunk.offset"; const ANNOTATION_CHUNK_LENGTH: &str = "io.hule.chunk.length"; +fn store_root() -> R<PathBuf> { + let home = std::env::var("HOME").map_err(|_| "HOME is not set".to_string())?; + Ok(PathBuf::from(home).join(".hule").join("store")) +} + +fn blobs_dir() -> R<PathBuf> { + Ok(store_root()?.join("blobs").join("sha256")) +} + +fn materialized_dir(manifest_digest: &str) -> R<PathBuf> { + Ok(store_root()? + .join("materialized") + .join(strip_sha256(manifest_digest))) +} + +fn index_path() -> R<PathBuf> { + Ok(store_root()?.join("index.json")) +} + +fn strip_sha256(digest: &str) -> &str { + digest.strip_prefix("sha256:").unwrap_or(digest) +} + +fn sha256_hex(data: &[u8]) -> String { + use sha2::{Digest, Sha256}; + let mut hasher = Sha256::new(); + hasher.update(data); + format!("sha256:{:x}", hasher.finalize()) +} + +fn ensure_store() -> R<()> { + std::fs::create_dir_all(blobs_dir()?).map_err(|e| e.to_string())?; + std::fs::create_dir_all(store_root()?.join("materialized")).map_err(|e| e.to_string())?; + let layout = store_root()?.join("oci-layout"); + if !layout.exists() { + std::fs::write(&layout, br#"{"imageLayoutVersion":"1.0.0"}"#).map_err(|e| e.to_string())?; + } + Ok(()) +} + +/// Writes raw bytes as a content-addressed blob, no-op if already present. +fn write_blob(data: &[u8]) -> R<String> { + let digest = sha256_hex(data); + let path = blobs_dir()?.join(strip_sha256(&digest)); + if !path.exists() { + let tmp = path.with_extension("tmp"); + std::fs::write(&tmp, data).map_err(|e| e.to_string())?; + std::fs::rename(&tmp, &path).map_err(|e| e.to_string())?; + } + Ok(digest) +} + +fn read_blob(digest: &str) -> R<Vec<u8>> { + std::fs::read(blobs_dir()?.join(strip_sha256(digest))).map_err(|e| e.to_string()) +} + +fn read_index() -> R<OciImageIndex> { + let path = index_path()?; + if !path.exists() { + return Ok(OciImageIndex { + schema_version: 2, + media_type: None, + manifests: vec![], + artifact_type: None, + annotations: None, + }); + } + let data = std::fs::read(&path).map_err(|e| e.to_string())?; + serde_json::from_slice(&data).map_err(|e| e.to_string()) +} + +fn write_index(index: &OciImageIndex) -> R<()> { + let data = serde_json::to_vec_pretty(index).map_err(|e| e.to_string())?; + std::fs::write(index_path()?, data).map_err(|e| e.to_string()) +} + fn index_lookup(index: &OciImageIndex, reference: &str) -> Option<String> { index .manifests @@ -70,71 +138,79 @@ fn index_set(index: &mut OciImageIndex, reference: &str, digest: &str, size: u64 }); } -/// Manages Hule images backed by a [`Storage`]. -#[derive(Clone, Debug)] -pub struct ImageManager { - storage: Storage, -} - -impl ImageManager { - pub fn new(storage: Storage) -> Self { - Self { storage } +fn hardlink_or_copy(src: &Path, dest: &Path) -> R<()> { + if std::fs::hard_link(src, dest).is_err() { + std::fs::copy(src, dest).map_err(|e| e.to_string())?; } + Ok(()) +} - pub fn storage(&self) -> &Storage { - &self.storage +fn write_at(file: &std::fs::File, offset: u64, data: &[u8]) -> R<()> { + use std::os::unix::fs::FileExt; + let mut written = 0usize; + while written < data.len() { + let n = file + .write_at(&data[written..], offset + written as u64) + .map_err(|e| e.to_string())?; + if n == 0 { + return Err("write_at wrote 0 bytes".to_string()); + } + written += n; } + Ok(()) +} - /// Splits `path` into fixed-size chunks, compresses each independently - /// and writes each as its own blob. - async fn write_file_chunks(&self, path: &Path) -> R<Vec<OciDescriptor>> { - let title = path - .file_name() - .ok_or_else(|| Error::InvalidImagePath(path.to_path_buf()))? - .to_string_lossy() - .to_string(); - let mut file = File::open(path).await?; - let mut descriptors = Vec::new(); - let mut offset: u64 = 0; - loop { - let mut buf = Vec::with_capacity(CHUNK_SIZE); - (&mut file) - .take(CHUNK_SIZE as u64) - .read_to_end(&mut buf) - .await?; - if buf.is_empty() { - break; - } - let length = buf.len() as u64; - let compressed = - task::spawn_blocking(move || zstd::stream::encode_all(&buf[..], 0)).await??; - let compressed_len = compressed.len(); - let (digest, _) = self.storage.write_blob(compressed).await?; - - let mut annotations = BTreeMap::new(); - annotations.insert(ORG_OPENCONTAINERS_IMAGE_TITLE.to_string(), title.clone()); - annotations.insert(ANNOTATION_CHUNK_OFFSET.to_string(), offset.to_string()); - annotations.insert(ANNOTATION_CHUNK_LENGTH.to_string(), length.to_string()); - - descriptors.push(OciDescriptor { - media_type: HULE_CHUNK_MEDIA_TYPE.to_string(), - digest, - size: compressed_len as i64, - urls: None, - annotations: Some(annotations), - artifact_type: None, - }); - - offset += length; - if length < CHUNK_SIZE as u64 { - break; - } +/// Splits `path` into fixed-size chunks, compresses each independently +/// (own zstd frame, no state shared between chunks -- see the design notes +/// in the project plan on why this must not be done the other way around), +/// and writes each as its own blob. Returns one descriptor per chunk, all +/// sharing a title annotation plus a chunk offset/length in terms of the +/// *uncompressed* file so pull can reassemble it. +fn write_file_chunks(path: &Path) -> R<Vec<OciDescriptor>> { + let title = path + .file_name() + .ok_or_else(|| format!("{} has no file name", path.display()))? + .to_string_lossy() + .to_string(); + let mut file = std::fs::File::open(path).map_err(|e| e.to_string())?; + let mut descriptors = Vec::new(); + let mut offset: u64 = 0; + loop { + let mut buf = Vec::with_capacity(CHUNK_SIZE); + (&mut file) + .take(CHUNK_SIZE as u64) + .read_to_end(&mut buf) + .map_err(|e| e.to_string())?; + if buf.is_empty() { + break; } - if descriptors.is_empty() { - return Err(Error::EmptyImageFile(path.to_path_buf())); + let length = buf.len() as u64; + let compressed = zstd::stream::encode_all(&buf[..], 0).map_err(|e| e.to_string())?; + let digest = write_blob(&compressed)?; + + let mut annotations = BTreeMap::new(); + annotations.insert(ORG_OPENCONTAINERS_IMAGE_TITLE.to_string(), title.clone()); + annotations.insert(ANNOTATION_CHUNK_OFFSET.to_string(), offset.to_string()); + annotations.insert(ANNOTATION_CHUNK_LENGTH.to_string(), length.to_string()); + + descriptors.push(OciDescriptor { + media_type: HULE_CHUNK_MEDIA_TYPE.to_string(), + digest, + size: compressed.len() as i64, + urls: None, + annotations: Some(annotations), + artifact_type: None, + }); + + offset += length; + if length < CHUNK_SIZE as u64 { + break; } - Ok(descriptors) } + if descriptors.is_empty() { + return Err(format!("{} is empty", path.display())); + } + Ok(descriptors) } fn make_client(reference: &Reference) -> Client { @@ -152,335 +228,232 @@ fn make_client(reference: &Reference) -> Client { } fn parse_reference(s: &str) -> R<Reference> { - s.parse().map_err(|source| Error::InvalidReference { - reference: s.to_string(), - source, - }) + s.parse() + .map_err(|e| format!("invalid reference '{s}': {e}")) } -// ---- image operations ------------------------------------------------- - -impl ImageManager { - /// Loads a prepared HMI image directory and optionally tags it. - pub async fn load(&self, path: &Path, reference: Option<&str>) -> R<String> { - let config_path = path.join("config.json"); - match fs::metadata(&config_path).await { - Ok(metadata) if metadata.is_file() => {} - Ok(_) => return Err(Error::MissingConfig(path.to_path_buf())), - Err(error) if error.kind() == std::io::ErrorKind::NotFound => { - return Err(Error::MissingConfig(path.to_path_buf())); - } - Err(error) => return Err(error.into()), - } - let config_bytes = fs::read(&config_path).await?; - MachineImage::from_json(&config_bytes)?; - - let mut dir = fs::read_dir(path).await?; - let mut entries = Vec::new(); - while let Some(entry) = dir.next_entry().await? { - entries.push(entry); - } - entries.sort_by_key(|entry| entry.file_name()); - - let mut layers = Vec::new(); - let mut sources: Vec<(String, PathBuf)> = Vec::new(); - for entry in entries { - if !entry.file_type().await?.is_file() { - continue; - } - let name = entry.file_name().to_string_lossy().to_string(); - if name == "config.json" { - continue; - } - let file_path = entry.path(); - layers.extend(self.write_file_chunks(&file_path).await?); - sources.push((name, file_path)); - } +// ---- import / push / pull / run --------------------------------------- - let config_size = config_bytes.len(); - let (config_digest, _) = self.storage.write_blob(config_bytes).await?; - let config = OciDescriptor { - media_type: HULE_CONFIG_MEDIA_TYPE.to_string(), - digest: config_digest, - size: config_size as i64, - urls: None, - annotations: None, - artifact_type: None, - }; - - let manifest = OciImageManifest { - schema_version: 2, - media_type: Some(OCI_IMAGE_MEDIA_TYPE.to_string()), - config, - layers, - subject: None, - artifact_type: None, - annotations: None, - }; - let manifest_bytes = serde_json::to_vec(&manifest)?; - let manifest_size = manifest_bytes.len(); - let (manifest_digest, _) = self.storage.write_blob(manifest_bytes).await?; - - self.storage.ensure_hmi_image(&manifest_digest).await?; - for (title, source) in &sources { - self.storage - .cache_hmi_file(&manifest_digest, title, source) - .await?; - } - - if let Some(reference) = reference { - let mut index = self.storage.read_index().await?; - index_set( - &mut index, - reference, - &manifest_digest, - manifest_size as u64, - ); - self.storage.write_index(&index).await?; - } - Ok(manifest_digest) +/// Imports an image directory into the local OCI layout and optionally tags it. +pub async fn import(path: &Path, reference: Option<&str>) -> R<String> { + ensure_store()?; + let config_path = path.join("config.json"); + if !config_path.is_file() { + return Err(format!("{} does not contain config.json", path.display())); } - - /// Pushes a locally tagged image to its registry reference. - pub async fn push(&self, reference_str: &str) -> R<()> { - let index = self.storage.read_index().await?; - let manifest_digest = index_lookup(&index, reference_str) - .ok_or_else(|| Error::ImageNotFound(reference_str.to_string()))?; - let manifest_bytes = self.storage.read_blob(&manifest_digest).await?; - let manifest: OciImageManifest = serde_json::from_slice(&manifest_bytes)?; - - let reference = parse_reference(reference_str)?; - let client = make_client(&reference); - let auth = RegistryAuth::Anonymous; - - let mut layers = Vec::new(); - for descriptor in &manifest.layers { - let data = self.storage.read_blob(&descriptor.digest).await?; - layers.push(ImageLayer::new( - data, - descriptor.media_type.clone(), - descriptor.annotations.clone(), - )); + let config_bytes = std::fs::read(&config_path).map_err(|e| e.to_string())?; + MachineImage::from_json(&config_bytes).map_err(|e| e.to_string())?; + + let mut entries: Vec<_> = std::fs::read_dir(path) + .map_err(|e| e.to_string())? + .collect::<std::result::Result<Vec<_>, _>>() + .map_err(|e| e.to_string())?; + entries.sort_by_key(|e| e.file_name()); + + let mut layers = Vec::new(); + let mut sources: Vec<(String, PathBuf)> = Vec::new(); + for entry in entries { + if !entry.file_type().map_err(|e| e.to_string())?.is_file() { + continue; } - let config_bytes = self.storage.read_blob(&manifest.config.digest).await?; - let config = Config::new( - config_bytes, - manifest.config.media_type.clone(), - manifest.config.annotations.clone(), - ); - - client - .push(&reference, &layers, config, &auth, Some(manifest)) - .await?; - - Ok(()) + let name = entry.file_name().to_string_lossy().to_string(); + if name == "config.json" { + continue; + } + let file_path = entry.path(); + layers.extend(write_file_chunks(&file_path)?); + sources.push((name, file_path)); } - /// Pulls an image into the OCI layout and materializes it in the HMI store. - pub async fn pull(&self, reference_str: &str) -> R<String> { - let reference = parse_reference(reference_str)?; - let client = make_client(&reference); - let auth = RegistryAuth::Anonymous; - - let mut image_data = client - .pull(&reference, &auth, vec![HULE_CHUNK_MEDIA_TYPE]) - .await?; - let manifest = image_data.manifest.ok_or(Error::MissingManifest)?; - - // `client.pull()` fetches layers via `buffer_unordered`, so `image_data.layers` is - // in completion order, not manifest order. Each layer carries its own annotations. - for layer in &mut image_data.layers { - let data = std::mem::take(&mut layer.data); - let (_, data) = self.storage.write_blob(data).await?; - layer.data = data; - } - let config_data = std::mem::take(&mut image_data.config.data); - let (_, config_data) = self.storage.write_blob(config_data).await?; - image_data.config.data = config_data; - - let manifest_bytes = serde_json::to_vec(&manifest)?; - let manifest_size = manifest_bytes.len(); - let (manifest_digest, _) = self.storage.write_blob(manifest_bytes).await?; - self.storage.ensure_hmi_image(&manifest_digest).await?; - - let mut by_title: BTreeMap<String, Vec<(u64, ImageLayer)>> = BTreeMap::new(); - for layer in image_data.layers { - let annotations = layer - .annotations - .as_ref() - .ok_or(Error::InvalidLayer("missing annotations"))?; - let title = annotations - .get(ORG_OPENCONTAINERS_IMAGE_TITLE) - .ok_or(Error::InvalidLayer("missing title annotation"))?; - let offset_value = annotations - .get(ANNOTATION_CHUNK_OFFSET) - .ok_or(Error::InvalidLayer("missing offset annotation"))?; - let offset: u64 = offset_value.parse().map_err(|_| Error::InvalidAnnotation { - name: "offset", - value: offset_value.clone(), - })?; - by_title - .entry(title.clone()) - .or_default() - .push((offset, layer)); - } + let config_digest = write_blob(&config_bytes)?; + let config = OciDescriptor { + media_type: HULE_CONFIG_MEDIA_TYPE.to_string(), + digest: config_digest, + size: config_bytes.len() as i64, + urls: None, + annotations: None, + artifact_type: None, + }; - for (title, chunks) in by_title { - let mut decompressed_chunks = Vec::with_capacity(chunks.len()); - for (offset, layer) in chunks { - let data = task::spawn_blocking(move || zstd::stream::decode_all(&layer.data[..])) - .await??; - decompressed_chunks.push((offset, data)); - } - self.storage - .write_hmi_file(&manifest_digest, &title, decompressed_chunks) - .await?; + let manifest = OciImageManifest { + schema_version: 2, + media_type: Some(OCI_IMAGE_MEDIA_TYPE.to_string()), + config, + layers, + subject: None, + artifact_type: None, + annotations: None, + }; + let manifest_bytes = serde_json::to_vec(&manifest).map_err(|e| e.to_string())?; + let manifest_digest = write_blob(&manifest_bytes)?; + + let materialized = materialized_dir(&manifest_digest)?; + std::fs::create_dir_all(&materialized).map_err(|e| e.to_string())?; + for (title, source) in &sources { + let dest = materialized.join(title); + if !dest.exists() { + hardlink_or_copy(source, &dest)?; } + } - let mut index = self.storage.read_index().await?; + if let Some(reference) = reference { + let mut index = read_index()?; index_set( &mut index, - reference_str, + reference, &manifest_digest, - manifest_size as u64, + manifest_bytes.len() as u64, ); - self.storage.write_index(&index).await?; + write_index(&index)?; + } + Ok(manifest_digest) +} - Ok(manifest_digest) +/// Pushes a locally tagged image to its registry reference. +pub async fn push(reference_str: &str) -> R<()> { + ensure_store()?; + let index = read_index()?; + let manifest_digest = index_lookup(&index, reference_str) + .ok_or_else(|| format!("no local image tagged '{reference_str}'"))?; + let manifest_bytes = read_blob(&manifest_digest)?; + let manifest: OciImageManifest = + serde_json::from_slice(&manifest_bytes).map_err(|e| e.to_string())?; + + let reference = parse_reference(reference_str)?; + let client = make_client(&reference); + let auth = RegistryAuth::Anonymous; + + let mut layers = Vec::new(); + for descriptor in &manifest.layers { + let data = read_blob(&descriptor.digest)?; + layers.push(ImageLayer::new( + data, + descriptor.media_type.clone(), + descriptor.annotations.clone(), + )); } + let config_bytes = read_blob(&manifest.config.digest)?; + let config = Config::new( + config_bytes, + manifest.config.media_type.clone(), + manifest.config.annotations.clone(), + ); + + client + .push(&reference, &layers, config, &auth, Some(manifest)) + .await + .map_err(|e| e.to_string())?; - /// Returns whether a reference is present in the local OCI layout. - pub async fn contains(&self, reference_str: &str) -> R<bool> { - Ok(index_lookup(&self.storage.read_index().await?, reference_str).is_some()) + Ok(()) +} + +/// Pulls an image into the local OCI layout and materializes its files. +pub async fn pull(reference_str: &str) -> R<String> { + ensure_store()?; + let reference = parse_reference(reference_str)?; + let client = make_client(&reference); + let auth = RegistryAuth::Anonymous; + + let image_data = client + .pull(&reference, &auth, vec![HULE_CHUNK_MEDIA_TYPE]) + .await + .map_err(|e| e.to_string())?; + let manifest = image_data + .manifest + .ok_or("registry returned no image manifest")?; + + // `client.pull()` fetches layers via `buffer_unordered`, so `image_data.layers` is in + // completion order, NOT `manifest.layers` order -- do not zip the two. Each `ImageLayer` + // already carries its own annotations, so it's self-describing without cross-referencing. + for layer in &image_data.layers { + write_blob(&layer.data)?; } + write_blob(&image_data.config.data)?; - /// Materializes a locally tagged image into `destination` and returns config.json. - pub async fn materialize(&self, reference_str: &str, destination: &Path) -> R<Vec<u8>> { - let manifest_digest = index_lookup(&self.storage.read_index().await?, reference_str) - .ok_or_else(|| Error::ImageNotFound(reference_str.to_string()))?; + let manifest_bytes = serde_json::to_vec(&manifest).map_err(|e| e.to_string())?; + let manifest_digest = write_blob(&manifest_bytes)?; - let manifest_bytes = self.storage.read_blob(&manifest_digest).await?; - let manifest: OciImageManifest = serde_json::from_slice(&manifest_bytes)?; - let config_bytes = self.storage.read_blob(&manifest.config.digest).await?; + let materialized = materialized_dir(&manifest_digest)?; + std::fs::create_dir_all(&materialized).map_err(|e| e.to_string())?; - fs::create_dir_all(destination).await?; - fs::write(destination.join("config.json"), &config_bytes).await?; + let mut by_title: BTreeMap<String, Vec<(u64, &[u8])>> = BTreeMap::new(); + for layer in &image_data.layers { + let annotations = layer + .annotations + .as_ref() + .ok_or("chunk layer missing annotations")?; + let title = annotations + .get(ORG_OPENCONTAINERS_IMAGE_TITLE) + .ok_or("chunk layer missing title annotation")?; + let offset: u64 = annotations + .get(ANNOTATION_CHUNK_OFFSET) + .ok_or("chunk layer missing offset annotation")? + .parse() + .map_err(|_| "invalid chunk offset annotation".to_string())?; + by_title + .entry(title.clone()) + .or_default() + .push((offset, &layer.data[..])); + } - let mut titles: BTreeSet<String> = BTreeSet::new(); - for descriptor in &manifest.layers { - if let Some(title) = descriptor - .annotations - .as_ref() - .and_then(|annotations| annotations.get(ORG_OPENCONTAINERS_IMAGE_TITLE)) - { - titles.insert(title.clone()); - } - } - for title in titles { - self.storage - .export_hmi_file(&manifest_digest, &title, &destination.join(&title)) - .await?; + for (title, mut chunks) in by_title { + chunks.sort_by_key(|(offset, _)| *offset); + let file = std::fs::File::create(materialized.join(&title)).map_err(|e| e.to_string())?; + for (offset, compressed) in chunks { + let decompressed = zstd::stream::decode_all(compressed).map_err(|e| e.to_string())?; + write_at(&file, offset, &decompressed)?; } - - Ok(config_bytes) } + + let mut index = read_index()?; + index_set( + &mut index, + reference_str, + &manifest_digest, + manifest_bytes.len() as u64, + ); + write_index(&index)?; + + Ok(manifest_digest) } -#[cfg(test)] -mod tests { - use super::*; - use std::sync::atomic::{AtomicU64, Ordering}; - - const TEST_CONFIG: &[u8] = br#"{ - "schemaVersion": 1, - "kind": "MachineImage", - "system": { - "os": "linux", - "name": "test", - "version": "1", - "architecture": "amd64" - }, - "machine": { - "cpu": { "minimum": 1, "default": 1 }, - "ram": { "minimum": 268435456, "default": 268435456 }, - "boot": [{ "protocol": "firmware-disk/bios", "disk": "root" }], - "access": [{ - "type": "ssh", - "port": 22, - "user": "root", - "auth": "empty-password" - }], - "network": { "mode": "dhcp" } - }, - "disks": [{ - "id": "root", - "format": "qcow2", - "path": "root.hmi", - "digest": "sha256:372409142c91c51316a7ab2b055596e145de56d99aa0f5eb110068876cef0be4", - "virtSize": 14, - "diskSize": 14 - }] - }"#; - - fn temporary_directory() -> PathBuf { - static NEXT_ID: AtomicU64 = AtomicU64::new(0); - std::env::temp_dir().join(format!( - "hule-oci-test-{}-{}", - std::process::id(), - NEXT_ID.fetch_add(1, Ordering::Relaxed) - )) - } +/// Returns whether a reference is present in the local OCI layout. +pub fn contains(reference_str: &str) -> R<bool> { + ensure_store()?; + Ok(index_lookup(&read_index()?, reference_str).is_some()) +} - #[test] - fn manager_uses_separate_oci_and_hmi_roots() { - tokio::runtime::Builder::new_current_thread() - .build() - .unwrap() - .block_on(async { - let root = temporary_directory(); - let source = root.join("source"); - let oci_root = root.join("oci"); - let hmi_root = root.join("hmi"); - let destination = root.join("destination"); - fs::create_dir_all(&source).await.unwrap(); - fs::write(source.join("config.json"), TEST_CONFIG) - .await - .unwrap(); - fs::write(source.join("root.hmi"), b"test hmi image") - .await - .unwrap(); - - let storage = Storage::open(&oci_root, &hmi_root).await.unwrap(); - let images = ImageManager::new(storage); - let reference = "example.test/hule:tokio"; - let digest = images.load(&source, Some(reference)).await.unwrap(); - - assert!(images.contains(reference).await.unwrap()); - assert!(fs::try_exists(oci_root.join("index.json")).await.unwrap()); - assert!( - fs::try_exists( - hmi_root - .join(digest.strip_prefix("sha256:").unwrap_or(&digest)) - .join("root.hmi") - ) - .await - .unwrap() - ); - - let config = images.materialize(reference, &destination).await.unwrap(); - assert!(!config.is_empty()); - assert_eq!( - fs::read(destination.join("root.hmi")).await.unwrap(), - b"test hmi image" - ); - - assert!(matches!(images.contains("missing").await, Ok(false))); - assert!(matches!( - images.materialize("missing", &destination).await, - Err(Error::ImageNotFound(reference)) if reference == "missing" - )); - - fs::remove_dir_all(root).await.unwrap(); - }); +/// Materializes a locally tagged image into `destination` and returns config.json. +pub fn materialize(reference_str: &str, destination: &Path) -> R<Vec<u8>> { + ensure_store()?; + let manifest_digest = index_lookup(&read_index()?, reference_str) + .ok_or_else(|| format!("no local image tagged '{reference_str}'"))?; + + let manifest_bytes = read_blob(&manifest_digest)?; + let manifest: OciImageManifest = + serde_json::from_slice(&manifest_bytes).map_err(|e| e.to_string())?; + let config_bytes = read_blob(&manifest.config.digest)?; + + std::fs::create_dir_all(destination).map_err(|e| e.to_string())?; + std::fs::write(destination.join("config.json"), &config_bytes).map_err(|e| e.to_string())?; + + let materialized = materialized_dir(&manifest_digest)?; + let mut titles: BTreeSet<String> = BTreeSet::new(); + for descriptor in &manifest.layers { + if let Some(title) = descriptor + .annotations + .as_ref() + .and_then(|a| a.get(ORG_OPENCONTAINERS_IMAGE_TITLE)) + { + titles.insert(title.clone()); + } } + for title in titles { + let dest = destination.join(&title); + if !dest.exists() { + hardlink_or_copy(&materialized.join(&title), &dest)?; + } + } + + Ok(config_bytes) } diff --git a/crates/hule-oci/src/storage.rs b/crates/hule-oci/src/storage.rs deleted file mode 100644 --- a/crates/hule-oci/src/storage.rs +++ /dev/null @@ -1,213 +0,0 @@ -// SPDX-FileCopyrightText: 2026 Nikolay Govorov -// SPDX-License-Identifier: Apache-2.0 - -use crate::{Error, Result}; -use oci_client::manifest::OciImageIndex; -use std::io::SeekFrom; -use std::path::{Component, Path, PathBuf}; -use tokio::fs::{self, File}; -use tokio::io::{AsyncSeekExt, AsyncWriteExt}; -use tokio::task; - -/// Filesystem storage for OCI content and materialized HMI images. -/// -/// The roots are independent so callers can place content-addressed OCI data -/// and large materialized disks on different filesystems. -#[derive(Clone, Debug)] -pub struct Storage { - oci_root: PathBuf, - hmi_root: PathBuf, -} - -impl Storage { - /// Opens the storage and creates its filesystem layout when necessary. - pub async fn open(oci_root: impl Into<PathBuf>, hmi_root: impl Into<PathBuf>) -> Result<Self> { - let storage = Self { - oci_root: oci_root.into(), - hmi_root: hmi_root.into(), - }; - - fs::create_dir_all(&storage.hmi_root).await?; - fs::create_dir_all(storage.blobs_dir()).await?; - - let layout = storage.oci_root.join("oci-layout"); - if !fs::try_exists(&layout).await? { - fs::write(&layout, br#"{"imageLayoutVersion":"1.0.0"}"#).await?; - } - - Ok(storage) - } - - pub fn oci_root(&self) -> &Path { - &self.oci_root - } - - pub fn hmi_root(&self) -> &Path { - &self.hmi_root - } - - fn blobs_dir(&self) -> PathBuf { - self.oci_root.join("blobs").join("sha256") - } - - fn index_path(&self) -> PathBuf { - self.oci_root.join("index.json") - } - - fn hmi_image_dir(&self, manifest_digest: &str) -> Result<PathBuf> { - let digest = safe_component(strip_sha256(manifest_digest), "manifest digest")?; - Ok(self.hmi_root.join(digest)) - } - - fn hmi_file_path(&self, manifest_digest: &str, title: &str) -> Result<PathBuf> { - let title = safe_component(title, "image file name")?; - Ok(self.hmi_image_dir(manifest_digest)?.join(title)) - } - - fn blob_path(&self, digest: &str) -> Result<PathBuf> { - let digest = safe_component(strip_sha256(digest), "blob digest")?; - Ok(self.blobs_dir().join(digest)) - } - - pub(crate) async fn read_blob(&self, digest: &str) -> Result<Vec<u8>> { - Ok(fs::read(self.blob_path(digest)?).await?) - } - - /// Writes raw bytes as a content-addressed blob, no-op if already present. - pub(crate) async fn write_blob<T>(&self, data: T) -> Result<(String, T)> - where - T: AsRef<[u8]> + Send + Sync + 'static, - { - let (digest, data) = - task::spawn_blocking(move || (sha256_hex(data.as_ref()), data)).await?; - let path = self.blob_path(&digest)?; - if !fs::try_exists(&path).await? { - let tmp = path.with_extension("tmp"); - fs::write(&tmp, data.as_ref()).await?; - fs::rename(&tmp, &path).await?; - } - Ok((digest, data)) - } - - pub(crate) async fn read_index(&self) -> Result<OciImageIndex> { - let path = self.index_path(); - if !fs::try_exists(&path).await? { - return Ok(OciImageIndex { - schema_version: 2, - media_type: None, - manifests: vec![], - artifact_type: None, - annotations: None, - }); - } - let data = fs::read(&path).await?; - Ok(serde_json::from_slice(&data)?) - } - - pub(crate) async fn write_index(&self, index: &OciImageIndex) -> Result<()> { - let data = serde_json::to_vec_pretty(index)?; - fs::write(self.index_path(), data).await?; - Ok(()) - } - - pub(crate) async fn ensure_hmi_image(&self, manifest_digest: &str) -> Result<()> { - fs::create_dir_all(self.hmi_image_dir(manifest_digest)?).await?; - Ok(()) - } - - pub(crate) async fn cache_hmi_file( - &self, - manifest_digest: &str, - title: &str, - source: &Path, - ) -> Result<()> { - let destination = self.hmi_file_path(manifest_digest, title)?; - if !fs::try_exists(&destination).await? { - Self::hardlink_or_copy(source, &destination).await?; - } - Ok(()) - } - - pub(crate) async fn write_hmi_file( - &self, - manifest_digest: &str, - title: &str, - mut chunks: Vec<(u64, Vec<u8>)>, - ) -> Result<()> { - chunks.sort_by_key(|(offset, _)| *offset); - let mut file = File::create(self.hmi_file_path(manifest_digest, title)?).await?; - for (offset, data) in chunks { - file.seek(SeekFrom::Start(offset)).await?; - file.write_all(&data).await?; - } - file.flush().await?; - Ok(()) - } - - pub(crate) async fn export_hmi_file( - &self, - manifest_digest: &str, - title: &str, - destination: &Path, - ) -> Result<()> { - let source = self.hmi_file_path(manifest_digest, title)?; - if !fs::try_exists(destination).await? { - Self::hardlink_or_copy(&source, destination).await?; - } - Ok(()) - } - - async fn hardlink_or_copy(source: &Path, destination: &Path) -> Result<()> { - if fs::hard_link(source, destination).await.is_err() { - fs::copy(source, destination).await?; - } - Ok(()) - } -} - -fn safe_component<'a>(value: &'a str, kind: &'static str) -> Result<&'a str> { - let mut components = Path::new(value).components(); - match (components.next(), components.next()) { - (Some(Component::Normal(_)), None) => Ok(value), - _ => Err(Error::InvalidStoragePath { - kind, - value: value.to_string(), - }), - } -} - -fn strip_sha256(digest: &str) -> &str { - digest.strip_prefix("sha256:").unwrap_or(digest) -} - -fn sha256_hex(data: &[u8]) -> String { - use sha2::{Digest, Sha256}; - let mut hasher = Sha256::new(); - hasher.update(data); - format!("sha256:{:x}", hasher.finalize()) -} - -#[cfg(test)] -mod tests { - use super::*; - - #[test] - fn paths_cannot_escape_storage_roots() { - let storage = Storage { - oci_root: "oci".into(), - hmi_root: "hmi".into(), - }; - assert!(matches!( - storage.blob_path("sha256:../../outside"), - Err(Error::InvalidStoragePath { .. }) - )); - assert!(matches!( - storage.hmi_image_dir("sha256:../outside"), - Err(Error::InvalidStoragePath { .. }) - )); - assert!(matches!( - storage.hmi_file_path("sha256:digest", "../outside"), - Err(Error::InvalidStoragePath { .. }) - )); - } -} diff --git a/crates/hule-vmm/Cargo.toml b/crates/hule-vmm/Cargo.toml index 50170c9..fc56926 100644 --- a/crates/hule-vmm/Cargo.toml +++ b/crates/hule-vmm/Cargo.toml @@ -1,4 +1,4 @@ -# SPDX-FileCopyrightText: 2026 Nikolay Govorov +# SPDX-FileCopyrightText: 2026 Nikolay Govorov # SPDX-License-Identifier: Apache-2.0 [package] diff --git a/crates/hule-vmm/src/backend/mod.rs b/crates/hule-vmm/src/backend/mod.rs index 1109b59..e4e1984 100644 --- a/crates/hule-vmm/src/backend/mod.rs +++ b/crates/hule-vmm/src/backend/mod.rs @@ -1,4 +1,4 @@ -// SPDX-FileCopyrightText: 2026 Nikolay Govorov +// SPDX-FileCopyrightText: 2026 Nikolay Govorov // SPDX-License-Identifier: Apache-2.0 pub mod qemu; diff --git a/crates/hule-vmm/src/backend/qemu/cli.rs b/crates/hule-vmm/src/backend/qemu/cli.rs index 68d7260..5c3e7b9 100644 --- a/crates/hule-vmm/src/backend/qemu/cli.rs +++ b/crates/hule-vmm/src/backend/qemu/cli.rs @@ -1,4 +1,4 @@ -// SPDX-FileCopyrightText: 2026 Nikolay Govorov +// SPDX-FileCopyrightText: 2026 Nikolay Govorov // SPDX-License-Identifier: Apache-2.0 //! Typed wrapper over the `qemu-system-*` command line. One qemu concept diff --git a/crates/hule-vmm/src/backend/qemu/mod.rs b/crates/hule-vmm/src/backend/qemu/mod.rs index be470e0..73ad36c 100644 --- a/crates/hule-vmm/src/backend/qemu/mod.rs +++ b/crates/hule-vmm/src/backend/qemu/mod.rs @@ -1,4 +1,4 @@ -// SPDX-FileCopyrightText: 2026 Nikolay Govorov +// SPDX-FileCopyrightText: 2026 Nikolay Govorov // SPDX-License-Identifier: Apache-2.0 //! QMP is an unconditional implementation detail of this backend. Guest diff --git a/crates/hule-vmm/src/backend/qemu/qga.rs b/crates/hule-vmm/src/backend/qemu/qga.rs index 0b2b269..a9a57f7 100644 --- a/crates/hule-vmm/src/backend/qemu/qga.rs +++ b/crates/hule-vmm/src/backend/qemu/qga.rs @@ -1,4 +1,4 @@ -// SPDX-FileCopyrightText: 2026 Nikolay Govorov +// SPDX-FileCopyrightText: 2026 Nikolay Govorov // SPDX-License-Identifier: Apache-2.0 //! Minimal qemu-guest-agent client over qemu's host-side chardev socket. diff --git a/crates/hule-vmm/src/backend/qemu/qmp.rs b/crates/hule-vmm/src/backend/qemu/qmp.rs index f7d890b..1028289 100644 --- a/crates/hule-vmm/src/backend/qemu/qmp.rs +++ b/crates/hule-vmm/src/backend/qemu/qmp.rs @@ -1,4 +1,4 @@ -// SPDX-FileCopyrightText: 2026 Nikolay Govorov +// SPDX-FileCopyrightText: 2026 Nikolay Govorov // SPDX-License-Identifier: Apache-2.0 //! Minimal QMP client: line-delimited JSON commands/responses over the TCP diff --git a/crates/hule-vmm/src/backend/qemu/supervise.rs b/crates/hule-vmm/src/backend/qemu/supervise.rs index 6eb38e8..c799bb2 100644 --- a/crates/hule-vmm/src/backend/qemu/supervise.rs +++ b/crates/hule-vmm/src/backend/qemu/supervise.rs @@ -1,4 +1,4 @@ -// SPDX-FileCopyrightText: 2026 Nikolay Govorov +// SPDX-FileCopyrightText: 2026 Nikolay Govorov // SPDX-License-Identifier: Apache-2.0 //! Runs a command so its exit code survives even once nobody is left to diff --git a/crates/hule-vmm/src/hypervisor.rs b/crates/hule-vmm/src/hypervisor.rs index 9944660..31262b4 100644 --- a/crates/hule-vmm/src/hypervisor.rs +++ b/crates/hule-vmm/src/hypervisor.rs @@ -1,4 +1,4 @@ -// SPDX-FileCopyrightText: 2026 Nikolay Govorov +// SPDX-FileCopyrightText: 2026 Nikolay Govorov // SPDX-License-Identifier: Apache-2.0 use std::fmt; diff --git a/crates/hule-vmm/src/lib.rs b/crates/hule-vmm/src/lib.rs index 681faa1..6f1b67a 100644 --- a/crates/hule-vmm/src/lib.rs +++ b/crates/hule-vmm/src/lib.rs @@ -1,4 +1,4 @@ -// SPDX-FileCopyrightText: 2026 Nikolay Govorov +// SPDX-FileCopyrightText: 2026 Nikolay Govorov // SPDX-License-Identifier: Apache-2.0 //! Machine lifecycle: hypervisor plugins, machine handles, and the monitor diff --git a/crates/hule-vmm/src/machine.rs b/crates/hule-vmm/src/machine.rs index f1df0e5..3f826e6 100644 --- a/crates/hule-vmm/src/machine.rs +++ b/crates/hule-vmm/src/machine.rs @@ -1,4 +1,4 @@ -// SPDX-FileCopyrightText: 2026 Nikolay Govorov +// SPDX-FileCopyrightText: 2026 Nikolay Govorov // SPDX-License-Identifier: Apache-2.0 use std::fmt; diff --git a/crates/hule-vmm/src/monitor.rs b/crates/hule-vmm/src/monitor.rs index 825b07e..038b219 100644 --- a/crates/hule-vmm/src/monitor.rs +++ b/crates/hule-vmm/src/monitor.rs @@ -1,4 +1,4 @@ -// SPDX-FileCopyrightText: 2026 Nikolay Govorov +// SPDX-FileCopyrightText: 2026 Nikolay Govorov // SPDX-License-Identifier: Apache-2.0 use std::path::{Path, PathBuf}; diff --git a/crates/hule/Cargo.toml b/crates/hule/Cargo.toml index 728df1e..12f361d 100644 --- a/crates/hule/Cargo.toml +++ b/crates/hule/Cargo.toml @@ -1,4 +1,4 @@ -# SPDX-FileCopyrightText: 2026 Nikolay Govorov +# SPDX-FileCopyrightText: 2026 Nikolay Govorov # SPDX-License-Identifier: Apache-2.0 [package] @@ -13,7 +13,6 @@ authors.workspace = true repository.workspace = true [dependencies] -clap = { version = "4.6.1", features = ["derive"] } hule-hmi.workspace = true hule-oci.workspace = true hule-vmm.workspace = true diff --git a/crates/hule/src/main.rs b/crates/hule/src/main.rs index a1be2bb..3f316f5 100644 --- a/crates/hule/src/main.rs +++ b/crates/hule/src/main.rs @@ -1,11 +1,9 @@ -// SPDX-FileCopyrightText: 2026 Nikolay Govorov +// SPDX-FileCopyrightText: 2026 Nikolay Govorov // SPDX-License-Identifier: Apache-2.0 -use std::fmt::Display; -use std::path::{Path, PathBuf}; +use std::path::Path; use std::process::exit; -use clap::{Parser, Subcommand}; use hule_hmi::{Access, MachineImage}; use hule_vmm::backend::qemu::QemuHypervisor; use hule_vmm::{Hypervisor, MachineId, Settings}; @@ -13,77 +11,19 @@ use uuid::Uuid; type R<T> = std::result::Result<T, String>; -#[derive(Parser)] -#[command(version, about)] -#[command(propagate_version = true)] -struct Cli { - #[command(subcommand)] - command: Commands, -} - -#[derive(Subcommand)] -enum Commands { - Image { - #[command(subcommand)] - command: ImageCommands, - }, - - Machine { - #[command(subcommand)] - command: MachineCommands, - }, -} - -#[derive(Subcommand)] -enum ImageCommands { - Pull { - name: String, - }, - - Push { - name: String, - }, - - Load { - image: String, - - reference: Option<String>, - }, -} - -#[derive(Subcommand)] -enum MachineCommands { - Run { - image: String, - - #[arg(default_value_t = 8022)] - port: u16, - }, -} - -fn die(msg: impl Display) -> ! { - eprintln!("hule: {msg}"); +fn die(msg: impl AsRef<str>) -> ! { + eprintln!("hule: {}", msg.as_ref()); exit(1); } -async fn cmd_run(images: &hule_oci::ImageManager, reference: &str, port: u16) -> R<()> { - if !images - .contains(reference) - .await - .map_err(|error| error.to_string())? - { +async fn cmd_run(reference: &str, port: u16) -> R<()> { + if !hule_oci::contains(reference)? { eprintln!("hule: {reference} not found locally, pulling..."); - images - .pull(reference) - .await - .map_err(|error| error.to_string())?; + hule_oci::pull(reference).await?; } let scratch = std::env::temp_dir().join(format!("hule-run-{}", std::process::id())); - let config = images - .materialize(reference, &scratch) - .await - .map_err(|error| error.to_string())?; + let config = hule_oci::materialize(reference, &scratch)?; let image = MachineImage::from_json(&config).map_err(|e| e.to_string())?; let hv = QemuHypervisor; @@ -134,49 +74,60 @@ async fn cmd_run(images: &hule_oci::ImageManager, reference: &str, port: u16) -> #[tokio::main] async fn main() { - let cli = Cli::parse(); - - let home = std::env::var("HOME").unwrap_or_else(|_| die("HOME is not set")); - let root = PathBuf::from(home).join(".hule"); - - let storage = hule_oci::Storage::open(root.join("oci"), root.join("hmi")) - .await - .unwrap_or_else(|e| die(e)); - - let images = hule_oci::ImageManager::new(storage); + let args: Vec<String> = std::env::args().collect(); + let usage = |prog: &str| -> ! { + eprintln!("usage:"); + eprintln!(" {prog} import <image-dir> [ref]"); + eprintln!(" {prog} push <ref>"); + eprintln!(" {prog} pull <ref>"); + eprintln!(" {prog} run <ref> [port]"); + exit(2); + }; - match &cli.command { - Commands::Image { command } => match &command { - ImageCommands::Pull { name } => { - let digest = images.pull(name).await.unwrap_or_else(|e| die(e)); - eprintln!("hule: pulled {} ({digest})", name); - } + if args.len() < 2 { + usage(&args[0]); + } - ImageCommands::Push { name } => { - images.push(name).await.unwrap_or_else(|e| die(e)); - eprintln!("hule: pushed {}", name); + match args[1].as_str() { + "import" => { + if args.len() < 3 { + usage(&args[0]); } - - ImageCommands::Load { reference, image } => { - let digest = images - .load(Path::new(image), reference.as_deref()) - .await - .unwrap_or_else(|e| die(e)); - - match reference { - Some(reference) => { - eprintln!("hule: loaded {} as {reference} ({digest})", image) - } - None => eprintln!("hule: loaded {} ({digest}, untagged)", image), + let reference = args.get(3).map(String::as_str); + let digest = hule_oci::import(Path::new(&args[2]), reference) + .await + .unwrap_or_else(|e| die(e)); + match reference { + Some(reference) => { + eprintln!("hule: imported {} as {reference} ({digest})", args[2]) } + None => eprintln!("hule: imported {} ({digest}, untagged)", args[2]), + } + } + "push" => { + if args.len() < 3 { + usage(&args[0]); + } + hule_oci::push(&args[2]).await.unwrap_or_else(|e| die(e)); + eprintln!("hule: pushed {}", args[2]); + } + "pull" => { + if args.len() < 3 { + usage(&args[0]); } - }, - Commands::Machine { command } => match &command { - MachineCommands::Run { image, port } => { - cmd_run(&images, image, *port) - .await - .unwrap_or_else(|e| die(e)); + let digest = hule_oci::pull(&args[2]).await.unwrap_or_else(|e| die(e)); + eprintln!("hule: pulled {} ({digest})", args[2]); + } + "run" => { + if args.len() < 3 { + usage(&args[0]); } - }, + let port = args + .get(3) + .map_or(Ok(8022), |s| s.parse::<u16>()) + .unwrap_or_else(|_| die(format!("invalid port '{}'", args[3]))); + cmd_run(&args[2], port).await.unwrap_or_else(|e| die(e)); + } + _ => usage(&args[0]), } } diff --git a/docs/whitepaper.md b/docs/whitepaper.md index 2661601..948430e 100644 --- a/docs/whitepaper.md +++ b/docs/whitepaper.md @@ -106,7 +106,7 @@ chunks so they can be transferred and verified in parallel. It is responsible for: -- loading and saving already prepared Hule machines; +- importing an already prepared machine; - pushing and pulling OCI artifacts; - maintaining a content-addressed local cache; - resolving complete backing chains; @@ -142,12 +142,12 @@ builder, an exported VM, or a directory copied by the user. A Hulefile is a recipe for deriving one Hule image from another. Unlike an external image builder, it does not install an operating system from scratch. -Its input is an already loaded Hule machine that can be started and controlled +Its input is an already imported Hule machine that can be started and controlled through an `exec`-capable access method. Every Hulefile has exactly one parent image. There is no empty base and no equivalent of `FROM scratch`: creating the first bootable machine always happens -outside the Hulefile workflow and enters Hule through load or import. +outside the Hulefile workflow and enters Hule through import. The intended execution model is deliberately simple: @@ -172,15 +172,12 @@ implicitly portable across operating systems. ## Image Lifecycle -### Prepare, Import, and Load +### Prepare and Import Preparing a base guest operating system is outside Hule. Users may use Packer, a -`genimg` script, an unattended installer, or a manually configured VM. A -finished Hule machine with HMI disks and a `config.json` enters the local store -through load and can be exported again through save. A qcow2 or raw disk image -instead enters through import, which converts it to HMI and constructs the -machine configuration where possible. The resulting Hule image can then be -distributed or used as the parent of a Hulefile. +`genimg` script, an unattended installer, or a manually configured VM. Hule +imports the finished, powered-off machine, which can then be distributed or used +as the parent of a Hulefile. This boundary is important for systems whose prebuilt images cannot be freely redistributed. A project can publish a recipe that downloads official @@ -189,9 +186,8 @@ to the user's own OCI registry. ### Publish -The prepared Hule machine is loaded, validated, split into OCI blobs, and pushed -to a registry. Tags provide convenient names; digests identify immutable -versions. +The prepared machine is imported, validated, split into OCI blobs, and pushed to +a registry. Tags provide convenient names; digests identify immutable versions. ### Run diff --git a/images/alpine/genimg b/images/alpine/genimg index f5446ce..76405a4 100755 --- a/images/alpine/genimg +++ b/images/alpine/genimg @@ -1,6 +1,6 @@ #!/bin/sh -eux # SPDX-FileCopyrightText: 2017-2026 Drew DeVault -# SPDX-FileCopyrightText: 2026 Nikolay Govorov +# SPDX-FileCopyrightText: 2026 Nikolay Govorov # SPDX-License-Identifier: AGPL-3.0-only self=$(dirname "$(readlink -f "$0")") @@ -56,7 +56,7 @@ qemu-img create -f qcow2 -o compat=1.1 "$out"/root.hmi "${size_gib}G" modprobe nbd max_part=16 qemu-nbd --connect=/dev/nbd0 "$out"/root.hmi for i in $(seq 1 5); do - sleep "0.$i" + sleep 0.$i partprobe /dev/nbd0 && break done trap cleanup EXIT @@ -82,13 +82,13 @@ swapon /dev/nbd0p2 # TODO: Remove bash apk add -U \ - -X "http://dl-cdn.alpinelinux.org/alpine/$release/main/" \ - -X "http://dl-cdn.alpinelinux.org/alpine/$release/community/" \ + -X http://dl-cdn.alpinelinux.org/alpine/$release/main/ \ + -X http://dl-cdn.alpinelinux.org/alpine/$release/community/ \ --allow-untrusted \ --arch="$apk_arch" \ --root=/mnt \ --initdb \ - acct alpine-base alpine-conf alpine-sdk linux-firmware-none "$linux" \ + acct alpine-base alpine-conf alpine-sdk linux-firmware-none $linux \ git mercurial openssh sudo syslinux tzdata gnupg haveged bash curl \ doas qemu-guest-agent @@ -200,11 +200,11 @@ cat >/mnt/etc/docker/daemon.json <<EOF EOF pkg_version() { - name=$(run_root apk list "$1" | grep installed | cut -d' ' -f1) - echo "${name##"$1"-}" + name=$(run_root apk list $1 | grep installed | cut -d' ' -f1) + echo ${name##$1-} } -run_root apk add "$linux=$(pkg_version "$linux")" +run_root apk add $linux=$(pkg_version $linux) sync diff --git a/images/debian/genimg b/images/debian/genimg index 2dedba5..85e363a 100755 --- a/images/debian/genimg +++ b/images/debian/genimg @@ -1,6 +1,6 @@ #!/bin/sh -eux # SPDX-FileCopyrightText: 2017-2026 Drew DeVault -# SPDX-FileCopyrightText: 2026 Nikolay Govorov +# SPDX-FileCopyrightText: 2026 Nikolay Govorov # SPDX-License-Identifier: AGPL-3.0-only self=$(dirname "$(readlink -f "$0")") @@ -21,16 +21,19 @@ case $arch in amd64) darch=amd64 iface=ens3 + qarch=x86_64 kpkg=linux-image-amd64 ;; arm64) darch=arm64 iface=enp0s1 + qarch=aarch64 kpkg=linux-image-arm64 ;; ppc64le) darch=ppc64el iface=enp0s0 + qarch=ppc64le kpkg=linux-image-powerpc64le ;; *) @@ -64,7 +67,7 @@ qemu-img create -f qcow2 -o compat=1.1 "$out/root.hmi" "${size_gib}G" modprobe nbd max_part=16 qemu-nbd --connect=/dev/nbd0 "$out/root.hmi" for i in $(seq 1 5); do - sleep "0.$i" + sleep 0.$i partprobe /dev/nbd0 && break done trap cleanup EXIT @@ -88,9 +91,9 @@ mkdir /mnt/boot mount /dev/nbd0p1 /mnt/boot if [ "$arch" = "amd64" ]; then - debootstrap --include=gnupg2 --arch="$darch" "$release" /mnt + debootstrap --include=gnupg2 --arch=$darch $release /mnt else - ./qemu-debootstrap --include=gnupg2 --arch="$darch" "$release" /mnt + ./qemu-debootstrap --include=gnupg2 --arch=$darch $release /mnt fi mount --bind /dev /mnt/dev @@ -156,14 +159,7 @@ EOF run_root update-initramfs -u -kernel_path= -for candidate in /mnt/boot/vmlinuz-*; do - [ -e "$candidate" ] || continue - kernel_path=$candidate - break -done -[ -n "$kernel_path" ] -linuxver=${kernel_path##*/vmlinuz-} +linuxver=$(ls /mnt/boot | grep vmlinuz | cut -d- -f2-) # Reference partitions by PARTUUID so boot survives whatever the VMM names the # disk. cmdline is canonical: identical for every boot protocol (extlinux append diff --git a/images/fedora/genimg b/images/fedora/genimg index 8215ec5..56e2a5d 100755 --- a/images/fedora/genimg +++ b/images/fedora/genimg @@ -1,6 +1,6 @@ #!/bin/sh -eux # SPDX-FileCopyrightText: 2017-2026 Drew DeVault -# SPDX-FileCopyrightText: 2026 Nikolay Govorov +# SPDX-FileCopyrightText: 2026 Nikolay Govorov # SPDX-License-Identifier: AGPL-3.0-only # Network Block Device used to interact with the QCOW2 image. @@ -150,14 +150,7 @@ run_root dnf clean all cat >/mnt/etc/dracut.conf.d/virtio-blk.conf <<EOF add_drivers="virtio-blk" EOF -kernel_path= -for candidate in /mnt/boot/vmlinuz-*."$fedora_arch"; do - [ -e "$candidate" ] || continue - kernel_path=$candidate - break -done -[ -n "$kernel_path" ] -kernel_version=${kernel_path##*/vmlinuz-} +kernel_version=$(ls /mnt/boot | grep "vmlinuz.*.$fedora_arch" | cut -d- -f2-) run_root dracut --force --kver "$kernel_version" run_root grub2-install --target=i386-pc $NBD_DEVICE diff --git a/images/freebsd/genimg b/images/freebsd/genimg index 08a258c..4d40076 100755 --- a/images/freebsd/genimg +++ b/images/freebsd/genimg @@ -1,6 +1,6 @@ #!/bin/sh -eux # SPDX-FileCopyrightText: 2017-2026 Drew DeVault -# SPDX-FileCopyrightText: 2026 Nikolay Govorov +# SPDX-FileCopyrightText: 2026 Nikolay Govorov # SPDX-License-Identifier: AGPL-3.0-only self=$(dirname "$(readlink -f "$0")") diff --git a/images/ubuntu/genimg b/images/ubuntu/genimg index 1980803..28d6e08 100755 --- a/images/ubuntu/genimg +++ b/images/ubuntu/genimg @@ -1,6 +1,6 @@ #!/bin/sh -eux # SPDX-FileCopyrightText: 2017-2026 Drew DeVault -# SPDX-FileCopyrightText: 2026 Nikolay Govorov +# SPDX-FileCopyrightText: 2026 Nikolay Govorov # SPDX-License-Identifier: AGPL-3.0-only self=$(dirname "$(readlink -f "$0")") @@ -81,7 +81,7 @@ export DEBIAN_FRONTEND=noninteractive debootstrap \ --include=gnupg,ubuntu-keyring \ - --arch="$arch" "$release" \ + --arch=$arch $release \ /mnt http://archive.ubuntu.com/ubuntu/ mount --bind /dev /mnt/dev @@ -111,9 +111,9 @@ echo 'nameserver 1.1.1.1' >>/mnt/etc/resolv.conf net_mode=static net_address=10.0.2.15/24 net_gateway=10.0.2.2 -cat >"/mnt/etc/systemd/network/25-$iface.network" <<EOF +cat >/mnt/etc/systemd/network/25-ens3.network <<EOF [Match] -Name=$iface +Name=ens3 [Network] Address=$net_address @@ -172,14 +172,7 @@ EOF run_root update-initramfs -u -kernel_path= -for candidate in /mnt/boot/vmlinuz-[0-9]*; do - [ -e "$candidate" ] || continue - kernel_path=$candidate - break -done -[ -n "$kernel_path" ] -linuxver=${kernel_path##*/vmlinuz-} +linuxver=$(ls /mnt/boot | grep 'vmlinuz-[0-9].*' | cut -d- -f2-) # Reference partitions by PARTUUID so boot works regardless of how the VMM names # the disk (vda/sda/nvme...). cmdline is canonical: identical for every boot diff --git a/mise.lock b/mise.lock deleted file mode 100644 --- a/mise.lock +++ /dev/null @@ -1,48 +0,0 @@ -# @generated - this file is auto-generated by `mise lock` https://mise.jdx.dev/dev-tools/mise-lock.html - -[[tools.rust]] -version = "1.97.1" -backend = "core:rust" - -[tools.rust.options] -components = "clippy,llvm-tools-preview,rustfmt" -profile = "minimal" - -[[tools.shellcheck]] -version = "0.11.0" -backend = "aqua:koalaman/shellcheck" - -[tools.shellcheck."platforms.linux-arm64"] -checksum = "sha256:12b331c1d2db6b9eb13cfca64306b1b157a86eb69db83023e261eaa7e7c14588" -url = "https://github.com/koalaman/shellcheck/releases/download/v0.11.0/shellcheck-v0.11.0.linux.aarch64.tar.xz" -url_api = "https://api.github.com/repos/koalaman/shellcheck/releases/assets/279056934" - -[tools.shellcheck."platforms.linux-arm64-musl"] -checksum = "sha256:12b331c1d2db6b9eb13cfca64306b1b157a86eb69db83023e261eaa7e7c14588" -url = "https://github.com/koalaman/shellcheck/releases/download/v0.11.0/shellcheck-v0.11.0.linux.aarch64.tar.xz" -url_api = "https://api.github.com/repos/koalaman/shellcheck/releases/assets/279056934" - -[tools.shellcheck."platforms.linux-x64"] -checksum = "sha256:8c3be12b05d5c177a04c29e3c78ce89ac86f1595681cab149b65b97c4e227198" -url = "https://github.com/koalaman/shellcheck/releases/download/v0.11.0/shellcheck-v0.11.0.linux.x86_64.tar.xz" -url_api = "https://api.github.com/repos/koalaman/shellcheck/releases/assets/279056942" - -[tools.shellcheck."platforms.linux-x64-musl"] -checksum = "sha256:8c3be12b05d5c177a04c29e3c78ce89ac86f1595681cab149b65b97c4e227198" -url = "https://github.com/koalaman/shellcheck/releases/download/v0.11.0/shellcheck-v0.11.0.linux.x86_64.tar.xz" -url_api = "https://api.github.com/repos/koalaman/shellcheck/releases/assets/279056942" - -[tools.shellcheck."platforms.macos-arm64"] -checksum = "sha256:56affdd8de5527894dca6dc3d7e0a99a873b0f004d7aabc30ae407d3f48b0a79" -url = "https://github.com/koalaman/shellcheck/releases/download/v0.11.0/shellcheck-v0.11.0.darwin.aarch64.tar.xz" -url_api = "https://api.github.com/repos/koalaman/shellcheck/releases/assets/279056932" - -[tools.shellcheck."platforms.macos-x64"] -checksum = "sha256:3c89db4edcab7cf1c27bff178882e0f6f27f7afdf54e859fa041fca10febe4c6" -url = "https://github.com/koalaman/shellcheck/releases/download/v0.11.0/shellcheck-v0.11.0.darwin.x86_64.tar.xz" -url_api = "https://api.github.com/repos/koalaman/shellcheck/releases/assets/279056930" - -[tools.shellcheck."platforms.windows-x64"] -checksum = "sha256:8a4e35ab0b331c85d73567b12f2a444df187f483e5079ceffa6bda1faa2e740e" -url = "https://github.com/koalaman/shellcheck/releases/download/v0.11.0/shellcheck-v0.11.0.zip" -url_api = "https://api.github.com/repos/koalaman/shellcheck/releases/assets/279056944" diff --git a/mise.toml b/mise.toml deleted file mode 100644 --- a/mise.toml +++ /dev/null @@ -1,17 +0,0 @@ -# SPDX-FileCopyrightText: 2026 Nikolay Govorov -# SPDX-License-Identifier: Apache-2.0 - -min_version = "2026.7.5" - -[settings] -experimental = true - -[tools] -rust = { version = "1.97.1", profile = "minimal", components = [ "clippy", "llvm-tools-preview", "rustfmt" ] } -shellcheck = "0.11.0" - -[task_config] -dir = "{{cwd}}" -includes = [ - "git::https://git.dimidiumlabs.io/platform.git//tasks?ref=e5ca3be4349af3d1da2dde9d1165d52fb014a371", -] diff --git a/scripts/check-signoff b/scripts/check-signoff new file mode 100755 --- /dev/null +++ b/scripts/check-signoff @@ -0,0 +1,39 @@ +#!/bin/sh -eu +# SPDX-FileCopyrightText: 2026 Nikolay Govorov +# SPDX-License-Identifier: Apache-2.0 + +ALLOWLIST='Nikolay Govorov|github-actions\[bot\]' + +bad=0 +for sha in $(git log --no-merges --format=%H); do + author=$(git log -1 --format='%an' "$sha") + if printf '%s\n' "$author" | grep -qE "^($ALLOWLIST)$"; then + continue + fi + + email=$(git log -1 --format='%ae' "$sha") + expected="${author} <${email}>" + if ! git log -1 --format='%(trailers:key=Signed-off-by,valueonly)' "$sha" | grep -qF "$expected"; then + echo "Commit $(printf '%.8s' "$sha") by ${expected} is missing a valid Signed-off-by" + bad=1 + fi +done + +if [ "$bad" -eq 1 ]; then + echo "All commits must be signed off (git commit -s). See CLA.md" + exit 1 +fi + +# Check that all authors and committers are in .mailmap +missing=0 +for email in $(git log --no-merges --format='%ae%n%ce' | sort -u); do + if ! grep -v '^#' .mailmap | grep -qF "<${email}>"; then + echo "Email <${email}> is not in .mailmap" + missing=1 + fi +done + +if [ "$missing" -eq 1 ]; then + echo "All contributors must be listed in .mailmap. See README.md" + exit 1 +fi |
