Public release release-b8454b34d38c
Source commit: b8454b34d38cc2ba0bd278e842060db45d091e1c Public tree identity: sha256:69d6c8143bf6227e1bb07852aa94e8af9c26793eca252bb46788894f728cb6d2
This commit is contained in:
commit
d2e84229c5
221 changed files with 80960 additions and 0 deletions
13
examples/hello-build/Cargo.toml
Normal file
13
examples/hello-build/Cargo.toml
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
[package]
|
||||
name = "hello-build"
|
||||
version = "0.1.0"
|
||||
edition.workspace = true
|
||||
license.workspace = true
|
||||
repository.workspace = true
|
||||
publish = false
|
||||
|
||||
[lib]
|
||||
crate-type = ["rlib", "cdylib"]
|
||||
|
||||
[dependencies]
|
||||
clusterflux = { package = "clusterflux-sdk", path = "../../crates/clusterflux-sdk" }
|
||||
18
examples/hello-build/README.md
Normal file
18
examples/hello-build/README.md
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
# Hello build
|
||||
|
||||
The primary Clusterflux example snapshots this project, compiles a real static C
|
||||
executable in the declared offline Linux environment, and publishes the
|
||||
executable as a retained artifact.
|
||||
|
||||
Run it with:
|
||||
|
||||
~~~bash
|
||||
clusterflux bundle inspect --project examples/hello-build
|
||||
clusterflux run --project examples/hello-build build
|
||||
clusterflux artifact list --process <process-id>
|
||||
clusterflux artifact download <artifact-id> --to ./hello-clusterflux
|
||||
chmod +x ./hello-clusterflux
|
||||
./hello-clusterflux
|
||||
~~~
|
||||
|
||||
The final command prints hello from a real Clusterflux build.
|
||||
3
examples/hello-build/envs/linux/Containerfile
Normal file
3
examples/hello-build/envs/linux/Containerfile
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
FROM docker.io/library/alpine:3.20
|
||||
RUN apk add --no-cache build-base tar zstd
|
||||
WORKDIR /workspace
|
||||
6
examples/hello-build/fixture/hello-clusterflux.c
Normal file
6
examples/hello-build/fixture/hello-clusterflux.c
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
#include <stdio.h>
|
||||
|
||||
int main(void) {
|
||||
puts("hello from a real Clusterflux build");
|
||||
return 0;
|
||||
}
|
||||
30
examples/hello-build/src/lib.rs
Normal file
30
examples/hello-build/src/lib.rs
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
use clusterflux::prelude::*;
|
||||
|
||||
#[clusterflux::task(capabilities = "command")]
|
||||
pub async fn compile(source: SourceSnapshot) -> Result<Artifact> {
|
||||
let executable = fs::output("hello-clusterflux")?;
|
||||
Command::new("cc")
|
||||
.args([
|
||||
"-Os",
|
||||
"-static",
|
||||
"-s",
|
||||
"fixture/hello-clusterflux.c",
|
||||
"-o",
|
||||
executable.as_str(),
|
||||
])
|
||||
.cwd(source.mount()?)
|
||||
.env("SOURCE_DATE_EPOCH", "0")
|
||||
.network_disabled()
|
||||
.run()
|
||||
.await?;
|
||||
fs::publish(&executable).await
|
||||
}
|
||||
|
||||
#[clusterflux::main]
|
||||
pub async fn build() -> Result<Artifact> {
|
||||
let source = source::current_project().snapshot().await?;
|
||||
let compile = clusterflux::spawn!(compile(source))
|
||||
.on(clusterflux::env!("linux"))
|
||||
.await?;
|
||||
compile.join().await
|
||||
}
|
||||
14
examples/recovery-build/Cargo.toml
Normal file
14
examples/recovery-build/Cargo.toml
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
[package]
|
||||
name = "recovery-build"
|
||||
version = "0.1.0"
|
||||
edition.workspace = true
|
||||
license.workspace = true
|
||||
repository.workspace = true
|
||||
publish = false
|
||||
|
||||
[lib]
|
||||
crate-type = ["rlib", "cdylib"]
|
||||
|
||||
[dependencies]
|
||||
clusterflux = { package = "clusterflux-sdk", path = "../../crates/clusterflux-sdk" }
|
||||
serde.workspace = true
|
||||
7
examples/recovery-build/README.md
Normal file
7
examples/recovery-build/README.md
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
# Recovery build
|
||||
|
||||
This advanced example starts two instances of the same task definition. The
|
||||
stable lane completes while the recovering lane executes a real failing command
|
||||
under AwaitOperator. Edit the failing command to write
|
||||
/clusterflux/output/recovering.txt, then restart that task from the debugger or
|
||||
CLI. The original main join completes from the replacement attempt.
|
||||
3
examples/recovery-build/envs/linux/Containerfile
Normal file
3
examples/recovery-build/envs/linux/Containerfile
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
FROM docker.io/library/alpine:3.20
|
||||
RUN apk add --no-cache build-base tar zstd
|
||||
WORKDIR /workspace
|
||||
45
examples/recovery-build/src/lib.rs
Normal file
45
examples/recovery-build/src/lib.rs
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
use clusterflux::prelude::*;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Clone, Serialize, Deserialize, clusterflux::TaskArg)]
|
||||
pub struct BuildInput {
|
||||
lane: String,
|
||||
source: SourceSnapshot,
|
||||
}
|
||||
|
||||
#[clusterflux::task(capabilities = "command")]
|
||||
pub async fn build_lane(input: BuildInput) -> Result<Artifact> {
|
||||
let source_root = input.source.mount()?;
|
||||
let output = fs::output(format!("{}.txt", input.lane))?;
|
||||
let command = if input.lane == "recovering" {
|
||||
"exit 23".to_owned()
|
||||
} else {
|
||||
format!("sleep 3; printf 'stable\n' > {}", output.as_str())
|
||||
};
|
||||
Command::new("sh")
|
||||
.args(["-c", command.as_str()])
|
||||
.cwd(source_root)
|
||||
.network_disabled()
|
||||
.run()
|
||||
.await?;
|
||||
fs::publish(&output).await
|
||||
}
|
||||
|
||||
#[clusterflux::main]
|
||||
pub async fn build() -> Result<Vec<Artifact>> {
|
||||
let source = source::current_project().snapshot().await?;
|
||||
let stable = clusterflux::spawn!(build_lane(BuildInput {
|
||||
lane: "stable".to_owned(),
|
||||
source: source.clone(),
|
||||
}))
|
||||
.on(clusterflux::env!("linux"))
|
||||
.await?;
|
||||
let recovering = clusterflux::spawn!(build_lane(BuildInput {
|
||||
lane: "recovering".to_owned(),
|
||||
source,
|
||||
}))
|
||||
.on(clusterflux::env!("linux"))
|
||||
.failure_policy(clusterflux::TaskFailurePolicy::AwaitOperator)
|
||||
.await?;
|
||||
Ok(vec![stable.join().await?, recovering.join().await?])
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue