// Oxygen's own pipeline (OxygenFlow, docs in the oxygenflow repository).
// Every push to a bookmark on OxygenHub runs it in Firecracker microVMs on
// Earth; the jobs appear as checks on the change.
schema-version 1

// The OxygenFlow build image: Rust with rustfmt and clippy, Node, and every
// crate of Cargo.lock vendored (oxygenflow/images/rust). Rebuild and re-pin
// it when Cargo.lock changes.
sandbox "rust" {
    runtime "microvm"
    rootfs "cas://blob/a3b49f36a2ad1838219ea0b7985591e44ac0e6d7f92e9d993d3a3738263fe32e"
    memory-limit "8GiB"
    cpu-limit 4
    // Tests serve and connect on 127.0.0.1; nothing leaves the guest.
    network "loopback"
    // CI builds are thrown away: no incremental state and no debug info,
    // so less to compile, link and write (as in oxygenhub's pipeline).
    env {
        CARGO_INCREMENTAL "0"
        CARGO_PROFILE_DEV_DEBUG "0"
        CARGO_PROFILE_TEST_DEBUG "0"
        CARGO_PROFILE_RELEASE_DEBUG "0"
    }
}

sandbox "rust-small" {
    runtime "microvm"
    rootfs "cas://blob/a3b49f36a2ad1838219ea0b7985591e44ac0e6d7f92e9d993d3a3738263fe32e"
    memory-limit "1GiB"
    cpu-limit 1
    network "isolated"
}

job "fmt" {
    sandbox "rust-small"
    exec "cargo" "fmt" "--all" "--check"
}

job "clippy" {
    sandbox "rust"
    depends-on "fmt"
    mount {
        source "ephemeral://disk"
        target "/src/target"
        size "24GiB"
    }
    exec "sh" ".flow/warm-target.sh" "cargo" "clippy" "--workspace" "--all-targets" "--locked" "--" "-D" "warnings"
}

job "test" {
    sandbox "rust"
    depends-on "fmt"
    mount {
        source "ephemeral://disk"
        target "/src/target"
        size "24GiB"
    }
    exec "sh" ".flow/warm-target.sh" "cargo" "test" "--workspace" "--locked"
}

job "build" {
    sandbox "rust"
    depends-on "fmt"
    mount {
        source "ephemeral://disk"
        target "/src/target"
        size "24GiB"
    }
    exec "sh" ".flow/warm-target.sh" "cargo" "build" "--release" "--locked"
    // The binary, kept as a blob of this repository and named by the
    // job's signed receipt; the run page links it.
    output {
        artifact "oxy" {
            path "/src/target/release/oxy"
        }
    }
}
