we don't have to commit styles.css, actually
All checks were successful
arche-build-and-publish / gractwo-arche-build-test (push) Successful in 1m15s

This commit is contained in:
2026-04-08 00:45:13 +02:00
parent 6613ccb239
commit f27325ee30
5 changed files with 37 additions and 37 deletions

View File

@@ -10,7 +10,7 @@ WORKDIR /app
ENV IN_DOCKER=true ENV IN_DOCKER=true
# Install host build dependencies. # Install host build dependencies.
RUN apk add --no-cache clang lld musl-dev git RUN apk add --no-cache clang lld musl-dev git gcompat
# Build the application. # Build the application.
# Leverage a cache mount to /usr/local/cargo/registry/ # Leverage a cache mount to /usr/local/cargo/registry/
@@ -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 # source code into the container. Once built, copy the executable to an
# output directory before the cache mounted /app/target is unmounted. # output directory before the cache mounted /app/target is unmounted.
RUN --mount=type=bind,source=src,target=src \ RUN --mount=type=bind,source=src,target=src \
--mount=type=bind,source=build.rs,target=build.rs \
--mount=type=bind,source=web,target=web \ --mount=type=bind,source=web,target=web \
--mount=type=bind,source=assets,target=assets \ --mount=type=bind,source=assets,target=assets \
--mount=type=bind,source=askama.toml,target=askama.toml \ --mount=type=bind,source=askama.toml,target=askama.toml \

View File

@@ -7,17 +7,23 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
println!("cargo:rerun-if-changed=build.rs"); println!("cargo:rerun-if-changed=build.rs");
println!("cargo:rerun-if-changed=web"); println!("cargo:rerun-if-changed=web");
if std::env::var("IN_DOCKER").is_err() {
let os = env::var("CARGO_CFG_TARGET_OS").unwrap_or_else(|_| String::from("unknown")); 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 arch = env::var("CARGO_CFG_TARGET_ARCH").unwrap_or_else(|_| String::from("unknown"));
let download_url = match (os.as_str(), arch.as_str()) { let env = env::var("CARGO_CFG_TARGET_ENV").unwrap_or_else(|_| String::from("unknown"));
("macos", "aarch64") => { 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" "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" "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" "https://github.com/tailwindlabs/tailwindcss/releases/latest/download/tailwindcss-linux-arm64"
} }
_ => return Err(format!("Unsupported platform: {} {}", os, arch).into()), _ => 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)?; download_tailwind(&download_url, &tailwind_binary)?;
println!("cargo:rustc-env=TAILWIND_BIN={}", tailwind_binary.display()); println!("cargo:rustc-env=TAILWIND_BIN={}", tailwind_binary.display());
run_tailwind(&tailwind_binary)?; run_tailwind(&tailwind_binary)?;
}
Ok(()) Ok(())
} }
@@ -40,17 +45,19 @@ fn run_tailwind(bin: &PathBuf) -> Result<(), Box<dyn std::error::Error>> {
let basedir = std::env::var("CARGO_MANIFEST_DIR").unwrap_or_else(|_| ".".into()); let basedir = std::env::var("CARGO_MANIFEST_DIR").unwrap_or_else(|_| ".".into());
let input = Path::new(&basedir).join("web").join("input.css"); let input = Path::new(&basedir).join("web").join("input.css");
let inputstr = input.to_str().unwrap(); let inputstr = input.to_str().unwrap();
let output = Path::new(&basedir).join("web").join("styles.css"); let output = PathBuf::from(env::var("OUT_DIR")?).join("styles.css");
let outputstr = output.to_str().unwrap(); let outputstr = output.to_str().unwrap();
let args = vec!["-i", inputstr, "-o", outputstr, "--minify"]; let args = vec!["-i", inputstr, "-o", outputstr, "--minify"];
let run = Command::new(&bin).args(args).status()?; let run = Command::new(&bin).args(args).status()?;
match run.success() { match run.success() {
true => println!("Tailwind CSS build complete."), true => {
false => println!("Tailwind CSS build failed."), println!("Tailwind CSS build complete.");
};
Ok(()) Ok(())
} }
false => panic!("Tailwind CSS build failed."),
}
}
fn download_tailwind(url: &str, target_path: &Path) -> Result<(), Box<dyn std::error::Error>> { fn download_tailwind(url: &str, target_path: &Path) -> Result<(), Box<dyn std::error::Error>> {
if target_path.exists() { if target_path.exists() {

View File

@@ -1,8 +1,2 @@
arche arche
===== =====
Regarding /web/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.

View File

@@ -10,7 +10,7 @@ use crate::website::pages::{index::page_index, notfound::page_notfound};
mod pages; mod pages;
const STYLES_CSS: &str = include_str!("../../web/styles.css"); const STYLES_CSS: &str = include_str!(concat!(env!("OUT_DIR"), "/styles.css"));
const FAVICON_SVG: &str = include_str!("../../assets/logo.svg"); const FAVICON_SVG: &str = include_str!("../../assets/logo.svg");
const FAVICON_X64: &[u8] = include_bytes!("../../assets/logo-x64.png"); const FAVICON_X64: &[u8] = include_bytes!("../../assets/logo-x64.png");

File diff suppressed because one or more lines are too long