feat: add base
This commit is contained in:
commit
8b45df571d
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
.shuttle/
|
||||||
|
target/
|
40
actions/ci.go
Normal file
40
actions/ci.go
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"log"
|
||||||
|
"os"
|
||||||
|
"os/exec"
|
||||||
|
)
|
||||||
|
|
||||||
|
func Ci(ctx context.Context) error {
|
||||||
|
err := runRustPipeline(ctx)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func runRustPipeline(ctx context.Context) error {
|
||||||
|
cmd := exec.Command("cargo", "build")
|
||||||
|
cmd.Dir = "ci"
|
||||||
|
cmd.Stdin = os.Stdin
|
||||||
|
cmd.Stdout = os.Stdout
|
||||||
|
cmd.Stderr = os.Stderr
|
||||||
|
err := cmd.Run()
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
cmd = exec.Command("ci/target/debug/ci")
|
||||||
|
cmd.Stdin = os.Stdin
|
||||||
|
cmd.Stdout = os.Stdout
|
||||||
|
cmd.Stderr = os.Stderr
|
||||||
|
err = cmd.Run()
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
3
actions/go.mod
Normal file
3
actions/go.mod
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
module actions
|
||||||
|
|
||||||
|
go 1.20
|
1873
ci/Cargo.lock
generated
Normal file
1873
ci/Cargo.lock
generated
Normal file
File diff suppressed because it is too large
Load Diff
13
ci/Cargo.toml
Normal file
13
ci/Cargo.toml
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
[package]
|
||||||
|
name = "ci"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2021"
|
||||||
|
|
||||||
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
async-scoped = { version = "0.7.1", features = ["use-tokio"] }
|
||||||
|
color-eyre = "0.6.2"
|
||||||
|
dagger-sdk = "0.2.22"
|
||||||
|
eyre = "0.6.8"
|
||||||
|
tokio = { version = "1.28.0", features = ["full"] }
|
105
ci/src/main.rs
Normal file
105
ci/src/main.rs
Normal file
@ -0,0 +1,105 @@
|
|||||||
|
use std::sync::Arc;
|
||||||
|
|
||||||
|
use dagger_sdk::{ContainerPublishOptsBuilder, QueryContainerOptsBuilder};
|
||||||
|
use eyre::Context;
|
||||||
|
use tokio::sync::mpsc;
|
||||||
|
|
||||||
|
#[tokio::main]
|
||||||
|
async fn main() -> eyre::Result<()> {
|
||||||
|
color_eyre::install().unwrap();
|
||||||
|
|
||||||
|
let client = dagger_sdk::connect().await?;
|
||||||
|
|
||||||
|
let (tx, mut rx) = mpsc::channel(2);
|
||||||
|
|
||||||
|
async_scoped::TokioScope::scope_and_block(|s| {
|
||||||
|
for platform in &[("linux/amd64", "amd64"), ("linux/arm64", "aarch64")] {
|
||||||
|
let client = client.clone();
|
||||||
|
let tx = tx.clone();
|
||||||
|
let f = || async move {
|
||||||
|
let container = run_wasmer(client, platform.0, platform.1)
|
||||||
|
.await
|
||||||
|
.context("failed to run wasmer")
|
||||||
|
.unwrap();
|
||||||
|
let container_id = container
|
||||||
|
.id()
|
||||||
|
.await
|
||||||
|
.context("failed to get container id")
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
println!("done building for platform: {}", platform.0);
|
||||||
|
|
||||||
|
tx.send(container_id)
|
||||||
|
.await
|
||||||
|
.context("failed to send container id")
|
||||||
|
.unwrap();
|
||||||
|
};
|
||||||
|
|
||||||
|
s.spawn(f());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
drop(tx);
|
||||||
|
let mut containers: Vec<dagger_sdk::ContainerId> = Default::default();
|
||||||
|
while let Some(container) = rx.recv().await {
|
||||||
|
containers.push(container);
|
||||||
|
}
|
||||||
|
|
||||||
|
println!("publishing image!");
|
||||||
|
|
||||||
|
client
|
||||||
|
.container()
|
||||||
|
.publish_opts(
|
||||||
|
"git.front.kjuulh.io/kjuulh/wasmer:debian",
|
||||||
|
ContainerPublishOptsBuilder::default()
|
||||||
|
.platform_variants(containers)
|
||||||
|
.build()?,
|
||||||
|
)
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn run_wasmer(
|
||||||
|
client: Arc<dagger_sdk::Query>,
|
||||||
|
platform: &str,
|
||||||
|
architecture: &str,
|
||||||
|
) -> eyre::Result<dagger_sdk::Container> {
|
||||||
|
let wasmer_version = "v3.3.0";
|
||||||
|
let wasmer_architecture = architecture;
|
||||||
|
let wasmer_download_url =
|
||||||
|
format!("https://github.com/wasmerio/wasmer/releases/download/{wasmer_version}/wasmer-linux-{wasmer_architecture}.tar.gz");
|
||||||
|
|
||||||
|
let debian = build_debian(client, platform).await?;
|
||||||
|
|
||||||
|
let wasmer = debian
|
||||||
|
.with_exec(vec!["wget", &wasmer_download_url, "-O", "wasmer.tar.gz"])
|
||||||
|
.with_exec(vec!["tar", "-xvf", "wasmer.tar.gz"])
|
||||||
|
.with_exec(vec!["mv", "bin/wasmer", "/usr/bin/wasmer"])
|
||||||
|
.with_exec(vec!["wasmer", "-v"]);
|
||||||
|
|
||||||
|
let exit = wasmer.exit_code().await?;
|
||||||
|
if exit != 0 {
|
||||||
|
eyre::bail!("failed with exitcode: {exit}");
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(wasmer)
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn build_debian(
|
||||||
|
client: Arc<dagger_sdk::Query>,
|
||||||
|
platform: &str,
|
||||||
|
) -> eyre::Result<dagger_sdk::Container> {
|
||||||
|
let debian = client
|
||||||
|
.container_opts(
|
||||||
|
QueryContainerOptsBuilder::default()
|
||||||
|
.platform(platform)
|
||||||
|
.build()?,
|
||||||
|
)
|
||||||
|
.from("debian:bookworm")
|
||||||
|
.with_workdir("/tmp/")
|
||||||
|
.with_exec(vec!["apt", "update", "-y"])
|
||||||
|
.with_exec(vec!["apt", "install", "wget", "xz-utils", "-y"]);
|
||||||
|
|
||||||
|
Ok(debian)
|
||||||
|
}
|
1
shuttle.yaml
Normal file
1
shuttle.yaml
Normal file
@ -0,0 +1 @@
|
|||||||
|
plan: false
|
Loading…
Reference in New Issue
Block a user