Compare commits
2 Commits
1adb4d9e33
...
d6e68ac8f7
| Author | SHA1 | Date | |
|---|---|---|---|
| d6e68ac8f7 | |||
|
386118de7d
|
@@ -21,6 +21,7 @@ RUN apk add --no-cache clang lld musl-dev git
|
||||
# source code into the container. Once built, copy the executable to an
|
||||
# output directory before the cache mounted /app/target is unmounted.
|
||||
RUN --mount=type=bind,source=src,target=src \
|
||||
--mount=type=bind,source=build.rs,target=build.rs \
|
||||
--mount=type=bind,source=Cargo.toml,target=Cargo.toml \
|
||||
--mount=type=bind,source=Cargo.lock,target=Cargo.lock \
|
||||
--mount=type=cache,target=/app/target/ \
|
||||
|
||||
30
build.rs
30
build.rs
@@ -7,17 +7,23 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
println!("cargo:rerun-if-changed=build.rs");
|
||||
println!("cargo:rerun-if-changed=src/web");
|
||||
|
||||
if std::env::var("IN_DOCKER").is_err() {
|
||||
let os = env::var("CARGO_CFG_TARGET_OS").unwrap_or_else(|_| String::from("unknown"));
|
||||
let arch = env::var("CARGO_CFG_TARGET_ARCH").unwrap_or_else(|_| String::from("unknown"));
|
||||
let download_url = match (os.as_str(), arch.as_str()) {
|
||||
("macos", "aarch64") => {
|
||||
let env = env::var("CARGO_CFG_TARGET_ENV").unwrap_or_else(|_| String::from("unknown"));
|
||||
let download_url = match (os.as_str(), arch.as_str(), env.as_str()) {
|
||||
("macos", "aarch64", _) => {
|
||||
"https://github.com/tailwindlabs/tailwindcss/releases/latest/download/tailwindcss-macos-arm64"
|
||||
}
|
||||
("linux", "x86_64") => {
|
||||
("linux", "x86_64", "musl") => {
|
||||
"https://github.com/tailwindlabs/tailwindcss/releases/latest/download/tailwindcss-linux-x64-musl"
|
||||
}
|
||||
("linux", "x86_64", _) => {
|
||||
"https://github.com/tailwindlabs/tailwindcss/releases/latest/download/tailwindcss-linux-x64"
|
||||
}
|
||||
("linux", "aarch64") => {
|
||||
("linux", "aarch64", "musl") => {
|
||||
"https://github.com/tailwindlabs/tailwindcss/releases/latest/download/tailwindcss-linux-arm64-musl"
|
||||
}
|
||||
("linux", "aarch64", _) => {
|
||||
"https://github.com/tailwindlabs/tailwindcss/releases/latest/download/tailwindcss-linux-arm64"
|
||||
}
|
||||
_ => return Err(format!("Unsupported platform: {} {}", os, arch).into()),
|
||||
@@ -30,7 +36,6 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
download_tailwind(&download_url, &tailwind_binary)?;
|
||||
println!("cargo:rustc-env=TAILWIND_BIN={}", tailwind_binary.display());
|
||||
run_tailwind(&tailwind_binary)?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -43,20 +48,19 @@ fn run_tailwind(bin: &PathBuf) -> Result<(), Box<dyn std::error::Error>> {
|
||||
.join("web")
|
||||
.join("input.css");
|
||||
let inputstr = input.to_str().unwrap();
|
||||
let output = Path::new(&basedir)
|
||||
.join("src")
|
||||
.join("web")
|
||||
.join("styles.css");
|
||||
let output = PathBuf::from(env::var("OUT_DIR")?).join("styles.css");
|
||||
let outputstr = output.to_str().unwrap();
|
||||
let args = vec!["-i", inputstr, "-o", outputstr, "--minify"];
|
||||
|
||||
let run = Command::new(&bin).args(args).status()?;
|
||||
match run.success() {
|
||||
true => println!("Tailwind CSS build complete."),
|
||||
false => println!("Tailwind CSS build failed."),
|
||||
};
|
||||
true => {
|
||||
println!("Tailwind CSS build complete.");
|
||||
Ok(())
|
||||
}
|
||||
false => panic!("Tailwind CSS build failed."),
|
||||
}
|
||||
}
|
||||
|
||||
fn download_tailwind(url: &str, target_path: &Path) -> Result<(), Box<dyn std::error::Error>> {
|
||||
if target_path.exists() {
|
||||
|
||||
@@ -2,5 +2,3 @@ Mnemosyne
|
||||
|
||||
|
||||
Mnemosyne is a work-in-progress project which aims to satisfy all the quote-collecting needs of your community, all the while making them queryable and well notarized.
|
||||
|
||||
Note on tailwind and styles.css: The styles.css file, which is generated by a standalone Tailwind binary downloaded and executed automatically within build.rs, is to be committed any time it changes, as without it styling will be broken on the frontend part of the page. This is in contrast to a perhaps expected approach of gitignoring them and just generating them every build; this is incompatible with building docker images in an efficient way, however, as docker exposes no way to mount directories while retaining ability to write files and execute binaries.
|
||||
|
||||
@@ -9,13 +9,13 @@ mod components;
|
||||
mod icons;
|
||||
mod pages;
|
||||
|
||||
pub const STYLES_CSS: &str = include_str!("./styles.css");
|
||||
pub const CSS: &str = include_str!(concat!(env!("OUT_DIR"), "/styles.css"));
|
||||
|
||||
pub fn web_router() -> Router {
|
||||
Router::new()
|
||||
.route(
|
||||
"/styles.css",
|
||||
get(|| async { ([(header::CONTENT_TYPE, "text/css")], STYLES_CSS) }),
|
||||
get(([(header::CONTENT_TYPE, "text/css")], CSS)),
|
||||
)
|
||||
.merge(pages::pages())
|
||||
}
|
||||
|
||||
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user