Compare commits
16 Commits
v0.2.0
...
feat/with-
Author | SHA1 | Date | |
---|---|---|---|
10956e7af4
|
|||
4f72b4fdae
|
|||
ec029c81db | |||
ddde6c0734 | |||
cc1c356ad0 | |||
e18d247e11 | |||
11323c0752
|
|||
39d15b5d7f | |||
bdaea19ac6
|
|||
2d57b4f3b4
|
|||
52914e08e6
|
|||
e2c7f46378
|
|||
82289f2552
|
|||
2482987daf
|
|||
614a3bc305
|
|||
5e604d7a10
|
583
Cargo.lock
generated
583
Cargo.lock
generated
File diff suppressed because it is too large
Load Diff
17
Cargo.toml
17
Cargo.toml
@@ -2,6 +2,14 @@
|
||||
members = ["crates/*", "examples/*", "ci"]
|
||||
resolver = "2"
|
||||
|
||||
[workspace.package]
|
||||
version = "0.2.0"
|
||||
edition = "2021"
|
||||
license = "MIT"
|
||||
authors = ["kjuulh <contact@kjuulh.io>"]
|
||||
readme = "README.md"
|
||||
repository = "https://git.front.kjuulh.io/kjuulh/dagger-components"
|
||||
|
||||
[workspace.dependencies]
|
||||
cuddle-components = { path = "crates/cuddle-components" }
|
||||
dagger-components = { path = "crates/dagger-components" }
|
||||
@@ -9,8 +17,9 @@ dagger-cuddle-please = { path = "crates/dagger-cuddle-please" }
|
||||
dagger-rust = { path = "crates/dagger-rust" }
|
||||
ci = { path = "ci" }
|
||||
|
||||
dagger-sdk = "0.2.22"
|
||||
eyre = "0.6.8"
|
||||
tokio = "1.31.0"
|
||||
#dagger-sdk = "0.3.2"
|
||||
dagger-sdk = {git = "https://github.com/kjuulh/dagger.git", branch = "feat/with-send-sync"}
|
||||
eyre = "0.6.9"
|
||||
tokio = "1.34.0"
|
||||
dotenv = "0.15.0"
|
||||
async-trait = "0.1.73"
|
||||
async-trait = "0.1.74"
|
||||
|
@@ -8,12 +8,12 @@ edition = "2021"
|
||||
[dependencies]
|
||||
dagger-cuddle-please.workspace = true
|
||||
dagger-rust.workspace = true
|
||||
dagger-sdk.workspace = true
|
||||
|
||||
dagger-sdk = "*"
|
||||
eyre = "*"
|
||||
color-eyre = "*"
|
||||
tokio = "1"
|
||||
clap = {version = "4", features = ["derive"]}
|
||||
futures = "0.3.28"
|
||||
async-scoped = { version = "0.7.1", features = ["tokio", "use-tokio"] }
|
||||
futures = "0.3.29"
|
||||
async-scoped = { version = "0.8.0", features = ["tokio", "use-tokio"] }
|
||||
dotenv.workspace = true
|
||||
|
@@ -74,7 +74,7 @@ async fn main() -> eyre::Result<()> {
|
||||
LocalCommands::PleaseRelease => todo!(),
|
||||
},
|
||||
Commands::PullRequest {} => {
|
||||
async fn test(client: Arc<dagger_sdk::Query>, cli: &Command) {
|
||||
async fn test(client: dagger_sdk::Query, cli: &Command) {
|
||||
let args = &cli.global;
|
||||
|
||||
test::execute(client.clone(), args).await.unwrap();
|
||||
@@ -83,13 +83,13 @@ async fn main() -> eyre::Result<()> {
|
||||
tokio::join!(test(client.clone(), &cli),);
|
||||
}
|
||||
Commands::Main {} => {
|
||||
async fn test(client: Arc<dagger_sdk::Query>, cli: &Command) {
|
||||
async fn test(client: dagger_sdk::Query, cli: &Command) {
|
||||
let args = &cli.global;
|
||||
|
||||
test::execute(client.clone(), args).await.unwrap();
|
||||
}
|
||||
|
||||
async fn cuddle_please(client: Arc<dagger_sdk::Query>, cli: &Command) {
|
||||
async fn cuddle_please(client: dagger_sdk::Query, cli: &Command) {
|
||||
run_release_please(client.clone(), &cli.global)
|
||||
.await
|
||||
.unwrap();
|
||||
@@ -100,7 +100,7 @@ async fn main() -> eyre::Result<()> {
|
||||
cuddle_please(client.clone(), &cli)
|
||||
);
|
||||
}
|
||||
Commands::Release => todo!(),
|
||||
Commands::Release => {}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
@@ -114,7 +114,7 @@ mod please_release {
|
||||
use crate::GlobalArgs;
|
||||
|
||||
pub async fn run_release_please(
|
||||
client: Arc<dagger_sdk::Query>,
|
||||
client: dagger_sdk::Query,
|
||||
args: &GlobalArgs,
|
||||
) -> eyre::Result<()> {
|
||||
DaggerCuddlePleaseAction::dagger(client)
|
||||
@@ -142,7 +142,7 @@ mod test {
|
||||
|
||||
use crate::GlobalArgs;
|
||||
|
||||
pub async fn execute(client: Arc<dagger_sdk::Query>, _args: &GlobalArgs) -> eyre::Result<()> {
|
||||
pub async fn execute(client: dagger_sdk::Query, _args: &GlobalArgs) -> eyre::Result<()> {
|
||||
dagger_rust::test::RustTest::new(client)
|
||||
.test(
|
||||
None::<PathBuf>,
|
||||
|
@@ -1,7 +1,12 @@
|
||||
[package]
|
||||
name = "dagger-cuddle-please"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
description = "A set of components for running cuddle-please in dagger"
|
||||
version.workspace = true
|
||||
edition.workspace = true
|
||||
authors.workspace = true
|
||||
readme.workspace = true
|
||||
license.workspace = true
|
||||
repository.workspace = true
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
|
@@ -1,4 +1,4 @@
|
||||
use std::sync::Arc;
|
||||
use std::sync::{Arc, Mutex};
|
||||
|
||||
use models::{CuddlePleaseArgs, CuddlePleaseSrcArgs};
|
||||
use traits::CuddlePlease;
|
||||
@@ -80,11 +80,11 @@ pub mod traits {
|
||||
}
|
||||
}
|
||||
|
||||
pub struct DaggerCuddlePleaseAction(Arc<dyn CuddlePlease + Send + Sync + 'static>);
|
||||
pub struct DaggerCuddlePleaseAction(Arc<dyn CuddlePlease>);
|
||||
|
||||
impl DaggerCuddlePleaseAction {
|
||||
/// Create a [`traits::CuddlePlease`] client based on dagger
|
||||
pub fn dagger(client: Arc<dagger_sdk::Query>) -> Self {
|
||||
pub fn dagger(client: dagger_sdk::Query) -> Self {
|
||||
Self(Arc::new(DaggerCuddlePlease::new(client)))
|
||||
}
|
||||
|
||||
@@ -104,31 +104,27 @@ impl DaggerCuddlePleaseAction {
|
||||
|
||||
#[derive(Clone)]
|
||||
struct DaggerCuddlePlease {
|
||||
client: Arc<dagger_sdk::Query>,
|
||||
client: dagger_sdk::Query,
|
||||
}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl CuddlePlease for DaggerCuddlePlease {
|
||||
async fn execute(&self, args: &CuddlePleaseArgs) -> eyre::Result<()> {
|
||||
self.cuddle_please(self.client.clone(), args).await
|
||||
self.cuddle_please(args).await
|
||||
}
|
||||
|
||||
async fn execute_src(&self, args: &CuddlePleaseSrcArgs) -> eyre::Result<()> {
|
||||
self.cuddle_please_src(self.client.clone(), args).await
|
||||
self.cuddle_please_src(args).await
|
||||
}
|
||||
}
|
||||
|
||||
impl DaggerCuddlePlease {
|
||||
pub fn new(client: Arc<dagger_sdk::Query>) -> Self {
|
||||
pub fn new(client: dagger_sdk::Query) -> Self {
|
||||
Self { client }
|
||||
}
|
||||
|
||||
pub async fn cuddle_please(
|
||||
&self,
|
||||
client: Arc<dagger_sdk::Query>,
|
||||
args: &CuddlePleaseArgs,
|
||||
) -> eyre::Result<()> {
|
||||
let build_image = client.container().from(&args.cuddle_image);
|
||||
pub async fn cuddle_please(&self, args: &CuddlePleaseArgs) -> eyre::Result<()> {
|
||||
let build_image = self.client.container().from(&args.cuddle_image);
|
||||
|
||||
let repo_url = match &args.server {
|
||||
Server::Gitea {
|
||||
@@ -182,11 +178,12 @@ impl DaggerCuddlePlease {
|
||||
};
|
||||
|
||||
let src = if args.use_ssh_socket {
|
||||
let socket = client
|
||||
let socket = self
|
||||
.client
|
||||
.host()
|
||||
.unix_socket(std::env::var("SSH_AGENT").expect("SSH_AGENT to be set"));
|
||||
|
||||
client
|
||||
self.client
|
||||
.git_opts(
|
||||
&repo_url,
|
||||
dagger_sdk::QueryGitOpts {
|
||||
@@ -200,7 +197,7 @@ impl DaggerCuddlePlease {
|
||||
ssh_known_hosts: None,
|
||||
})
|
||||
} else {
|
||||
client
|
||||
self.client
|
||||
.git_opts(
|
||||
&repo_url,
|
||||
dagger_sdk::QueryGitOpts {
|
||||
@@ -215,19 +212,16 @@ impl DaggerCuddlePlease {
|
||||
let res = build_image
|
||||
.with_secret_variable(
|
||||
"CUDDLE_PLEASE_TOKEN",
|
||||
client
|
||||
.set_secret(
|
||||
"CUDDLE_PLEASE_TOKEN",
|
||||
match &args.server {
|
||||
Server::Gitea { token, .. } => token,
|
||||
Server::GitHub { token } => token,
|
||||
},
|
||||
)
|
||||
.id()
|
||||
.await?,
|
||||
self.client.set_secret(
|
||||
"CUDDLE_PLEASE_TOKEN",
|
||||
match &args.server {
|
||||
Server::Gitea { token, .. } => token,
|
||||
Server::GitHub { token } => token,
|
||||
},
|
||||
),
|
||||
)
|
||||
.with_workdir("/mnt/app")
|
||||
.with_directory(".", src.id().await?)
|
||||
.with_directory(".", src)
|
||||
.with_exec(vec!["git", "remote", "set-url", "origin", &repo_url])
|
||||
.with_exec(vec![
|
||||
"cuddle-please",
|
||||
@@ -257,10 +251,7 @@ impl DaggerCuddlePlease {
|
||||
},
|
||||
]);
|
||||
|
||||
let exit_code = res.exit_code().await?;
|
||||
if exit_code != 0 {
|
||||
eyre::bail!("failed to run cuddle-please");
|
||||
}
|
||||
res.sync().await?;
|
||||
|
||||
let please_out = res.stdout().await?;
|
||||
println!("{please_out}");
|
||||
@@ -269,37 +260,26 @@ impl DaggerCuddlePlease {
|
||||
|
||||
Ok(())
|
||||
}
|
||||
pub async fn cuddle_please_src(
|
||||
&self,
|
||||
client: Arc<dagger_sdk::Query>,
|
||||
args: &CuddlePleaseSrcArgs,
|
||||
) -> eyre::Result<()> {
|
||||
let build_image = client.container().from(&args.cuddle_image);
|
||||
pub async fn cuddle_please_src(&self, args: &CuddlePleaseSrcArgs) -> eyre::Result<()> {
|
||||
let build_image = self.client.container().from(&args.cuddle_image);
|
||||
let res = build_image
|
||||
.with_secret_variable(
|
||||
"CUDDLE_PLEASE_TOKEN",
|
||||
client
|
||||
.set_secret(
|
||||
"CUDDLE_PLEASE_TOKEN",
|
||||
match &args.server {
|
||||
SrcServer::Gitea { token, .. } => token,
|
||||
SrcServer::GitHub { token } => token,
|
||||
},
|
||||
)
|
||||
.id()
|
||||
.await?,
|
||||
self.client.set_secret(
|
||||
"CUDDLE_PLEASE_TOKEN",
|
||||
match &args.server {
|
||||
SrcServer::Gitea { token, .. } => token,
|
||||
SrcServer::GitHub { token } => token,
|
||||
},
|
||||
),
|
||||
)
|
||||
.with_workdir("/mnt/app")
|
||||
.with_directory(".", client.host().directory(".").id().await?)
|
||||
.with_directory(".", self.client.host().directory("."))
|
||||
.with_unix_socket(
|
||||
"/tmp/ssh.sock",
|
||||
client
|
||||
.host()
|
||||
.unix_socket(
|
||||
std::env::var("SSH_AUTH_SOCK").expect("expect SSH_AUTH_SOCK to be present"),
|
||||
)
|
||||
.id()
|
||||
.await?,
|
||||
self.client.host().unix_socket(
|
||||
std::env::var("SSH_AUTH_SOCK").expect("expect SSH_AUTH_SOCK to be present"),
|
||||
),
|
||||
)
|
||||
.with_env_variable("SSH_AUTH_SOCK", "/tmp/ssh.sock")
|
||||
.with_new_file_opts(
|
||||
@@ -357,10 +337,7 @@ Host *
|
||||
},
|
||||
]);
|
||||
|
||||
let exit_code = res.exit_code().await?;
|
||||
if exit_code != 0 {
|
||||
eyre::bail!("failed to run cuddle-please");
|
||||
}
|
||||
res.sync().await?;
|
||||
|
||||
let please_out = res.stdout().await?;
|
||||
println!("{please_out}");
|
||||
|
16
crates/dagger-leptos/Cargo.toml
Normal file
16
crates/dagger-leptos/Cargo.toml
Normal file
@@ -0,0 +1,16 @@
|
||||
[package]
|
||||
name = "dagger-leptos"
|
||||
version.workspace = true
|
||||
edition.workspace = true
|
||||
license.workspace = true
|
||||
authors.workspace = true
|
||||
readme.workspace = true
|
||||
repository.workspace = true
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
dagger-sdk.workspace = true
|
||||
eyre.workspace = true
|
||||
async-trait.workspace = true
|
||||
tokio.workspace = true
|
1
crates/dagger-leptos/src/lib.rs
Normal file
1
crates/dagger-leptos/src/lib.rs
Normal file
@@ -0,0 +1 @@
|
||||
|
@@ -1,7 +1,14 @@
|
||||
[package]
|
||||
name = "dagger-rust"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
description = "A common set of components for dagger-sdk, which enables patterns such as build, test and publish"
|
||||
version.workspace = true
|
||||
edition.workspace = true
|
||||
authors.workspace = true
|
||||
readme.workspace = true
|
||||
license.workspace = true
|
||||
repository.workspace = true
|
||||
|
||||
publish = true
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
|
@@ -1,15 +1,15 @@
|
||||
use std::{path::PathBuf, sync::Arc};
|
||||
use std::path::PathBuf;
|
||||
|
||||
use crate::source::RustSource;
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub struct RustBuild {
|
||||
client: Arc<dagger_sdk::Query>,
|
||||
client: dagger_sdk::Query,
|
||||
registry: Option<String>,
|
||||
}
|
||||
|
||||
impl RustBuild {
|
||||
pub fn new(client: Arc<dagger_sdk::Query>) -> Self {
|
||||
pub fn new(client: dagger_sdk::Query) -> Self {
|
||||
Self {
|
||||
client,
|
||||
registry: None,
|
||||
@@ -60,9 +60,9 @@ impl RustBuild {
|
||||
}
|
||||
let rust_prebuild = rust_build_image
|
||||
.with_workdir("/mnt/src")
|
||||
.with_directory("/mnt/src", dep_src.id().await?)
|
||||
.with_directory("/mnt/src", dep_src)
|
||||
.with_exec(build_options)
|
||||
.with_mounted_cache("/mnt/src/target/", target_cache.id().await?);
|
||||
.with_mounted_cache("/mnt/src/target/", target_cache);
|
||||
|
||||
let incremental_dir = rust_source
|
||||
.get_rust_target_src(&source, rust_prebuild.clone(), crates.to_vec())
|
||||
@@ -72,10 +72,10 @@ impl RustBuild {
|
||||
.with_workdir("/mnt/src")
|
||||
.with_directory(
|
||||
"/usr/local/cargo",
|
||||
rust_prebuild.directory("/usr/local/cargo").id().await?,
|
||||
rust_prebuild.directory("/usr/local/cargo"),
|
||||
)
|
||||
.with_directory("/mnt/src/target", incremental_dir.id().await?)
|
||||
.with_directory("/mnt/src/", src.id().await?);
|
||||
.with_directory("/mnt/src/target", incremental_dir)
|
||||
.with_directory("/mnt/src/", src);
|
||||
|
||||
Ok(rust_with_src)
|
||||
}
|
||||
@@ -210,10 +210,10 @@ impl RustBuild {
|
||||
.with_exec(packages);
|
||||
|
||||
let final_image = base_debian
|
||||
.with_file(format!("/usr/local/bin/{}", bin_name), bin.id().await?)
|
||||
.with_file(format!("/usr/local/bin/{}", bin_name), bin)
|
||||
.with_exec(vec![bin_name, "--help"]);
|
||||
|
||||
final_image.exit_code().await?;
|
||||
final_image.sync().await?;
|
||||
|
||||
Ok(final_image)
|
||||
}
|
||||
@@ -238,8 +238,7 @@ impl RustBuild {
|
||||
packages.extend_from_slice(production_deps);
|
||||
let base_debian = base_debian.with_exec(packages);
|
||||
|
||||
let final_image =
|
||||
base_debian.with_file(format!("/usr/local/bin/{}", bin_name), bin.id().await?);
|
||||
let final_image = base_debian.with_file(format!("/usr/local/bin/{}", bin_name), bin);
|
||||
|
||||
Ok(final_image)
|
||||
}
|
||||
@@ -252,7 +251,7 @@ pub enum RustVersion {
|
||||
|
||||
impl AsRef<RustVersion> for RustVersion {
|
||||
fn as_ref(&self) -> &RustVersion {
|
||||
&self
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
@@ -288,7 +287,7 @@ impl BuildTarget {
|
||||
}
|
||||
}
|
||||
|
||||
fn into_platform(&self) -> dagger_sdk::Platform {
|
||||
pub fn into_platform(&self) -> dagger_sdk::Platform {
|
||||
let platform = match self {
|
||||
BuildTarget::LinuxAmd64 => "linux/amd64",
|
||||
BuildTarget::LinuxArm64 => "linux/arm64",
|
||||
@@ -304,7 +303,7 @@ impl BuildTarget {
|
||||
|
||||
impl AsRef<BuildTarget> for BuildTarget {
|
||||
fn as_ref(&self) -> &BuildTarget {
|
||||
&self
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
@@ -330,7 +329,7 @@ pub enum BuildProfile {
|
||||
|
||||
impl AsRef<BuildProfile> for BuildProfile {
|
||||
fn as_ref(&self) -> &BuildProfile {
|
||||
&self
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
|
266
crates/dagger-rust/src/htmx.rs
Normal file
266
crates/dagger-rust/src/htmx.rs
Normal file
@@ -0,0 +1,266 @@
|
||||
use std::path::PathBuf;
|
||||
|
||||
use crate::{
|
||||
build::{BuildProfile, BuildTarget, RustVersion, SlimImage},
|
||||
source::RustSource,
|
||||
};
|
||||
|
||||
pub struct HtmxBuild {
|
||||
client: dagger_sdk::Query,
|
||||
registry: Option<String>,
|
||||
}
|
||||
|
||||
impl HtmxBuild {
|
||||
pub fn new(client: dagger_sdk::Query) -> Self {
|
||||
Self {
|
||||
client,
|
||||
registry: None,
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn build(
|
||||
&self,
|
||||
source_path: Option<impl Into<PathBuf>>,
|
||||
rust_version: impl AsRef<RustVersion>,
|
||||
profile: impl AsRef<BuildProfile>,
|
||||
crates: &[&str],
|
||||
extra_deps: &[&str],
|
||||
) -> eyre::Result<dagger_sdk::Container> {
|
||||
let source_path = source_path.map(|s| s.into()).unwrap_or(PathBuf::from("."));
|
||||
let rust_version = rust_version.as_ref();
|
||||
let profile = profile.as_ref();
|
||||
|
||||
let rust_source = RustSource::new(self.client.clone());
|
||||
|
||||
let (src, dep_src) = rust_source
|
||||
.get_rust_src(Some(&source_path), crates.to_vec())
|
||||
.await?;
|
||||
|
||||
let mut deps = vec!["apt", "install", "-y"];
|
||||
deps.extend(extra_deps);
|
||||
|
||||
let rust_build_image = self
|
||||
.client
|
||||
.container()
|
||||
.from(rust_version.to_string())
|
||||
.with_exec(vec!["rustup", "target", "add", "wasm32-unknown-unknown"])
|
||||
.with_exec(vec!["apt", "update"])
|
||||
.with_exec(deps)
|
||||
.with_exec(vec!["wget", "https://github.com/cargo-bins/cargo-binstall/releases/latest/download/cargo-binstall-x86_64-unknown-linux-musl.tgz"])
|
||||
.with_exec("tar -xvf cargo-binstall-x86_64-unknown-linux-musl.tgz".split_whitespace().collect())
|
||||
.with_exec("mv cargo-binstall /usr/local/cargo/bin".split_whitespace().collect())
|
||||
|
||||
.with_exec(vec!["wget", "https://github.com/rui314/mold/releases/latest/download/mold-2.3.3-x86_64-linux.tar.gz"])
|
||||
.with_exec("tar -xvf mold-2.3.3-x86_64-linux.tar.gz".split_whitespace().collect())
|
||||
.with_exec("mv mold /usr/bin/mold".split_whitespace().collect())
|
||||
|
||||
.with_exec(vec!["cargo", "binstall", "sqlx-cli", "-y"]);
|
||||
|
||||
let target_cache = self
|
||||
.client
|
||||
.cache_volume(format!("rust_htmx_{}", profile.to_string()));
|
||||
|
||||
let build_options = vec!["cargo", "sqlx", "prepare"];
|
||||
|
||||
let rust_prebuild = rust_build_image
|
||||
.with_workdir("/mnt/src")
|
||||
.with_directory("/mnt/src", dep_src)
|
||||
.with_exec(build_options)
|
||||
.with_mounted_cache("/mnt/src/target/", target_cache);
|
||||
|
||||
let incremental_dir = rust_source
|
||||
.get_rust_target_src(&source_path, rust_prebuild.clone(), crates.to_vec())
|
||||
.await?;
|
||||
|
||||
let rust_with_src = rust_build_image
|
||||
.with_workdir("/mnt/src")
|
||||
.with_directory(
|
||||
"/usr/local/cargo",
|
||||
rust_prebuild.directory("/usr/local/cargo"),
|
||||
)
|
||||
.with_directory("/mnt/src/target", incremental_dir)
|
||||
.with_directory("/mnt/src/", src);
|
||||
|
||||
Ok(rust_with_src)
|
||||
}
|
||||
|
||||
pub async fn build_release(
|
||||
&self,
|
||||
source_path: Option<impl Into<PathBuf>>,
|
||||
rust_version: impl AsRef<RustVersion>,
|
||||
crates: &[&str],
|
||||
extra_deps: &[&str],
|
||||
images: impl IntoIterator<Item = SlimImage>,
|
||||
bin_name: &str,
|
||||
) -> eyre::Result<Vec<dagger_sdk::Container>> {
|
||||
let images = images.into_iter().collect::<Vec<_>>();
|
||||
let source_path = source_path.map(|s| s.into());
|
||||
|
||||
let postgres_password = "somepassword123";
|
||||
let postgres = self
|
||||
.client
|
||||
.container()
|
||||
.from("postgres:16.1")
|
||||
.with_env_variable("POSTGRES_PASSWORD", postgres_password);
|
||||
|
||||
let postgres_service = postgres.with_exposed_port(5432);
|
||||
|
||||
let mut containers = Vec::new();
|
||||
for container_image in images {
|
||||
let container =
|
||||
match &container_image {
|
||||
SlimImage::Debian { image, deps, .. } => {
|
||||
let target = BuildTarget::from_target(&container_image);
|
||||
|
||||
let build_container = self
|
||||
.build(
|
||||
source_path.clone(),
|
||||
&rust_version,
|
||||
BuildProfile::Release,
|
||||
crates,
|
||||
extra_deps,
|
||||
)
|
||||
.await?;
|
||||
|
||||
let binary_build = build_container
|
||||
.with_service_binding("postgres", postgres_service.as_service())
|
||||
.with_env_variable(
|
||||
"DATABASE_URL",
|
||||
"root:somepassword123@postgres:5432/postgres",
|
||||
)
|
||||
.with_exec(vec!["cargo", "sqlx", "migrate", "run"])
|
||||
.with_exec(vec!["cargo", "sqlx", "prepare"])
|
||||
.with_exec(vec!["cargo", "build", "--release", "--bin", bin_name]);
|
||||
|
||||
self.build_debian_image(
|
||||
binary_build,
|
||||
image,
|
||||
BuildTarget::from_target(&container_image),
|
||||
deps.iter()
|
||||
.map(|d| d.as_str())
|
||||
.collect::<Vec<&str>>()
|
||||
.as_slice(),
|
||||
bin_name,
|
||||
)
|
||||
.await?
|
||||
}
|
||||
SlimImage::Alpine { image, deps, .. } => {
|
||||
let target = BuildTarget::from_target(&container_image);
|
||||
|
||||
let build_container = self
|
||||
.build(
|
||||
source_path.clone(),
|
||||
&rust_version,
|
||||
BuildProfile::Release,
|
||||
crates,
|
||||
extra_deps,
|
||||
)
|
||||
.await?;
|
||||
|
||||
let bin = build_container
|
||||
.with_exec(vec![
|
||||
"cargo",
|
||||
"build",
|
||||
"--target",
|
||||
&target.to_string(),
|
||||
"--release",
|
||||
"-p",
|
||||
bin_name,
|
||||
])
|
||||
.file(format!("target/{}/release/{}", target.to_string(), bin_name));
|
||||
|
||||
self.build_alpine_image(
|
||||
bin,
|
||||
image,
|
||||
BuildTarget::from_target(&container_image),
|
||||
deps.iter()
|
||||
.map(|d| d.as_str())
|
||||
.collect::<Vec<&str>>()
|
||||
.as_slice(),
|
||||
bin_name,
|
||||
)
|
||||
.await?
|
||||
}
|
||||
};
|
||||
|
||||
containers.push(container);
|
||||
}
|
||||
|
||||
Ok(containers)
|
||||
}
|
||||
|
||||
async fn build_debian_image(
|
||||
&self,
|
||||
builder_image: dagger_sdk::Container,
|
||||
image: &str,
|
||||
target: BuildTarget,
|
||||
production_deps: &[&str],
|
||||
bin_name: &str,
|
||||
) -> eyre::Result<dagger_sdk::Container> {
|
||||
let base_debian = self
|
||||
.client
|
||||
.container_opts(dagger_sdk::QueryContainerOpts {
|
||||
id: None,
|
||||
platform: Some(target.into_platform()),
|
||||
})
|
||||
.from(image);
|
||||
|
||||
let mut packages = vec!["apt", "install", "-y"];
|
||||
packages.extend_from_slice(production_deps);
|
||||
let base_debian = base_debian
|
||||
.with_exec(vec!["apt", "update"])
|
||||
.with_exec(packages);
|
||||
|
||||
let final_image = base_debian
|
||||
.with_workdir("/mnt/app")
|
||||
.with_file(
|
||||
format!("/mnt/app/{bin_name}"),
|
||||
builder_image.file(format!("/mnt/src/target/release/{bin_name}")),
|
||||
)
|
||||
.with_directory(
|
||||
"/mnt/app/target/site",
|
||||
builder_image.directory(format!("/mnt/src/target/site")),
|
||||
)
|
||||
.with_file(
|
||||
"/mnt/app/Cargo.toml",
|
||||
builder_image.file(format!("/mnt/src/crates/{bin_name}/Cargo.toml")),
|
||||
)
|
||||
.with_env_variable("RUST_LOG", "debug")
|
||||
.with_env_variable("APP_ENVIRONMENT", "production")
|
||||
.with_env_variable("LEPTOS_OUTPUT_NAME", bin_name)
|
||||
.with_env_variable("LEPTOS_SITE_ADDR", "0.0.0.0:8080")
|
||||
.with_env_variable("LEPTOS_SITE_ROOT", "site")
|
||||
.with_env_variable("LEPTOS_SITE_PKG_DIR", "pkg")
|
||||
.with_exposed_port(8080)
|
||||
.with_entrypoint(vec![format!("/mnt/app/{bin_name}")]);
|
||||
|
||||
final_image.sync().await?;
|
||||
|
||||
Ok(final_image)
|
||||
}
|
||||
|
||||
async fn build_alpine_image(
|
||||
&self,
|
||||
bin: dagger_sdk::File,
|
||||
image: &str,
|
||||
target: BuildTarget,
|
||||
production_deps: &[&str],
|
||||
bin_name: &str,
|
||||
) -> eyre::Result<dagger_sdk::Container> {
|
||||
let base_debian = self
|
||||
.client
|
||||
.container_opts(dagger_sdk::QueryContainerOpts {
|
||||
id: None,
|
||||
platform: Some(target.into_platform()),
|
||||
})
|
||||
.from(image);
|
||||
|
||||
let mut packages = vec!["apk", "add"];
|
||||
packages.extend_from_slice(production_deps);
|
||||
let base_debian = base_debian.with_exec(packages);
|
||||
|
||||
let final_image = base_debian.with_file(format!("/usr/local/bin/{}", bin_name), bin);
|
||||
|
||||
Ok(final_image)
|
||||
}
|
||||
}
|
245
crates/dagger-rust/src/leptos.rs
Normal file
245
crates/dagger-rust/src/leptos.rs
Normal file
@@ -0,0 +1,245 @@
|
||||
use std::path::PathBuf;
|
||||
|
||||
use crate::{
|
||||
build::{BuildProfile, BuildTarget, RustVersion, SlimImage},
|
||||
source::RustSource,
|
||||
};
|
||||
|
||||
pub struct LeptosBuild {
|
||||
client: dagger_sdk::Query,
|
||||
registry: Option<String>,
|
||||
}
|
||||
|
||||
impl LeptosBuild {
|
||||
pub fn new(client: dagger_sdk::Query) -> Self {
|
||||
Self {
|
||||
client,
|
||||
registry: None,
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn build(
|
||||
&self,
|
||||
source_path: Option<impl Into<PathBuf>>,
|
||||
rust_version: impl AsRef<RustVersion>,
|
||||
profile: impl AsRef<BuildProfile>,
|
||||
crates: &[&str],
|
||||
extra_deps: &[&str],
|
||||
) -> eyre::Result<dagger_sdk::Container> {
|
||||
let source_path = source_path.map(|s| s.into()).unwrap_or(PathBuf::from("."));
|
||||
let rust_version = rust_version.as_ref();
|
||||
let profile = profile.as_ref();
|
||||
|
||||
let rust_source = RustSource::new(self.client.clone());
|
||||
|
||||
let (src, dep_src) = rust_source
|
||||
.get_rust_src(Some(&source_path), crates.to_vec())
|
||||
.await?;
|
||||
|
||||
let mut deps = vec!["apt", "install", "-y"];
|
||||
deps.extend(extra_deps);
|
||||
|
||||
let rust_build_image = self
|
||||
.client
|
||||
.container()
|
||||
.from(rust_version.to_string())
|
||||
.with_exec(vec!["rustup", "target", "add", "wasm32-unknown-unknown"])
|
||||
.with_exec(vec!["apt", "update"])
|
||||
.with_exec(deps)
|
||||
.with_exec(vec!["wget", "https://github.com/cargo-bins/cargo-binstall/releases/latest/download/cargo-binstall-x86_64-unknown-linux-musl.tgz"])
|
||||
.with_exec("tar -xvf cargo-binstall-x86_64-unknown-linux-musl.tgz".split_whitespace().collect())
|
||||
.with_exec("mv cargo-binstall /usr/local/cargo/bin".split_whitespace().collect())
|
||||
.with_exec(vec!["cargo", "binstall", "cargo-leptos", "-y"]);
|
||||
|
||||
let target_cache = self
|
||||
.client
|
||||
.cache_volume(format!("rust_leptos_{}", profile.to_string()));
|
||||
|
||||
let mut build_options = vec!["cargo", "leptos", "build", "--release", "-vv"];
|
||||
|
||||
let rust_prebuild = rust_build_image
|
||||
.with_workdir("/mnt/src")
|
||||
.with_directory("/mnt/src", dep_src)
|
||||
.with_exec(build_options)
|
||||
.with_mounted_cache("/mnt/src/target/", target_cache);
|
||||
|
||||
let incremental_dir = rust_source
|
||||
.get_rust_target_src(&source_path, rust_prebuild.clone(), crates.to_vec())
|
||||
.await?;
|
||||
|
||||
let rust_with_src = rust_build_image
|
||||
.with_workdir("/mnt/src")
|
||||
.with_directory(
|
||||
"/usr/local/cargo",
|
||||
rust_prebuild.directory("/usr/local/cargo"),
|
||||
)
|
||||
.with_directory("/mnt/src/target", incremental_dir)
|
||||
.with_directory("/mnt/src/", src);
|
||||
|
||||
Ok(rust_with_src)
|
||||
}
|
||||
|
||||
pub async fn build_release(
|
||||
&self,
|
||||
source_path: Option<impl Into<PathBuf>>,
|
||||
rust_version: impl AsRef<RustVersion>,
|
||||
crates: &[&str],
|
||||
extra_deps: &[&str],
|
||||
images: impl IntoIterator<Item = SlimImage>,
|
||||
bin_name: &str,
|
||||
) -> eyre::Result<Vec<dagger_sdk::Container>> {
|
||||
let images = images.into_iter().collect::<Vec<_>>();
|
||||
let source_path = source_path.map(|s| s.into());
|
||||
|
||||
let mut containers = Vec::new();
|
||||
for container_image in images {
|
||||
let container = match &container_image {
|
||||
SlimImage::Debian { image, deps, .. } => {
|
||||
let target = BuildTarget::from_target(&container_image);
|
||||
|
||||
let build_container = self
|
||||
.build(
|
||||
source_path.clone(),
|
||||
&rust_version,
|
||||
BuildProfile::Release,
|
||||
crates,
|
||||
extra_deps,
|
||||
)
|
||||
.await?;
|
||||
|
||||
let binary_build =
|
||||
build_container
|
||||
.with_exec(vec!["cargo", "leptos", "build", "--release", "-vv"]);
|
||||
|
||||
self.build_debian_image(
|
||||
binary_build,
|
||||
image,
|
||||
BuildTarget::from_target(&container_image),
|
||||
deps.iter()
|
||||
.map(|d| d.as_str())
|
||||
.collect::<Vec<&str>>()
|
||||
.as_slice(),
|
||||
bin_name,
|
||||
)
|
||||
.await?
|
||||
}
|
||||
SlimImage::Alpine { image, deps, .. } => {
|
||||
let target = BuildTarget::from_target(&container_image);
|
||||
|
||||
let build_container = self
|
||||
.build(
|
||||
source_path.clone(),
|
||||
&rust_version,
|
||||
BuildProfile::Release,
|
||||
crates,
|
||||
extra_deps,
|
||||
)
|
||||
.await?;
|
||||
|
||||
let bin = build_container
|
||||
.with_exec(vec![
|
||||
"cargo",
|
||||
"build",
|
||||
"--target",
|
||||
&target.to_string(),
|
||||
"--release",
|
||||
"-p",
|
||||
bin_name,
|
||||
])
|
||||
.file(format!("target/{}/release/{}", target.to_string(), bin_name));
|
||||
|
||||
self.build_alpine_image(
|
||||
bin,
|
||||
image,
|
||||
BuildTarget::from_target(&container_image),
|
||||
deps.iter()
|
||||
.map(|d| d.as_str())
|
||||
.collect::<Vec<&str>>()
|
||||
.as_slice(),
|
||||
bin_name,
|
||||
)
|
||||
.await?
|
||||
}
|
||||
};
|
||||
|
||||
containers.push(container);
|
||||
}
|
||||
|
||||
Ok(containers)
|
||||
}
|
||||
|
||||
async fn build_debian_image(
|
||||
&self,
|
||||
builder_image: dagger_sdk::Container,
|
||||
image: &str,
|
||||
target: BuildTarget,
|
||||
production_deps: &[&str],
|
||||
bin_name: &str,
|
||||
) -> eyre::Result<dagger_sdk::Container> {
|
||||
let base_debian = self
|
||||
.client
|
||||
.container_opts(dagger_sdk::QueryContainerOpts {
|
||||
id: None,
|
||||
platform: Some(target.into_platform()),
|
||||
})
|
||||
.from(image);
|
||||
|
||||
let mut packages = vec!["apt", "install", "-y"];
|
||||
packages.extend_from_slice(production_deps);
|
||||
let base_debian = base_debian
|
||||
.with_exec(vec!["apt", "update"])
|
||||
.with_exec(packages);
|
||||
|
||||
let final_image = base_debian
|
||||
.with_workdir("/mnt/app")
|
||||
.with_file(
|
||||
format!("/mnt/app/{bin_name}"),
|
||||
builder_image.file(format!("/mnt/src/target/release/{bin_name}")),
|
||||
)
|
||||
.with_directory(
|
||||
"/mnt/app/target/site",
|
||||
builder_image.directory(format!("/mnt/src/target/site")),
|
||||
)
|
||||
.with_file(
|
||||
"/mnt/app/Cargo.toml",
|
||||
builder_image.file(format!("/mnt/src/crates/{bin_name}/Cargo.toml")),
|
||||
)
|
||||
.with_env_variable("RUST_LOG", "debug")
|
||||
.with_env_variable("APP_ENVIRONMENT", "production")
|
||||
.with_env_variable("LEPTOS_OUTPUT_NAME", bin_name)
|
||||
.with_env_variable("LEPTOS_SITE_ADDR", "0.0.0.0:8080")
|
||||
.with_env_variable("LEPTOS_SITE_ROOT", "site")
|
||||
.with_env_variable("LEPTOS_SITE_PKG_DIR", "pkg")
|
||||
.with_exposed_port(8080)
|
||||
.with_entrypoint(vec![format!("/mnt/app/{bin_name}")]);
|
||||
|
||||
final_image.sync().await?;
|
||||
|
||||
Ok(final_image)
|
||||
}
|
||||
|
||||
async fn build_alpine_image(
|
||||
&self,
|
||||
bin: dagger_sdk::File,
|
||||
image: &str,
|
||||
target: BuildTarget,
|
||||
production_deps: &[&str],
|
||||
bin_name: &str,
|
||||
) -> eyre::Result<dagger_sdk::Container> {
|
||||
let base_debian = self
|
||||
.client
|
||||
.container_opts(dagger_sdk::QueryContainerOpts {
|
||||
id: None,
|
||||
platform: Some(target.into_platform()),
|
||||
})
|
||||
.from(image);
|
||||
|
||||
let mut packages = vec!["apk", "add"];
|
||||
packages.extend_from_slice(production_deps);
|
||||
let base_debian = base_debian.with_exec(packages);
|
||||
|
||||
let final_image = base_debian.with_file(format!("/usr/local/bin/{}", bin_name), bin);
|
||||
|
||||
Ok(final_image)
|
||||
}
|
||||
}
|
@@ -1,3 +1,6 @@
|
||||
pub mod build;
|
||||
pub mod htmx;
|
||||
pub mod leptos;
|
||||
pub mod publish;
|
||||
pub mod source;
|
||||
pub mod test;
|
||||
|
40
crates/dagger-rust/src/publish.rs
Normal file
40
crates/dagger-rust/src/publish.rs
Normal file
@@ -0,0 +1,40 @@
|
||||
use std::sync::Arc;
|
||||
|
||||
pub struct RustPublish {
|
||||
client: Arc<dagger_sdk::Query>,
|
||||
}
|
||||
|
||||
impl RustPublish {
|
||||
pub fn new(client: Arc<dagger_sdk::Query>) -> Self {
|
||||
Self { client }
|
||||
}
|
||||
|
||||
pub async fn publish(
|
||||
&self,
|
||||
image: impl Into<String>,
|
||||
tag: impl Into<String>,
|
||||
containers: impl IntoIterator<Item = dagger_sdk::Container>,
|
||||
) -> eyre::Result<()> {
|
||||
let mut ids = Vec::new();
|
||||
for container in containers.into_iter() {
|
||||
let id = container.id().await?;
|
||||
ids.push(id);
|
||||
}
|
||||
|
||||
let image = self
|
||||
.client
|
||||
.container()
|
||||
.publish_opts(
|
||||
format!("{}:{}", image.into(), tag.into()),
|
||||
dagger_sdk::ContainerPublishOpts {
|
||||
platform_variants: Some(ids),
|
||||
forced_compression: None,
|
||||
media_types: None,
|
||||
},
|
||||
)
|
||||
.await?;
|
||||
println!("published: {}", image);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
@@ -6,13 +6,13 @@ use std::{
|
||||
use eyre::Context;
|
||||
|
||||
pub struct RustSource {
|
||||
client: Arc<dagger_sdk::Query>,
|
||||
client: dagger_sdk::Query,
|
||||
|
||||
exclude: Vec<String>,
|
||||
}
|
||||
|
||||
impl RustSource {
|
||||
pub fn new(client: Arc<dagger_sdk::Query>) -> Self {
|
||||
pub fn new(client: dagger_sdk::Query) -> Self {
|
||||
Self {
|
||||
client,
|
||||
exclude: vec!["node_modules/", ".git/", "target/", ".cuddle/"]
|
||||
@@ -63,7 +63,7 @@ impl RustSource {
|
||||
|
||||
let src = self.get_src(source.clone()).await?;
|
||||
let rust_src = self.get_rust_dep_src(source).await?;
|
||||
let rust_src = rust_src.with_directory(".", skeleton_files.id().await?);
|
||||
let rust_src = rust_src.with_directory(".", skeleton_files);
|
||||
|
||||
Ok((src, rust_src))
|
||||
}
|
||||
@@ -90,10 +90,14 @@ impl RustSource {
|
||||
) -> eyre::Result<dagger_sdk::Directory> {
|
||||
let source = source.map(|s| s.into()).unwrap_or(PathBuf::from("."));
|
||||
|
||||
let mut excludes = self.exclude.clone();
|
||||
excludes.push("**/src".to_string());
|
||||
|
||||
let directory = self.client.host().directory_opts(
|
||||
source.display().to_string(),
|
||||
dagger_sdk::HostDirectoryOptsBuilder::default()
|
||||
.include(vec!["**/Cargo.toml", "**/Cargo.lock"])
|
||||
//.include(vec!["**/Cargo.toml", "**/Cargo.lock"])
|
||||
.exclude(excludes.iter().map(|s| s.as_str()).collect::<Vec<_>>())
|
||||
.build()?,
|
||||
);
|
||||
|
||||
@@ -119,7 +123,7 @@ impl RustSource {
|
||||
|
||||
let incremental_dir = self.client.directory().with_directory_opts(
|
||||
".",
|
||||
container.directory("target").id().await?,
|
||||
container.directory("target"),
|
||||
dagger_sdk::DirectoryWithDirectoryOpts {
|
||||
exclude: Some(exclude),
|
||||
include: None,
|
||||
|
@@ -3,12 +3,12 @@ use std::{path::PathBuf, sync::Arc};
|
||||
use crate::{build::RustVersion, source::RustSource};
|
||||
|
||||
pub struct RustTest {
|
||||
client: Arc<dagger_sdk::Query>,
|
||||
client: dagger_sdk::Query,
|
||||
registry: Option<String>,
|
||||
}
|
||||
|
||||
impl RustTest {
|
||||
pub fn new(client: Arc<dagger_sdk::Query>) -> Self {
|
||||
pub fn new(client: dagger_sdk::Query) -> Self {
|
||||
Self {
|
||||
client,
|
||||
registry: None,
|
||||
@@ -45,9 +45,9 @@ impl RustTest {
|
||||
let build_options = vec!["cargo", "build", "--workspace"];
|
||||
let rust_prebuild = rust_build_image
|
||||
.with_workdir("/mnt/src")
|
||||
.with_directory("/mnt/src", dep_src.id().await?)
|
||||
.with_directory("/mnt/src", dep_src)
|
||||
.with_exec(build_options)
|
||||
.with_mounted_cache("/mnt/src/target/", target_cache.id().await?);
|
||||
.with_mounted_cache("/mnt/src/target/", target_cache);
|
||||
|
||||
let incremental_dir = rust_source
|
||||
.get_rust_target_src(&source, rust_prebuild.clone(), crates.to_vec())
|
||||
@@ -57,10 +57,10 @@ impl RustTest {
|
||||
.with_workdir("/mnt/src")
|
||||
.with_directory(
|
||||
"/usr/local/cargo",
|
||||
rust_prebuild.directory("/usr/local/cargo").id().await?,
|
||||
rust_prebuild.directory("/usr/local/cargo"),
|
||||
)
|
||||
.with_directory("/mnt/src/target", incremental_dir.id().await?)
|
||||
.with_directory("/mnt/src/", src.id().await?);
|
||||
.with_directory("/mnt/src/target", incremental_dir)
|
||||
.with_directory("/mnt/src/", src);
|
||||
|
||||
let test = rust_with_src.with_exec(vec!["cargo", "test"]);
|
||||
|
||||
@@ -68,9 +68,7 @@ impl RustTest {
|
||||
let stderr = test.stderr().await?;
|
||||
println!("stdout: {}, stderr: {}", stdout, stderr);
|
||||
|
||||
if 0 != test.exit_code().await? {
|
||||
eyre::bail!("failed rust:test");
|
||||
}
|
||||
test.sync().await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
@@ -4,7 +4,7 @@ use dagger_cuddle_please::{models::CuddlePleaseArgs, DaggerCuddlePleaseAction};
|
||||
pub async fn main() -> eyre::Result<()> {
|
||||
let client = dagger_sdk::connect().await?;
|
||||
|
||||
DaggerCuddlePleaseAction::dagger(client.clone())
|
||||
DaggerCuddlePleaseAction::dagger(client)
|
||||
.execute(&CuddlePleaseArgs {
|
||||
repository: "dagger-components".into(),
|
||||
owner: "kjuulh".into(),
|
||||
|
17
examples/htmx/Cargo.toml
Normal file
17
examples/htmx/Cargo.toml
Normal file
@@ -0,0 +1,17 @@
|
||||
[package]
|
||||
name = "htmx"
|
||||
version.workspace = true
|
||||
edition.workspace = true
|
||||
license.workspace = true
|
||||
authors.workspace = true
|
||||
readme.workspace = true
|
||||
repository.workspace = true
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
dagger-rust.workspace = true
|
||||
|
||||
eyre.workspace = true
|
||||
dagger-sdk.workspace = true
|
||||
tokio.workspace = true
|
16
examples/htmx/src/main.rs
Normal file
16
examples/htmx/src/main.rs
Normal file
@@ -0,0 +1,16 @@
|
||||
use std::path::PathBuf;
|
||||
|
||||
#[tokio::main]
|
||||
pub async fn main() -> eyre::Result<()> {
|
||||
let client = dagger_sdk::connect().await?;
|
||||
|
||||
let crates = ["some-crate"];
|
||||
let dag = dagger_rust::source::RustSource::new(client.clone());
|
||||
let (_src, _rust_src) = dag.get_rust_src(None::<PathBuf>, crates).await?;
|
||||
|
||||
let _full_src = dag
|
||||
.get_rust_target_src(&PathBuf::from("."), client.container(), crates)
|
||||
.await?;
|
||||
|
||||
Ok(())
|
||||
}
|
13
examples/leptos-build/Cargo.toml
Normal file
13
examples/leptos-build/Cargo.toml
Normal file
@@ -0,0 +1,13 @@
|
||||
[package]
|
||||
name = "leptos-build"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
dagger-rust.workspace = true
|
||||
|
||||
eyre.workspace = true
|
||||
dagger-sdk.workspace = true
|
||||
tokio.workspace = true
|
97
examples/leptos-build/output/Cargo.toml
Normal file
97
examples/leptos-build/output/Cargo.toml
Normal file
@@ -0,0 +1,97 @@
|
||||
[package]
|
||||
name = "hackernews_axum"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
[lib]
|
||||
crate-type = ["cdylib", "rlib"]
|
||||
|
||||
[profile.release]
|
||||
codegen-units = 1
|
||||
lto = true
|
||||
|
||||
[dependencies]
|
||||
console_log = "1.0.0"
|
||||
console_error_panic_hook = "0.1.7"
|
||||
cfg-if = "1.0.0"
|
||||
leptos = { version = "0.5.1", features = ["nightly"] }
|
||||
leptos_axum = { version = "0.5.1", optional = true }
|
||||
leptos_meta = { version = "0.5.1", features = ["nightly"] }
|
||||
leptos_router = { version = "0.5.1", features = ["nightly"] }
|
||||
log = "0.4.17"
|
||||
simple_logger = "4.0.0"
|
||||
serde = { version = "1.0.148", features = ["derive"] }
|
||||
tracing = "0.1"
|
||||
gloo-net = { version = "0.2.5", features = ["http"] }
|
||||
reqwest = { version = "0.11.13", features = ["json"] }
|
||||
axum = { version = "0.6.1", optional = true }
|
||||
tower = { version = "0.4.13", optional = true }
|
||||
tower-http = { version = "0.4", features = ["fs"], optional = true }
|
||||
tokio = { version = "1.22.0", features = ["full"], optional = true }
|
||||
http = { version = "0.2.8", optional = true }
|
||||
web-sys = { version = "0.3", features = ["AbortController", "AbortSignal"] }
|
||||
wasm-bindgen = "0.2"
|
||||
|
||||
[features]
|
||||
default = ["csr"]
|
||||
csr = ["leptos/csr", "leptos_meta/csr", "leptos_router/csr"]
|
||||
hydrate = ["leptos/hydrate", "leptos_meta/hydrate", "leptos_router/hydrate"]
|
||||
ssr = [
|
||||
"dep:axum",
|
||||
"dep:tower",
|
||||
"dep:tower-http",
|
||||
"dep:tokio",
|
||||
"dep:http",
|
||||
"leptos/ssr",
|
||||
"leptos_axum",
|
||||
"leptos_meta/ssr",
|
||||
"leptos_router/ssr",
|
||||
]
|
||||
|
||||
[package.metadata.cargo-all-features]
|
||||
denylist = ["axum", "tower", "tower-http", "tokio", "http", "leptos_axum"]
|
||||
skip_feature_sets = [["csr", "ssr"], ["csr", "hydrate"], ["ssr", "hydrate"]]
|
||||
|
||||
[package.metadata.leptos]
|
||||
# The name used by wasm-bindgen/cargo-leptos for the JS/WASM bundle. Defaults to the crate name
|
||||
output-name = "hackernews_axum"
|
||||
# The site root folder is where cargo-leptos generate all output. WARNING: all content of this folder will be erased on a rebuild. Use it in your server setup.
|
||||
site-root = "target/site"
|
||||
# The site-root relative folder where all compiled output (JS, WASM and CSS) is written
|
||||
# Defaults to pkg
|
||||
site-pkg-dir = "pkg"
|
||||
# [Optional] The source CSS file. If it ends with .sass or .scss then it will be compiled by dart-sass into CSS. The CSS is optimized by Lightning CSS before being written to <site-root>/<site-pkg>/app.css
|
||||
style-file = "./style.css"
|
||||
# [Optional] Files in the asset-dir will be copied to the site-root directory
|
||||
assets-dir = "public"
|
||||
# The IP and port (ex: 127.0.0.1:3000) where the server serves the content. Use it in your server setup.
|
||||
site-addr = "0.0.0.0:8080"
|
||||
# The port to use for automatic reload monitoring
|
||||
reload-port = 3001
|
||||
# [Optional] Command to use when running end2end tests. It will run in the end2end dir.
|
||||
end2end-cmd = "npx playwright test"
|
||||
# The browserlist query used for optimizing the CSS.
|
||||
browserquery = "defaults"
|
||||
# Set by cargo-leptos watch when building with tha tool. Controls whether autoreload JS will be included in the head
|
||||
watch = false
|
||||
# The environment Leptos will run in, usually either "DEV" or "PROD"
|
||||
env = "DEV"
|
||||
# The features to use when compiling the bin target
|
||||
#
|
||||
# Optional. Can be over-ridden with the command line parameter --bin-features
|
||||
bin-features = ["ssr"]
|
||||
|
||||
# If the --no-default-features flag should be used when compiling the bin target
|
||||
#
|
||||
# Optional. Defaults to false.
|
||||
bin-default-features = false
|
||||
|
||||
# The features to use when compiling the lib target
|
||||
#
|
||||
# Optional. Can be over-ridden with the command line parameter --lib-features
|
||||
lib-features = ["hydrate"]
|
||||
|
||||
# If the --no-default-features flag should be used when compiling the lib target
|
||||
#
|
||||
# Optional. Defaults to false.
|
||||
lib-default-features = false
|
BIN
examples/leptos-build/output/hackernews_axum
Executable file
BIN
examples/leptos-build/output/hackernews_axum
Executable file
Binary file not shown.
62
examples/leptos-build/src/main.rs
Normal file
62
examples/leptos-build/src/main.rs
Normal file
@@ -0,0 +1,62 @@
|
||||
use dagger_rust::build::{BuildProfile, RustVersion, SlimImage};
|
||||
|
||||
#[tokio::main]
|
||||
pub async fn main() -> eyre::Result<()> {
|
||||
let client = dagger_sdk::connect().await?;
|
||||
|
||||
let rust_build = dagger_rust::leptos::LeptosBuild::new(client.clone());
|
||||
|
||||
let containers = rust_build
|
||||
.build_release(
|
||||
Some("testdata"),
|
||||
RustVersion::Nightly,
|
||||
&["crates/*"],
|
||||
&[
|
||||
"openssl",
|
||||
"libssl-dev",
|
||||
"pkg-config",
|
||||
"musl-tools",
|
||||
"ca-certificates",
|
||||
],
|
||||
vec![SlimImage::Debian {
|
||||
image: "debian:bullseye".into(),
|
||||
deps: vec![
|
||||
"openssl".into(),
|
||||
"libssl-dev".into(),
|
||||
"pkg-config".into(),
|
||||
"musl-tools".into(),
|
||||
"ca-certificates".into(),
|
||||
],
|
||||
architecture: dagger_rust::build::BuildArchitecture::Amd64,
|
||||
}],
|
||||
"hackernews_axum",
|
||||
)
|
||||
.await?;
|
||||
|
||||
let container = containers.first().unwrap();
|
||||
|
||||
container.directory("/mnt/app").export("output").await?;
|
||||
|
||||
let tunnel = client.host().tunnel(
|
||||
container
|
||||
.with_env_variable("LEPTOS_SITE_ADDR", "0.0.0.0:8080")
|
||||
.with_exec(vec!["/mnt/app/hackernews_axum"])
|
||||
.as_service(),
|
||||
);
|
||||
|
||||
tunnel.start().await?;
|
||||
|
||||
let endpoint = tunnel
|
||||
.endpoint_opts(
|
||||
dagger_sdk::ServiceEndpointOptsBuilder::default()
|
||||
.scheme("http")
|
||||
.build()?,
|
||||
)
|
||||
.await?;
|
||||
|
||||
println!("running on: {endpoint}, press enter to stop");
|
||||
|
||||
std::io::stdin().read_line(&mut String::new()).unwrap();
|
||||
|
||||
Ok(())
|
||||
}
|
2809
examples/leptos-build/testdata/Cargo.lock
generated
vendored
Normal file
2809
examples/leptos-build/testdata/Cargo.lock
generated
vendored
Normal file
File diff suppressed because it is too large
Load Diff
56
examples/leptos-build/testdata/Cargo.toml
vendored
Normal file
56
examples/leptos-build/testdata/Cargo.toml
vendored
Normal file
@@ -0,0 +1,56 @@
|
||||
[workspace]
|
||||
members = ["crates/*"]
|
||||
resolver = "2"
|
||||
|
||||
[profile.release]
|
||||
codegen-units = 1
|
||||
lto = true
|
||||
|
||||
[[workspace.metadata.leptos]]
|
||||
name = "hackernews_axum"
|
||||
bin-package = "hackernews_axum"
|
||||
lib-package = "hackernews_axum"
|
||||
|
||||
# The name used by wasm-bindgen/cargo-leptos for the JS/WASM bundle. Defaults to the crate name
|
||||
output-name = "hackernews_axum"
|
||||
|
||||
# The site root folder is where cargo-leptos generate all output. WARNING: all content of this folder will be erased on a rebuild. Use it in your server setup.
|
||||
site-root = "target/site"
|
||||
# The site-root relative folder where all compiled output (JS, WASM and CSS) is written
|
||||
# Defaults to pkg
|
||||
site-pkg-dir = "pkg"
|
||||
# [Optional] The source CSS file. If it ends with .sass or .scss then it will be compiled by dart-sass into CSS. The CSS is optimized by Lightning CSS before being written to <site-root>/<site-pkg>/app.css
|
||||
style-file = "./crates/hackernews_axum/style.css"
|
||||
# [Optional] Files in the asset-dir will be copied to the site-root directory
|
||||
assets-dir = "./crates/hackernews_axum/public"
|
||||
# The IP and port (ex: 127.0.0.1:3000) where the server serves the content. Use it in your server setup.
|
||||
site-addr = "0.0.0.0:8080"
|
||||
# The port to use for automatic reload monitoring
|
||||
reload-port = 3001
|
||||
# [Optional] Command to use when running end2end tests. It will run in the end2end dir.
|
||||
end2end-cmd = "npx playwright test"
|
||||
# The browserlist query used for optimizing the CSS.
|
||||
browserquery = "defaults"
|
||||
# Set by cargo-leptos watch when building with tha tool. Controls whether autoreload JS will be included in the head
|
||||
watch = false
|
||||
# The environment Leptos will run in, usually either "DEV" or "PROD"
|
||||
env = "DEV"
|
||||
# The features to use when compiling the bin target
|
||||
#
|
||||
# Optional. Can be over-ridden with the command line parameter --bin-features
|
||||
bin-features = ["ssr"]
|
||||
|
||||
# If the --no-default-features flag should be used when compiling the bin target
|
||||
#
|
||||
# Optional. Defaults to false.
|
||||
bin-default-features = false
|
||||
|
||||
# The features to use when compiling the lib target
|
||||
#
|
||||
# Optional. Can be over-ridden with the command line parameter --lib-features
|
||||
lib-features = ["hydrate"]
|
||||
|
||||
# If the --no-default-features flag should be used when compiling the lib target
|
||||
#
|
||||
# Optional. Defaults to false.
|
||||
lib-default-features = false
|
1
examples/leptos-build/testdata/crates/hackernews_axum/.gitignore
vendored
Normal file
1
examples/leptos-build/testdata/crates/hackernews_axum/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
/target
|
97
examples/leptos-build/testdata/crates/hackernews_axum/Cargo.toml
vendored
Normal file
97
examples/leptos-build/testdata/crates/hackernews_axum/Cargo.toml
vendored
Normal file
@@ -0,0 +1,97 @@
|
||||
[package]
|
||||
name = "hackernews_axum"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
[lib]
|
||||
crate-type = ["cdylib", "rlib"]
|
||||
|
||||
[profile.release]
|
||||
codegen-units = 1
|
||||
lto = true
|
||||
|
||||
[dependencies]
|
||||
console_log = "1.0.0"
|
||||
console_error_panic_hook = "0.1.7"
|
||||
cfg-if = "1.0.0"
|
||||
leptos = { version = "0.5.1", features = ["nightly"] }
|
||||
leptos_axum = { version = "0.5.1", optional = true }
|
||||
leptos_meta = { version = "0.5.1", features = ["nightly"] }
|
||||
leptos_router = { version = "0.5.1", features = ["nightly"] }
|
||||
log = "0.4.17"
|
||||
simple_logger = "4.0.0"
|
||||
serde = { version = "1.0.148", features = ["derive"] }
|
||||
tracing = "0.1"
|
||||
gloo-net = { version = "0.2.5", features = ["http"] }
|
||||
reqwest = { version = "0.11.13", features = ["json"] }
|
||||
axum = { version = "0.6.1", optional = true }
|
||||
tower = { version = "0.4.13", optional = true }
|
||||
tower-http = { version = "0.4", features = ["fs"], optional = true }
|
||||
tokio = { version = "1.22.0", features = ["full"], optional = true }
|
||||
http = { version = "0.2.8", optional = true }
|
||||
web-sys = { version = "0.3", features = ["AbortController", "AbortSignal"] }
|
||||
wasm-bindgen = "0.2"
|
||||
|
||||
[features]
|
||||
default = ["csr"]
|
||||
csr = ["leptos/csr", "leptos_meta/csr", "leptos_router/csr"]
|
||||
hydrate = ["leptos/hydrate", "leptos_meta/hydrate", "leptos_router/hydrate"]
|
||||
ssr = [
|
||||
"dep:axum",
|
||||
"dep:tower",
|
||||
"dep:tower-http",
|
||||
"dep:tokio",
|
||||
"dep:http",
|
||||
"leptos/ssr",
|
||||
"leptos_axum",
|
||||
"leptos_meta/ssr",
|
||||
"leptos_router/ssr",
|
||||
]
|
||||
|
||||
[package.metadata.cargo-all-features]
|
||||
denylist = ["axum", "tower", "tower-http", "tokio", "http", "leptos_axum"]
|
||||
skip_feature_sets = [["csr", "ssr"], ["csr", "hydrate"], ["ssr", "hydrate"]]
|
||||
|
||||
[package.metadata.leptos]
|
||||
# The name used by wasm-bindgen/cargo-leptos for the JS/WASM bundle. Defaults to the crate name
|
||||
output-name = "hackernews_axum"
|
||||
# The site root folder is where cargo-leptos generate all output. WARNING: all content of this folder will be erased on a rebuild. Use it in your server setup.
|
||||
site-root = "target/site"
|
||||
# The site-root relative folder where all compiled output (JS, WASM and CSS) is written
|
||||
# Defaults to pkg
|
||||
site-pkg-dir = "pkg"
|
||||
# [Optional] The source CSS file. If it ends with .sass or .scss then it will be compiled by dart-sass into CSS. The CSS is optimized by Lightning CSS before being written to <site-root>/<site-pkg>/app.css
|
||||
style-file = "./style.css"
|
||||
# [Optional] Files in the asset-dir will be copied to the site-root directory
|
||||
assets-dir = "public"
|
||||
# The IP and port (ex: 127.0.0.1:3000) where the server serves the content. Use it in your server setup.
|
||||
site-addr = "0.0.0.0:8080"
|
||||
# The port to use for automatic reload monitoring
|
||||
reload-port = 3001
|
||||
# [Optional] Command to use when running end2end tests. It will run in the end2end dir.
|
||||
end2end-cmd = "npx playwright test"
|
||||
# The browserlist query used for optimizing the CSS.
|
||||
browserquery = "defaults"
|
||||
# Set by cargo-leptos watch when building with tha tool. Controls whether autoreload JS will be included in the head
|
||||
watch = false
|
||||
# The environment Leptos will run in, usually either "DEV" or "PROD"
|
||||
env = "DEV"
|
||||
# The features to use when compiling the bin target
|
||||
#
|
||||
# Optional. Can be over-ridden with the command line parameter --bin-features
|
||||
bin-features = ["ssr"]
|
||||
|
||||
# If the --no-default-features flag should be used when compiling the bin target
|
||||
#
|
||||
# Optional. Defaults to false.
|
||||
bin-default-features = false
|
||||
|
||||
# The features to use when compiling the lib target
|
||||
#
|
||||
# Optional. Can be over-ridden with the command line parameter --lib-features
|
||||
lib-features = ["hydrate"]
|
||||
|
||||
# If the --no-default-features flag should be used when compiling the lib target
|
||||
#
|
||||
# Optional. Defaults to false.
|
||||
lib-default-features = false
|
21
examples/leptos-build/testdata/crates/hackernews_axum/LICENSE
vendored
Normal file
21
examples/leptos-build/testdata/crates/hackernews_axum/LICENSE
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2022 Greg Johnston
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
8
examples/leptos-build/testdata/crates/hackernews_axum/Makefile.toml
vendored
Normal file
8
examples/leptos-build/testdata/crates/hackernews_axum/Makefile.toml
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
extend = [
|
||||
{ path = "../cargo-make/main.toml" },
|
||||
{ path = "../cargo-make/cargo-leptos.toml" },
|
||||
]
|
||||
|
||||
[env]
|
||||
|
||||
CLIENT_PROCESS_NAME = "hackernews_axum"
|
7
examples/leptos-build/testdata/crates/hackernews_axum/README.md
vendored
Normal file
7
examples/leptos-build/testdata/crates/hackernews_axum/README.md
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
# Leptos Hacker News Example with Axum
|
||||
|
||||
This example creates a basic clone of the Hacker News site. It showcases Leptos' ability to create both a client-side rendered app, and a server side rendered app with hydration, in a single repository. This repo differs from the main Hacker News example by using Axum as it's server.
|
||||
|
||||
## Getting Started
|
||||
|
||||
See the [Examples README](../README.md) for setup and run instructions.
|
8
examples/leptos-build/testdata/crates/hackernews_axum/index.html
vendored
Normal file
8
examples/leptos-build/testdata/crates/hackernews_axum/index.html
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<link data-trunk rel="rust" data-wasm-opt="z"/>
|
||||
<link data-trunk rel="css" href="/style.css"/>
|
||||
</head>
|
||||
<body></body>
|
||||
</html>
|
BIN
examples/leptos-build/testdata/crates/hackernews_axum/public/favicon.ico
vendored
Normal file
BIN
examples/leptos-build/testdata/crates/hackernews_axum/public/favicon.ico
vendored
Normal file
Binary file not shown.
After Width: | Height: | Size: 15 KiB |
90
examples/leptos-build/testdata/crates/hackernews_axum/src/api.rs
vendored
Normal file
90
examples/leptos-build/testdata/crates/hackernews_axum/src/api.rs
vendored
Normal file
@@ -0,0 +1,90 @@
|
||||
use leptos::Serializable;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
pub fn story(path: &str) -> String {
|
||||
format!("https://node-hnapi.herokuapp.com/{path}")
|
||||
}
|
||||
|
||||
pub fn user(path: &str) -> String {
|
||||
format!("https://hacker-news.firebaseio.com/v0/user/{path}.json")
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "ssr"))]
|
||||
pub async fn fetch_api<T>(path: &str) -> Option<T>
|
||||
where
|
||||
T: Serializable,
|
||||
{
|
||||
let abort_controller = web_sys::AbortController::new().ok();
|
||||
let abort_signal = abort_controller.as_ref().map(|a| a.signal());
|
||||
|
||||
// abort in-flight requests if e.g., we've navigated away from this page
|
||||
leptos::on_cleanup(move || {
|
||||
if let Some(abort_controller) = abort_controller {
|
||||
abort_controller.abort()
|
||||
}
|
||||
});
|
||||
|
||||
let json = gloo_net::http::Request::get(path)
|
||||
.abort_signal(abort_signal.as_ref())
|
||||
.send()
|
||||
.await
|
||||
.map_err(|e| log::error!("{e}"))
|
||||
.ok()?
|
||||
.text()
|
||||
.await
|
||||
.ok()?;
|
||||
|
||||
T::de(&json).ok()
|
||||
}
|
||||
|
||||
#[cfg(feature = "ssr")]
|
||||
pub async fn fetch_api<T>(path: &str) -> Option<T>
|
||||
where
|
||||
T: Serializable,
|
||||
{
|
||||
let json = reqwest::get(path)
|
||||
.await
|
||||
.map_err(|e| log::error!("{e}"))
|
||||
.ok()?
|
||||
.text()
|
||||
.await
|
||||
.ok()?;
|
||||
T::de(&json).map_err(|e| log::error!("{e}")).ok()
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize, Serialize, PartialEq, Eq, Clone)]
|
||||
pub struct Story {
|
||||
pub id: usize,
|
||||
pub title: String,
|
||||
pub points: Option<i32>,
|
||||
pub user: Option<String>,
|
||||
pub time: usize,
|
||||
pub time_ago: String,
|
||||
#[serde(alias = "type")]
|
||||
pub story_type: String,
|
||||
pub url: String,
|
||||
#[serde(default)]
|
||||
pub domain: String,
|
||||
#[serde(default)]
|
||||
pub comments: Option<Vec<Comment>>,
|
||||
pub comments_count: Option<usize>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize, Serialize, PartialEq, Eq, Clone)]
|
||||
pub struct Comment {
|
||||
pub id: usize,
|
||||
pub level: usize,
|
||||
pub user: Option<String>,
|
||||
pub time: usize,
|
||||
pub time_ago: String,
|
||||
pub content: Option<String>,
|
||||
pub comments: Vec<Comment>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize, Serialize, PartialEq, Eq, Clone)]
|
||||
pub struct User {
|
||||
pub created: usize,
|
||||
pub id: String,
|
||||
pub karma: i32,
|
||||
pub about: Option<String>,
|
||||
}
|
28
examples/leptos-build/testdata/crates/hackernews_axum/src/error_template.rs
vendored
Normal file
28
examples/leptos-build/testdata/crates/hackernews_axum/src/error_template.rs
vendored
Normal file
@@ -0,0 +1,28 @@
|
||||
use leptos::{view, Errors, For, IntoView, RwSignal, View};
|
||||
|
||||
// A basic function to display errors served by the error boundaries. Feel free to do more complicated things
|
||||
// here than just displaying them
|
||||
pub fn error_template(errors: Option<RwSignal<Errors>>) -> View {
|
||||
let Some(errors) = errors else {
|
||||
panic!("No Errors found and we expected errors!");
|
||||
};
|
||||
|
||||
view! {
|
||||
<h1>"Errors"</h1>
|
||||
<For
|
||||
// a function that returns the items we're iterating over; a signal is fine
|
||||
each=errors
|
||||
// a unique key for each item as a reference
|
||||
key=|(key, _)| key.clone()
|
||||
// renders each item to a view
|
||||
children=move | (_, error)| {
|
||||
let error_string = error.to_string();
|
||||
view! {
|
||||
|
||||
<p>"Error: " {error_string}</p>
|
||||
}
|
||||
}
|
||||
/>
|
||||
}
|
||||
.into_view()
|
||||
}
|
44
examples/leptos-build/testdata/crates/hackernews_axum/src/fallback.rs
vendored
Normal file
44
examples/leptos-build/testdata/crates/hackernews_axum/src/fallback.rs
vendored
Normal file
@@ -0,0 +1,44 @@
|
||||
use cfg_if::cfg_if;
|
||||
|
||||
cfg_if! {
|
||||
if #[cfg(feature = "ssr")] {
|
||||
use axum::{
|
||||
body::{boxed, Body, BoxBody},
|
||||
extract::State,
|
||||
response::IntoResponse,
|
||||
http::{Request, Response, StatusCode, Uri},
|
||||
};
|
||||
use axum::response::Response as AxumResponse;
|
||||
use tower::ServiceExt;
|
||||
use tower_http::services::ServeDir;
|
||||
use leptos::{LeptosOptions};
|
||||
use crate::error_template::error_template;
|
||||
|
||||
pub async fn file_and_error_handler(uri: Uri, State(options): State<LeptosOptions>, req: Request<Body>) -> AxumResponse {
|
||||
let root = options.site_root.clone();
|
||||
let res = get_static_file(uri.clone(), &root).await.unwrap();
|
||||
|
||||
if res.status() == StatusCode::OK {
|
||||
res.into_response()
|
||||
} else{
|
||||
let handler = leptos_axum::render_app_to_stream(options.to_owned(), || error_template( None));
|
||||
handler(req).await.into_response()
|
||||
}
|
||||
}
|
||||
|
||||
async fn get_static_file(uri: Uri, root: &str) -> Result<Response<BoxBody>, (StatusCode, String)> {
|
||||
let req = Request::builder().uri(uri.clone()).body(Body::empty()).unwrap();
|
||||
// `ServeDir` implements `tower::Service` so we can call it with `tower::ServiceExt::oneshot`
|
||||
// This path is relative to the cargo root
|
||||
match ServeDir::new(root).oneshot(req).await {
|
||||
Ok(res) => Ok(res.map(boxed)),
|
||||
Err(err) => Err((
|
||||
StatusCode::INTERNAL_SERVER_ERROR,
|
||||
format!("Something went wrong: {}", err),
|
||||
)),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
63
examples/leptos-build/testdata/crates/hackernews_axum/src/handlers.rs
vendored
Normal file
63
examples/leptos-build/testdata/crates/hackernews_axum/src/handlers.rs
vendored
Normal file
@@ -0,0 +1,63 @@
|
||||
use cfg_if::cfg_if;
|
||||
|
||||
cfg_if! {
|
||||
if #[cfg(feature = "ssr")] {
|
||||
use axum::{
|
||||
body::{boxed, Body, BoxBody},
|
||||
http::{Request, Response, StatusCode, Uri},
|
||||
};
|
||||
use tower::ServiceExt;
|
||||
use tower_http::services::ServeDir;
|
||||
|
||||
pub async fn file_handler(uri: Uri) -> Result<Response<BoxBody>, (StatusCode, String)> {
|
||||
let res = get_static_file(uri.clone(), "/pkg").await?;
|
||||
|
||||
if res.status() == StatusCode::NOT_FOUND {
|
||||
// try with `.html`
|
||||
// TODO: handle if the Uri has query parameters
|
||||
match format!("{}.html", uri).parse() {
|
||||
Ok(uri_html) => get_static_file(uri_html, "/pkg").await,
|
||||
Err(_) => Err((StatusCode::INTERNAL_SERVER_ERROR, "Invalid URI".to_string())),
|
||||
}
|
||||
} else {
|
||||
Ok(res)
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn get_static_file_handler(uri: Uri) -> Result<Response<BoxBody>, (StatusCode, String)> {
|
||||
let res = get_static_file(uri.clone(), "/static").await?;
|
||||
|
||||
if res.status() == StatusCode::NOT_FOUND {
|
||||
Err((StatusCode::INTERNAL_SERVER_ERROR, "Invalid URI".to_string()))
|
||||
} else {
|
||||
Ok(res)
|
||||
}
|
||||
}
|
||||
|
||||
async fn get_static_file(uri: Uri, base: &str) -> Result<Response<BoxBody>, (StatusCode, String)> {
|
||||
let req = Request::builder().uri(&uri).body(Body::empty()).unwrap();
|
||||
|
||||
// `ServeDir` implements `tower::Service` so we can call it with `tower::ServiceExt::oneshot`
|
||||
// When run normally, the root should be the crate root
|
||||
if base == "/static" {
|
||||
match ServeDir::new("./static").oneshot(req).await {
|
||||
Ok(res) => Ok(res.map(boxed)),
|
||||
Err(err) => Err((
|
||||
StatusCode::INTERNAL_SERVER_ERROR,
|
||||
format!("Something went wrong: {}", err),
|
||||
))
|
||||
}
|
||||
} else if base == "/pkg" {
|
||||
match ServeDir::new("./pkg").oneshot(req).await {
|
||||
Ok(res) => Ok(res.map(boxed)),
|
||||
Err(err) => Err((
|
||||
StatusCode::INTERNAL_SERVER_ERROR,
|
||||
format!("Something went wrong: {}", err),
|
||||
)),
|
||||
}
|
||||
} else{
|
||||
Err((StatusCode::NOT_FOUND, "Not Found".to_string()))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
49
examples/leptos-build/testdata/crates/hackernews_axum/src/lib.rs
vendored
Normal file
49
examples/leptos-build/testdata/crates/hackernews_axum/src/lib.rs
vendored
Normal file
@@ -0,0 +1,49 @@
|
||||
use cfg_if::cfg_if;
|
||||
use leptos::{component, view, IntoView};
|
||||
use leptos_meta::*;
|
||||
use leptos_router::*;
|
||||
mod api;
|
||||
pub mod error_template;
|
||||
pub mod fallback;
|
||||
pub mod handlers;
|
||||
mod routes;
|
||||
use routes::{nav::*, stories::*, story::*, users::*};
|
||||
|
||||
#[component]
|
||||
pub fn App() -> impl IntoView {
|
||||
provide_meta_context();
|
||||
view! {
|
||||
|
||||
<>
|
||||
<Link rel="shortcut icon" type_="image/ico" href="/favicon.ico"/>
|
||||
<Stylesheet id="leptos" href="/pkg/hackernews_axum.css"/>
|
||||
<Meta name="description" content="Leptos implementation of a HackerNews demo."/>
|
||||
<Router>
|
||||
<Nav />
|
||||
<main>
|
||||
<Routes>
|
||||
<Route path="users/:id" view=User/>
|
||||
<Route path="stories/:id" view=Story/>
|
||||
<Route path=":stories?" view=Stories/>
|
||||
</Routes>
|
||||
</main>
|
||||
</Router>
|
||||
</>
|
||||
}
|
||||
}
|
||||
|
||||
// Needs to be in lib.rs AFAIK because wasm-bindgen needs us to be compiling a lib. I may be wrong.
|
||||
cfg_if! {
|
||||
if #[cfg(feature = "hydrate")] {
|
||||
use wasm_bindgen::prelude::wasm_bindgen;
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub fn hydrate() {
|
||||
_ = console_log::init_with_level(log::Level::Debug);
|
||||
console_error_panic_hook::set_once();
|
||||
leptos::mount_to_body(move || {
|
||||
view! { <App/> }
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
54
examples/leptos-build/testdata/crates/hackernews_axum/src/main.rs
vendored
Normal file
54
examples/leptos-build/testdata/crates/hackernews_axum/src/main.rs
vendored
Normal file
@@ -0,0 +1,54 @@
|
||||
use cfg_if::cfg_if;
|
||||
use leptos::{logging::log, *};
|
||||
|
||||
// boilerplate to run in different modes
|
||||
cfg_if! {
|
||||
if #[cfg(feature = "ssr")] {
|
||||
use axum::{
|
||||
Router,
|
||||
routing::get,
|
||||
};
|
||||
use leptos_axum::{generate_route_list, LeptosRoutes};
|
||||
use hackernews_axum::fallback::file_and_error_handler;
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() {
|
||||
use hackernews_axum::*;
|
||||
|
||||
let conf = get_configuration(Some("Cargo.toml")).await.unwrap();
|
||||
let leptos_options = conf.leptos_options;
|
||||
let addr = leptos_options.site_addr;
|
||||
let routes = generate_route_list(App);
|
||||
|
||||
simple_logger::init_with_level(log::Level::Debug).expect("couldn't initialize logging");
|
||||
|
||||
// build our application with a route
|
||||
let app = Router::new()
|
||||
.route("/favicon.ico", get(file_and_error_handler))
|
||||
.leptos_routes(&leptos_options, routes, || view! { <App/> } )
|
||||
.fallback(file_and_error_handler)
|
||||
.with_state(leptos_options);
|
||||
|
||||
// run our app with hyper
|
||||
// `axum::Server` is a re-export of `hyper::Server`
|
||||
log!("listening on {}", addr);
|
||||
axum::Server::bind(&addr)
|
||||
.serve(app.into_make_service())
|
||||
.await
|
||||
.unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
// client-only stuff for Trunk
|
||||
else {
|
||||
use hackernews_axum::*;
|
||||
|
||||
pub fn main() {
|
||||
_ = console_log::init_with_level(log::Level::Debug);
|
||||
console_error_panic_hook::set_once();
|
||||
mount_to_body(|| {
|
||||
view! { <App/> }
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
4
examples/leptos-build/testdata/crates/hackernews_axum/src/routes.rs
vendored
Normal file
4
examples/leptos-build/testdata/crates/hackernews_axum/src/routes.rs
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
pub mod nav;
|
||||
pub mod stories;
|
||||
pub mod story;
|
||||
pub mod users;
|
30
examples/leptos-build/testdata/crates/hackernews_axum/src/routes/nav.rs
vendored
Normal file
30
examples/leptos-build/testdata/crates/hackernews_axum/src/routes/nav.rs
vendored
Normal file
@@ -0,0 +1,30 @@
|
||||
use leptos::{component, view, IntoView};
|
||||
use leptos_router::*;
|
||||
|
||||
#[component]
|
||||
pub fn Nav() -> impl IntoView {
|
||||
view! {
|
||||
<header class="header">
|
||||
<nav class="inner">
|
||||
<A href="/">
|
||||
<strong>"HN"</strong>
|
||||
</A>
|
||||
<A href="/new">
|
||||
<strong>"New"</strong>
|
||||
</A>
|
||||
<A href="/show">
|
||||
<strong>"Show"</strong>
|
||||
</A>
|
||||
<A href="/ask">
|
||||
<strong>"Ask"</strong>
|
||||
</A>
|
||||
<A href="/job">
|
||||
<strong>"Jobs"</strong>
|
||||
</A>
|
||||
<a class="github" href="http://github.com/leptos-rs/leptos" target="_blank" rel="noreferrer">
|
||||
"Built with Leptos"
|
||||
</a>
|
||||
</nav>
|
||||
</header>
|
||||
}
|
||||
}
|
156
examples/leptos-build/testdata/crates/hackernews_axum/src/routes/stories.rs
vendored
Normal file
156
examples/leptos-build/testdata/crates/hackernews_axum/src/routes/stories.rs
vendored
Normal file
@@ -0,0 +1,156 @@
|
||||
use crate::api;
|
||||
use leptos::*;
|
||||
use leptos_router::*;
|
||||
|
||||
fn category(from: &str) -> &'static str {
|
||||
match from {
|
||||
"new" => "newest",
|
||||
"show" => "show",
|
||||
"ask" => "ask",
|
||||
"job" => "jobs",
|
||||
_ => "news",
|
||||
}
|
||||
}
|
||||
|
||||
#[component]
|
||||
pub fn Stories() -> impl IntoView {
|
||||
let query = use_query_map();
|
||||
let params = use_params_map();
|
||||
let page = move || {
|
||||
query
|
||||
.with(|q| q.get("page").and_then(|page| page.parse::<usize>().ok()))
|
||||
.unwrap_or(1)
|
||||
};
|
||||
let story_type = move || {
|
||||
params
|
||||
.with(|p| p.get("stories").cloned())
|
||||
.unwrap_or_else(|| "top".to_string())
|
||||
};
|
||||
let stories = create_resource(
|
||||
move || (page(), story_type()),
|
||||
move |(page, story_type)| async move {
|
||||
let path = format!("{}?page={}", category(&story_type), page);
|
||||
api::fetch_api::<Vec<api::Story>>(&api::story(&path)).await
|
||||
},
|
||||
);
|
||||
let (pending, set_pending) = create_signal(false);
|
||||
|
||||
let hide_more_link = move || {
|
||||
stories.get().unwrap_or(None).unwrap_or_default().len() < 28
|
||||
|| pending()
|
||||
};
|
||||
|
||||
view! {
|
||||
<div class="news-view">
|
||||
<div class="news-list-nav">
|
||||
<span>
|
||||
{move || if page() > 1 {
|
||||
view! {
|
||||
|
||||
<a class="page-link"
|
||||
href=move || format!("/{}?page={}", story_type(), page() - 1)
|
||||
attr:aria_label="Previous Page"
|
||||
>
|
||||
"< prev"
|
||||
</a>
|
||||
}.into_any()
|
||||
} else {
|
||||
view! {
|
||||
|
||||
<span class="page-link disabled" aria-hidden="true">
|
||||
"< prev"
|
||||
</span>
|
||||
}.into_any()
|
||||
}}
|
||||
</span>
|
||||
<span>"page " {page}</span>
|
||||
<span class="page-link"
|
||||
class:disabled=hide_more_link
|
||||
aria-hidden=hide_more_link
|
||||
>
|
||||
<a href=move || format!("/{}?page={}", story_type(), page() + 1)
|
||||
aria-label="Next Page"
|
||||
>
|
||||
"more >"
|
||||
</a>
|
||||
</span>
|
||||
</div>
|
||||
<main class="news-list">
|
||||
<div>
|
||||
<Transition
|
||||
fallback=move || view! { <p>"Loading..."</p> }
|
||||
set_pending
|
||||
>
|
||||
{move || match stories.get() {
|
||||
None => None,
|
||||
Some(None) => Some(view! { <p>"Error loading stories."</p> }.into_any()),
|
||||
Some(Some(stories)) => {
|
||||
Some(view! {
|
||||
<ul>
|
||||
<For
|
||||
each=move || stories.clone()
|
||||
key=|story| story.id
|
||||
let:story
|
||||
>
|
||||
<Story story/>
|
||||
</For>
|
||||
</ul>
|
||||
}.into_any())
|
||||
}
|
||||
}}
|
||||
</Transition>
|
||||
</div>
|
||||
</main>
|
||||
</div>
|
||||
}
|
||||
}
|
||||
|
||||
#[component]
|
||||
fn Story(story: api::Story) -> impl IntoView {
|
||||
view! {
|
||||
<li class="news-item">
|
||||
<span class="score">{story.points}</span>
|
||||
<span class="title">
|
||||
{if !story.url.starts_with("item?id=") {
|
||||
view! {
|
||||
<span>
|
||||
<a href=story.url target="_blank" rel="noreferrer">
|
||||
{story.title.clone()}
|
||||
</a>
|
||||
<span class="host">"("{story.domain}")"</span>
|
||||
</span>
|
||||
}.into_view()
|
||||
} else {
|
||||
let title = story.title.clone();
|
||||
view! { <A href=format!("/stories/{}", story.id)>{title.clone()}</A> }.into_view()
|
||||
}}
|
||||
</span>
|
||||
<br />
|
||||
<span class="meta">
|
||||
{if story.story_type != "job" {
|
||||
view! {
|
||||
<span>
|
||||
{"by "}
|
||||
{story.user.map(|user| view ! { <A href=format!("/users/{user}")>{user.clone()}</A>})}
|
||||
{format!(" {} | ", story.time_ago)}
|
||||
<A href=format!("/stories/{}", story.id)>
|
||||
{if story.comments_count.unwrap_or_default() > 0 {
|
||||
format!("{} comments", story.comments_count.unwrap_or_default())
|
||||
} else {
|
||||
"discuss".into()
|
||||
}}
|
||||
</A>
|
||||
</span>
|
||||
}.into_view()
|
||||
} else {
|
||||
let title = story.title.clone();
|
||||
view! { <A href=format!("/item/{}", story.id)>{title.clone()}</A> }.into_view()
|
||||
}}
|
||||
</span>
|
||||
{(story.story_type != "link").then(|| view! {
|
||||
" "
|
||||
<span class="label">{story.story_type}</span>
|
||||
})}
|
||||
</li>
|
||||
}
|
||||
}
|
125
examples/leptos-build/testdata/crates/hackernews_axum/src/routes/story.rs
vendored
Normal file
125
examples/leptos-build/testdata/crates/hackernews_axum/src/routes/story.rs
vendored
Normal file
@@ -0,0 +1,125 @@
|
||||
use crate::api;
|
||||
use leptos::*;
|
||||
use leptos_meta::*;
|
||||
use leptos_router::*;
|
||||
|
||||
#[component]
|
||||
pub fn Story() -> impl IntoView {
|
||||
let params = use_params_map();
|
||||
let story = create_resource(
|
||||
move || params().get("id").cloned().unwrap_or_default(),
|
||||
move |id| async move {
|
||||
if id.is_empty() {
|
||||
None
|
||||
} else {
|
||||
api::fetch_api::<api::Story>(&api::story(&format!("item/{id}")))
|
||||
.await
|
||||
}
|
||||
},
|
||||
);
|
||||
let meta_description = move || {
|
||||
story
|
||||
.get()
|
||||
.and_then(|story| story.map(|story| story.title))
|
||||
.unwrap_or_else(|| "Loading story...".to_string())
|
||||
};
|
||||
|
||||
view! {
|
||||
<Suspense fallback=|| view! { "Loading..." }>
|
||||
<Meta name="description" content=meta_description/>
|
||||
{move || story.get().map(|story| match story {
|
||||
None => view! { <div class="item-view">"Error loading this story."</div> },
|
||||
Some(story) => view! {
|
||||
<div class="item-view">
|
||||
<div class="item-view-header">
|
||||
<a href=story.url target="_blank">
|
||||
<h1>{story.title}</h1>
|
||||
</a>
|
||||
<span class="host">
|
||||
"("{story.domain}")"
|
||||
</span>
|
||||
{story.user.map(|user| view! { <p class="meta">
|
||||
{story.points}
|
||||
" points | by "
|
||||
<A href=format!("/users/{user}")>{user.clone()}</A>
|
||||
{format!(" {}", story.time_ago)}
|
||||
</p>})}
|
||||
</div>
|
||||
<div class="item-view-comments">
|
||||
<p class="item-view-comments-header">
|
||||
{if story.comments_count.unwrap_or_default() > 0 {
|
||||
format!("{} comments", story.comments_count.unwrap_or_default())
|
||||
} else {
|
||||
"No comments yet.".into()
|
||||
}}
|
||||
</p>
|
||||
<ul class="comment-children">
|
||||
<For
|
||||
each=move || story.comments.clone().unwrap_or_default()
|
||||
key=|comment| comment.id
|
||||
let:comment
|
||||
>
|
||||
<Comment comment />
|
||||
</For>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
}})}
|
||||
</Suspense>
|
||||
}
|
||||
}
|
||||
|
||||
#[component]
|
||||
pub fn Comment(comment: api::Comment) -> impl IntoView {
|
||||
let (open, set_open) = create_signal(true);
|
||||
|
||||
view! {
|
||||
<li class="comment">
|
||||
<div class="by">
|
||||
<A href=format!("/users/{}", comment.user.clone().unwrap_or_default())>{comment.user.clone()}</A>
|
||||
{format!(" {}", comment.time_ago)}
|
||||
</div>
|
||||
<div class="text" inner_html=comment.content></div>
|
||||
{(!comment.comments.is_empty()).then(|| {
|
||||
view! {
|
||||
<div>
|
||||
<div class="toggle" class:open=open>
|
||||
<a on:click=move |_| set_open.update(|n| *n = !*n)>
|
||||
{
|
||||
let comments_len = comment.comments.len();
|
||||
move || if open() {
|
||||
"[-]".into()
|
||||
} else {
|
||||
format!("[+] {}{} collapsed", comments_len, pluralize(comments_len))
|
||||
}
|
||||
}
|
||||
</a>
|
||||
</div>
|
||||
{move || open().then({
|
||||
let comments = comment.comments.clone();
|
||||
move || view! {
|
||||
<ul class="comment-children">
|
||||
<For
|
||||
each=move || comments.clone()
|
||||
key=|comment| comment.id
|
||||
let:comment
|
||||
>
|
||||
<Comment comment />
|
||||
</For>
|
||||
</ul>
|
||||
}
|
||||
})}
|
||||
</div>
|
||||
}
|
||||
})}
|
||||
</li>
|
||||
}
|
||||
}
|
||||
|
||||
fn pluralize(n: usize) -> &'static str {
|
||||
if n == 1 {
|
||||
" reply"
|
||||
} else {
|
||||
" replies"
|
||||
}
|
||||
}
|
46
examples/leptos-build/testdata/crates/hackernews_axum/src/routes/users.rs
vendored
Normal file
46
examples/leptos-build/testdata/crates/hackernews_axum/src/routes/users.rs
vendored
Normal file
@@ -0,0 +1,46 @@
|
||||
use crate::api::{self, User};
|
||||
use leptos::*;
|
||||
use leptos_router::*;
|
||||
|
||||
#[component]
|
||||
pub fn User() -> impl IntoView {
|
||||
let params = use_params_map();
|
||||
let user = create_resource(
|
||||
move || params().get("id").cloned().unwrap_or_default(),
|
||||
move |id| async move {
|
||||
if id.is_empty() {
|
||||
None
|
||||
} else {
|
||||
api::fetch_api::<User>(&api::user(&id)).await
|
||||
}
|
||||
},
|
||||
);
|
||||
view! {
|
||||
<div class="user-view">
|
||||
<Suspense fallback=|| view! { "Loading..." }>
|
||||
{move || user.get().map(|user| match user {
|
||||
None => view! { <h1>"User not found."</h1> }.into_any(),
|
||||
Some(user) => view! {
|
||||
<div>
|
||||
<h1>"User: " {&user.id}</h1>
|
||||
<ul class="meta">
|
||||
<li>
|
||||
<span class="label">"Created: "</span> {user.created}
|
||||
</li>
|
||||
<li>
|
||||
<span class="label">"Karma: "</span> {user.karma}
|
||||
</li>
|
||||
{user.about.as_ref().map(|about| view! { <li inner_html=about class="about"></li> })}
|
||||
</ul>
|
||||
<p class="links">
|
||||
<a href=format!("https://news.ycombinator.com/submitted?id={}", user.id)>"submissions"</a>
|
||||
" | "
|
||||
<a href=format!("https://news.ycombinator.com/threads?id={}", user.id)>"comments"</a>
|
||||
</p>
|
||||
</div>
|
||||
}.into_any()
|
||||
})}
|
||||
</Suspense>
|
||||
</div>
|
||||
}
|
||||
}
|
326
examples/leptos-build/testdata/crates/hackernews_axum/style.css
vendored
Normal file
326
examples/leptos-build/testdata/crates/hackernews_axum/style.css
vendored
Normal file
@@ -0,0 +1,326 @@
|
||||
body {
|
||||
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, Cantarell, "Fira Sans", "Droid Sans", "Helvetica Neue", sans-serif;
|
||||
font-size: 15px;
|
||||
background-color: #f2f3f5;
|
||||
margin: 0;
|
||||
padding-top: 55px;
|
||||
color: #34495e;
|
||||
overflow-y: scroll
|
||||
}
|
||||
|
||||
a {
|
||||
color: #34495e;
|
||||
text-decoration: none
|
||||
}
|
||||
|
||||
.header {
|
||||
background-color: #335d92;
|
||||
position: fixed;
|
||||
z-index: 999;
|
||||
height: 55px;
|
||||
top: 0;
|
||||
left: 0;
|
||||
right: 0
|
||||
}
|
||||
|
||||
.header .inner {
|
||||
max-width: 800px;
|
||||
box-sizing: border-box;
|
||||
margin: 0 auto;
|
||||
padding: 15px 5px
|
||||
}
|
||||
|
||||
.header a {
|
||||
color: rgba(255, 255, 255, .8);
|
||||
line-height: 24px;
|
||||
transition: color .15s ease;
|
||||
display: inline-block;
|
||||
vertical-align: middle;
|
||||
font-weight: 300;
|
||||
letter-spacing: .075em;
|
||||
margin-right: 1.8em
|
||||
}
|
||||
|
||||
.header a:hover {
|
||||
color: #fff
|
||||
}
|
||||
|
||||
.header a.active {
|
||||
color: #fff;
|
||||
font-weight: 400
|
||||
}
|
||||
|
||||
.header a:nth-child(6) {
|
||||
margin-right: 0
|
||||
}
|
||||
|
||||
.header .github {
|
||||
color: #fff;
|
||||
font-size: .9em;
|
||||
margin: 0;
|
||||
float: right
|
||||
}
|
||||
|
||||
.logo {
|
||||
width: 24px;
|
||||
margin-right: 10px;
|
||||
display: inline-block;
|
||||
vertical-align: middle
|
||||
}
|
||||
|
||||
.view {
|
||||
max-width: 800px;
|
||||
margin: 0 auto;
|
||||
position: relative
|
||||
}
|
||||
|
||||
.fade-enter-active,
|
||||
.fade-exit-active {
|
||||
transition: all .2s ease
|
||||
}
|
||||
|
||||
.fade-enter,
|
||||
.fade-exit-active {
|
||||
opacity: 0
|
||||
}
|
||||
|
||||
@media (max-width:860px) {
|
||||
.header .inner {
|
||||
padding: 15px 30px
|
||||
}
|
||||
}
|
||||
|
||||
@media (max-width:600px) {
|
||||
.header .inner {
|
||||
padding: 15px
|
||||
}
|
||||
|
||||
.header a {
|
||||
margin-right: 1em
|
||||
}
|
||||
|
||||
.header .github {
|
||||
display: none
|
||||
}
|
||||
}
|
||||
|
||||
.news-view {
|
||||
padding-top: 45px
|
||||
}
|
||||
|
||||
.news-list,
|
||||
.news-list-nav {
|
||||
background-color: #fff;
|
||||
border-radius: 2px
|
||||
}
|
||||
|
||||
.news-list-nav {
|
||||
padding: 15px 30px;
|
||||
position: fixed;
|
||||
text-align: center;
|
||||
top: 55px;
|
||||
left: 0;
|
||||
right: 0;
|
||||
z-index: 998;
|
||||
box-shadow: 0 1px 2px rgba(0, 0, 0, .1)
|
||||
}
|
||||
|
||||
.news-list-nav .page-link {
|
||||
margin: 0 1em
|
||||
}
|
||||
|
||||
.news-list-nav .disabled {
|
||||
color: #aaa
|
||||
}
|
||||
|
||||
.news-list {
|
||||
position: absolute;
|
||||
margin: 30px 0;
|
||||
width: 100%;
|
||||
transition: all .5s cubic-bezier(.55, 0, .1, 1)
|
||||
}
|
||||
|
||||
.news-list ul {
|
||||
list-style-type: none;
|
||||
padding: 0;
|
||||
margin: 0
|
||||
}
|
||||
|
||||
@media (max-width:600px) {
|
||||
.news-list {
|
||||
margin: 10px 0
|
||||
}
|
||||
}
|
||||
|
||||
.news-item {
|
||||
background-color: #fff;
|
||||
padding: 20px 30px 20px 80px;
|
||||
border-bottom: 1px solid #eee;
|
||||
position: relative;
|
||||
line-height: 20px
|
||||
}
|
||||
|
||||
.news-item .score {
|
||||
color: #335d92;
|
||||
font-size: 1.1em;
|
||||
font-weight: 700;
|
||||
position: absolute;
|
||||
top: 50%;
|
||||
left: 0;
|
||||
width: 80px;
|
||||
text-align: center;
|
||||
margin-top: -10px
|
||||
}
|
||||
|
||||
.news-item .host,
|
||||
.news-item .meta {
|
||||
font-size: .85em;
|
||||
color: #626262
|
||||
}
|
||||
|
||||
.news-item .host a,
|
||||
.news-item .meta a {
|
||||
color: #626262;
|
||||
text-decoration: underline
|
||||
}
|
||||
|
||||
.news-item .host a:hover,
|
||||
.news-item .meta a:hover {
|
||||
color: #335d92
|
||||
}
|
||||
|
||||
.item-view-header {
|
||||
background-color: #fff;
|
||||
padding: 1.8em 2em 1em;
|
||||
box-shadow: 0 1px 2px rgba(0, 0, 0, .1)
|
||||
}
|
||||
|
||||
.item-view-header h1 {
|
||||
display: inline;
|
||||
font-size: 1.5em;
|
||||
margin: 0;
|
||||
margin-right: .5em
|
||||
}
|
||||
|
||||
.item-view-header .host,
|
||||
.item-view-header .meta,
|
||||
.item-view-header .meta a {
|
||||
color: #626262
|
||||
}
|
||||
|
||||
.item-view-header .meta a {
|
||||
text-decoration: underline
|
||||
}
|
||||
|
||||
.item-view-comments {
|
||||
background-color: #fff;
|
||||
margin-top: 10px;
|
||||
padding: 0 2em .5em
|
||||
}
|
||||
|
||||
.item-view-comments-header {
|
||||
margin: 0;
|
||||
font-size: 1.1em;
|
||||
padding: 1em 0;
|
||||
position: relative
|
||||
}
|
||||
|
||||
.item-view-comments-header .spinner {
|
||||
display: inline-block;
|
||||
margin: -15px 0
|
||||
}
|
||||
|
||||
.comment-children {
|
||||
list-style-type: none;
|
||||
padding: 0;
|
||||
margin: 0
|
||||
}
|
||||
|
||||
@media (max-width:600px) {
|
||||
.item-view-header h1 {
|
||||
font-size: 1.25em
|
||||
}
|
||||
}
|
||||
|
||||
.comment-children .comment-children {
|
||||
margin-left: 1.5em
|
||||
}
|
||||
|
||||
.comment {
|
||||
border-top: 1px solid #eee;
|
||||
position: relative
|
||||
}
|
||||
|
||||
.comment .by,
|
||||
.comment .text,
|
||||
.comment .toggle {
|
||||
font-size: .9em;
|
||||
margin: 1em 0
|
||||
}
|
||||
|
||||
.comment .by {
|
||||
color: #626262
|
||||
}
|
||||
|
||||
.comment .by a {
|
||||
color: #626262;
|
||||
text-decoration: underline
|
||||
}
|
||||
|
||||
.comment .text {
|
||||
overflow-wrap: break-word
|
||||
}
|
||||
|
||||
.comment .text a:hover {
|
||||
color: #335d92
|
||||
}
|
||||
|
||||
.comment .text pre {
|
||||
white-space: pre-wrap
|
||||
}
|
||||
|
||||
.comment .toggle {
|
||||
background-color: #fffbf2;
|
||||
padding: .3em .5em;
|
||||
border-radius: 4px
|
||||
}
|
||||
|
||||
.comment .toggle a {
|
||||
color: #626262;
|
||||
cursor: pointer
|
||||
}
|
||||
|
||||
.comment .toggle.open {
|
||||
padding: 0;
|
||||
background-color: transparent;
|
||||
margin-bottom: -.5em
|
||||
}
|
||||
|
||||
.user-view {
|
||||
background-color: #fff;
|
||||
box-sizing: border-box;
|
||||
padding: 2em 3em
|
||||
}
|
||||
|
||||
.user-view h1 {
|
||||
margin: 0;
|
||||
font-size: 1.5em
|
||||
}
|
||||
|
||||
.user-view .meta {
|
||||
list-style-type: none;
|
||||
padding: 0
|
||||
}
|
||||
|
||||
.user-view .label {
|
||||
display: inline-block;
|
||||
min-width: 4em
|
||||
}
|
||||
|
||||
.user-view .about {
|
||||
margin: 1em 0
|
||||
}
|
||||
|
||||
.user-view .links a {
|
||||
text-decoration: underline
|
||||
}
|
@@ -22,7 +22,7 @@ pub async fn main() -> eyre::Result<()> {
|
||||
.await?;
|
||||
|
||||
for container in containers {
|
||||
container.exit_code().await?;
|
||||
container.sync().await?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
11
scripts/ci:release.sh
Executable file
11
scripts/ci:release.sh
Executable file
@@ -0,0 +1,11 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
set -e
|
||||
|
||||
CMD_PREFIX="cargo run -p ci --"
|
||||
|
||||
if [[ -n "$CI_PREFIX" ]]; then
|
||||
CMD_PREFIX="$CI_PREFIX"
|
||||
fi
|
||||
|
||||
$CMD_PREFIX pull-request --cuddle-please-image="$CUDDLE_PLEASE_IMAGE"
|
Reference in New Issue
Block a user