feat: fix ci

This commit is contained in:
2023-04-03 14:56:49 +02:00
parent 9565aa03b8
commit 079a076925
9 changed files with 182 additions and 136 deletions

View File

@@ -6,8 +6,9 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
dagger-sdk = "0.2.15"
dagger-sdk = "0.2.19"
eyre = "0.6.8"
color-eyre = "0.6.2"
tokio = { version = "1.26.0", features = ["full"] }
tokio = { version = "1.27.0", features = ["full"] }
chrono.workspace = true
dotenv = "0.15.0"

View File

@@ -1,5 +1,6 @@
#[tokio::main]
async fn main() -> eyre::Result<()> {
let _ = dotenv::dotenv();
let rust_image = "rustlang/rust:nightly";
let client = dagger_sdk::connect().await?;
@@ -14,12 +15,18 @@ async fn main() -> eyre::Result<()> {
let minio_url = "https://github.com/mozilla/sccache/releases/download/v0.3.3/sccache-v0.3.3-x86_64-unknown-linux-musl.tar.gz";
let sccache_download_cache = client.cache_volume("sccache_download");
let cargo_cache = client.cache_volume("cargo_cache");
// Main container
let rust_base = client
.container()
.from(rust_image)
.with_exec(vec!["apt-get", "update"])
.with_exec(vec!["apt-get", "install", "--yes", "libpq-dev", "wget"])
.with_exec(vec!["mkdir", "-p", "/src/downloads"])
.with_workdir("/src/downloads")
.with_mounted_cache("/src/downloads", sccache_download_cache.id().await?)
.with_exec(vec!["wget", minio_url])
.with_exec(vec![
"tar",
@@ -44,6 +51,8 @@ async fn main() -> eyre::Result<()> {
.with_env_variable("SCCACHE_BUCKET", "sccache")
.with_env_variable("SCCACHE_REGION", "auto")
.with_env_variable("SCCACHE_ENDPOINT", "https://api-minio.front.kjuulh.io")
.with_mounted_cache("~/.cargo", cargo_cache.id().await?)
.with_exec(vec!["rustup", "target", "add", "wasm32-unknown-unknown"])
.with_exec(vec!["cargo", "install", "cargo-chef"])
.with_exec(vec!["cargo", "install", "cargo-leptos"])
.with_workdir("/app");
@@ -53,8 +62,10 @@ async fn main() -> eyre::Result<()> {
eyre::bail!("could not build base");
}
let target_cache = client.cache_volume("target_cache");
let rust_prepare = rust_base
.with_mounted_directory(".", workdir.id().await?)
.with_mounted_cache("target", target_cache.id().await?)
.with_exec(vec![
"cargo",
"chef",
@@ -68,6 +79,8 @@ async fn main() -> eyre::Result<()> {
eyre::bail!("could not build prepare");
}
let target_rust_cache = client.cache_volume("target_rust_cache");
let rust_cacher = rust_base
.with_exec(vec!["apt", "update"])
.with_exec(vec![
@@ -83,7 +96,7 @@ async fn main() -> eyre::Result<()> {
"/recipe.json",
rust_prepare.file("./recipe.json").id().await?,
)
.with_mounted_directory(".", workdir.id().await?)
.with_mounted_cache("target", target_rust_cache.id().await?)
.with_exec(vec![
"cargo",
"chef",
@@ -91,36 +104,40 @@ async fn main() -> eyre::Result<()> {
"--release",
"--recipe-path",
"/recipe.json",
]);
])
.with_mounted_directory(".", workdir.id().await?);
let exit_code = rust_cacher.exit_code().await?;
if exit_code != 0 {
eyre::bail!("could not build cacher");
}
let rust_builder = rust_base
let nodejs_cacher = client.cache_volume("node");
// something
let rust_pre_builder = rust_cacher
.with_exec(vec!["mkdir", "-p", "node"])
.with_mounted_cache("node", nodejs_cacher.id().await?)
.with_exec(vec![
"curl",
"-sL",
"https://deb.nodesource.com/setup_12.x",
"-o",
"/node_12.txt",
"node/node_12.txt",
])
.with_exec(vec!["chmod", "+x", "/node_12.txt"])
.with_exec(vec!["bash", "-c", "/node_12.txt"])
.with_exec(vec!["chmod", "+x", "node/node_12.txt"])
.with_exec(vec!["bash", "-c", "node/node_12.txt"])
.with_exec(vec!["apt-get", "update"])
.with_exec(vec!["apt-get", "install", "nodejs"])
.with_mounted_directory(".", workdir.id().await?)
.with_directory(
"/app/target",
rust_cacher.directory("/app/target").id().await?,
)
.with_directory(
"/usr/local/cargo",
rust_cacher.directory("/usr/local/cargo").id().await?,
)
.with_exec(vec!["rustup", "target", "add", "wasm32-unknown-unknown"])
.with_exec(vec!["npm", "install", "-g", "sass"])
.with_exec(vec!["npm", "install", "-g", "sass"]);
let exit_code = rust_pre_builder.exit_code().await?;
if exit_code != 0 {
eyre::bail!("could not build rust_pre_builder");
}
let rust_builder = rust_pre_builder
.with_env_variable("LEPTOS_BROWSERQUERY", "defaults")
.with_exec(vec!["cargo", "leptos", "build", "--release"]);
@@ -131,16 +148,49 @@ async fn main() -> eyre::Result<()> {
let tag = chrono::Utc::now().timestamp();
let prod_image = "gcr.io/distroless/cc-debian11";
let prod_image = "debian:bullseye";
let prod = client
.container()
.from(prod_image)
.with_exec(vec!["apt", "update"])
.with_exec(vec!["apt", "install", "-y", "zlib1g", "git"])
.with_workdir("/app")
.with_directory("/app", rust_builder.directory("/app/target").id().await?)
.with_env_variable("LEPTOS_SITE_ADDRESS", "0.0.0.0:3000")
.with_entrypoint(vec!["/app/server/release/ssr_mode_axum"]);
.with_file(
"/app/ssr_modes",
rust_builder
.file("/app/target/server/release/ssr_modes")
.id()
.await?,
)
.with_directory(
"/app/site",
rust_builder.directory("/app/target/site").id().await?,
)
.with_env_variable("LEPTOS_OUTPUT_NAME", "ssr_modes")
.with_env_variable("LEPTOS_SITE_ROOT", "site")
.with_env_variable("LEPTOS_SITE_PKG_DIR", "pkg")
.with_env_variable("LEPTOS_SITE_ADDR", "0.0.0.0:3000")
.with_env_variable("LEPTOS_RELOAD_PORT", "3001")
.with_entrypoint(vec!["/app/ssr_modes"]);
prod.publish(format!("docker.io/kasperhermansen/bitebuds:{tag}"))
let image_tag = format!("docker.io/kasperhermansen/bitebuds:{tag}");
prod.publish(&image_tag).await?;
let update_deployment = client
.container()
.from("kasperhermansen/update-deployment:1680472594")
.with_env_variable("GIT_USERNAME", "kjuulh")
.with_env_variable("GIT_PASSWORD", std::env::var("GIT_PASSWORD").unwrap())
.with_exec(vec![
"update-deployment",
"--repo",
"https://git.front.kjuulh.io/kjuulh/bitebuds-deployment.git",
"--service",
"bitebuds",
"--image",
&image_tag,
])
.exit_code()
.await?;
Ok(())