Initial project structure in Rust with Rocket
This commit is contained in:
@@ -16,3 +16,8 @@ target/
|
||||
# and can be added to the global gitignore or merged into this file. For a more nuclear
|
||||
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
||||
#.idea/
|
||||
|
||||
|
||||
# Added by cargo
|
||||
|
||||
/target
|
||||
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
[package]
|
||||
name = "druid"
|
||||
version = "0.1.0"
|
||||
edition = "2024"
|
||||
|
||||
[dependencies]
|
||||
rocket = "0.5.1"
|
||||
|
||||
[dependencies.rocket_dyn_templates]
|
||||
version = "0.2.0"
|
||||
features = ["tera"]
|
||||
+30
@@ -0,0 +1,30 @@
|
||||
# --------------------
|
||||
# STAGE 1: The Builder
|
||||
FROM rust:1.96 as builder
|
||||
|
||||
WORKDIR /app
|
||||
COPY Cargo.* ./
|
||||
|
||||
# Create a dummy main.rs so the dependencies can be compiled and cached
|
||||
RUN mkdir src && \
|
||||
echo "fn main() { println!(\"dummy\"); }" > src/main.rs
|
||||
RUN cargo build --release
|
||||
|
||||
# Copy in the real source code changes
|
||||
COPY src ./src
|
||||
# Run the real build command
|
||||
RUN cargo build --release
|
||||
|
||||
# --------------------
|
||||
# STAGE 2: The Final, Minimal Image
|
||||
FROM debian:stable-slim
|
||||
|
||||
WORKDIR /usr/src/druid
|
||||
|
||||
# Copy ONLY the compiled binary from the builder stage
|
||||
COPY --from=builder /app/target/release/druid /usr/local/bin
|
||||
|
||||
ENV ROCKET_ADDRESS=0.0.0.0
|
||||
|
||||
# Define the command that runs your application
|
||||
CMD ["/usr/local/bin/druid"]
|
||||
@@ -1,3 +1,7 @@
|
||||
# Druid
|
||||
|
||||
Web app for storing PC hardware benchmarking data
|
||||
|
||||
## License
|
||||
|
||||
This project is licensed under the BSD 3-Clause license.
|
||||
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
#[macro_use] extern crate rocket;
|
||||
use rocket_dyn_templates::{Template, context};
|
||||
|
||||
#[get("/")]
|
||||
fn index() -> Template {
|
||||
Template::render("index", context! {
|
||||
title: "Dashboard",
|
||||
})
|
||||
}
|
||||
|
||||
#[get("/about")]
|
||||
fn about() -> Template {
|
||||
Template::render("about", context! {
|
||||
title: "About Druid",
|
||||
})
|
||||
}
|
||||
|
||||
#[launch]
|
||||
fn rocket() -> _ {
|
||||
rocket::build().attach(Template::fairing())
|
||||
.mount("/", routes![index, about])
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>{{ title }} | Druid</title>
|
||||
</head>
|
||||
<body>
|
||||
<p>This is about Druid.</p>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,11 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>{{ title }} | Druid</title>
|
||||
</head>
|
||||
<body>
|
||||
<p>This is a test.</p>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user