feat: with pull articles

This commit is contained in:
Kasper Juul Hermansen 2023-05-18 13:47:36 +02:00
parent 7f0ab1fc9a
commit 284ec2d636
Signed by: kjuulh
GPG Key ID: 57B6E1465221F912
4 changed files with 2292 additions and 0 deletions

9
build.sh Executable file
View File

@ -0,0 +1,9 @@
#!/bin/bash
pushd ci || exit
cargo build
popd || exit
./ci/target/debug/ci

2157
ci/Cargo.lock generated Normal file

File diff suppressed because it is too large Load Diff

14
ci/Cargo.toml Normal file
View File

@ -0,0 +1,14 @@
[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]
chrono = "0.4.24"
color-eyre = "0.6.2"
dagger-sdk = "0.2.19"
eyre = "0.6.8"
tokio = { version = "1.27.0", features = ["full"] }
tokio-scoped = "0.2.0"

112
ci/src/main.rs Normal file
View File

@ -0,0 +1,112 @@
use std::sync::Arc;
use dagger_sdk::{HostDirectoryOptsBuilder, QueryContainerOptsBuilder};
use tokio::sync::Mutex;
#[tokio::main]
async fn main() -> eyre::Result<()> {
color_eyre::install().unwrap();
let client = dagger_sdk::connect().await?;
let src = client.host().directory_opts(
".",
HostDirectoryOptsBuilder::default()
.exclude(vec!["target/", ".git/", "ci/"])
.build()?,
);
let variants = vec![/*"linux/amd64", */ "linux/arm64"];
let platform_variants = Arc::new(Mutex::new(Vec::new()));
tokio_scoped::scope(|s| {
for platform in variants {
let client = client.clone();
let platform_variants = platform_variants.clone();
let src = src.clone();
s.spawn(async move {
let rust_dep_image = client
.container_opts(
QueryContainerOptsBuilder::default()
.platform(platform)
.build()
.unwrap(),
)
.from("rustlang/rust:nightly")
.with_workdir("/app")
//.with_exec(vec!["apt-get", "update"])
//.with_exec(vec![
// "apt-get",
// "install",
// "-y",
// "build-essential",
// "cmake",
// "curl",
// "file",
// "git",
// "sudo",
// "xutils-dev",
// "unzip",
// "ca-certificates",
// "python3",
// "python3-pip",
// "autoconf",
// "autoconf-archive",
// "automake",
// "flex",
// "bison",
// "llvm-dev",
// "libclang-dev",
// "clang",
//])
.with_directory(".", src.id().await.unwrap())
.with_exec(vec!["cargo", "build", "--release"]);
let dep_image = client
.container_opts(
QueryContainerOptsBuilder::default()
.platform(platform)
.build()
.unwrap(),
)
.from("debian:bullseye")
.with_exec(vec!["apt-get", "update"])
.with_exec(vec!["apt-get", "install", "-y", "openssl", "git"])
.with_file(
"/usr/bin/pull-articles",
rust_dep_image
.file("target/release/pull-articles")
.id()
.await
.unwrap(),
)
.with_exec(vec!["pull-articles", "--help"]);
let mut platform_variants = platform_variants.lock().await;
platform_variants.push(dep_image.id().await.unwrap())
});
}
});
let variants = platform_variants
.lock()
.await
.iter()
.map(|c| c.clone())
.collect::<Vec<_>>();
let tag = chrono::Utc::now().timestamp();
let _ = client
.container()
.publish_opts(
format!("kasperhermansen/pull-articles:{tag}"),
dagger_sdk::ContainerPublishOptsBuilder::default()
.platform_variants(variants)
.build()?,
)
.await?;
Ok(())
}