Get the versions of emacs and org-mode and write them to stdout.

This commit is contained in:
Tom Alexander 2023-08-25 02:30:52 -04:00
parent 79c834a1e6
commit bd99fbc4c4
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE
4 changed files with 56 additions and 6 deletions

View File

@ -10,3 +10,8 @@ serde = { version = "1.0.183", features = ["derive"] }
tokio = { version = "1.30.0", default-features = false, features = ["macros", "process", "rt", "rt-multi-thread"] } tokio = { version = "1.30.0", default-features = false, features = ["macros", "process", "rt", "rt-multi-thread"] }
tower = "0.4.13" tower = "0.4.13"
tower-http = { version = "0.4.3", features = ["fs", "set-header"] } tower-http = { version = "0.4.3", features = ["fs", "set-header"] }
[profile.release-lto]
inherits = "release"
lto = true
strip = "symbols"

View File

@ -30,14 +30,14 @@ RUN apk add --no-cache musl-dev
RUN mkdir /root/org-investigation RUN mkdir /root/org-investigation
WORKDIR /root/org-investigation WORKDIR /root/org-investigation
COPY . . COPY . .
RUN CARGO_TARGET_DIR=/target cargo build --release RUN CARGO_TARGET_DIR=/target cargo build --profile release-lto
FROM alpine:3.17 AS run FROM alpine:3.17 AS run
RUN apk add --no-cache ncurses gnutls RUN apk add --no-cache ncurses gnutls
COPY --from=build-emacs /root/dist/ / COPY --from=build-emacs /root/dist/ /
COPY --from=build-org-mode /root/dist/ / COPY --from=build-org-mode /root/dist/ /
COPY --from=build-org-investigation /target/release/org_ownership_investigation /usr/bin/ COPY --from=build-org-investigation /target/release-lto/org_ownership_investigation /usr/bin/
COPY static /opt/org-investigation/static COPY static /opt/org-investigation/static
WORKDIR /opt/org-investigation WORKDIR /opt/org-investigation
CMD ["/usr/bin/org_ownership_investigation"] CMD ["/usr/bin/org_ownership_investigation"]

View File

@ -4,11 +4,13 @@ use axum::http::HeaderValue;
use axum::response::IntoResponse; use axum::response::IntoResponse;
use axum::{http::StatusCode, routing::post, Json, Router}; use axum::{http::StatusCode, routing::post, Json, Router};
use owner_tree::build_owner_tree; use owner_tree::build_owner_tree;
use parse::emacs_parse_org_document; use parse::{emacs_parse_org_document, get_emacs_version};
use tower::ServiceBuilder; use tower::ServiceBuilder;
use tower_http::services::{ServeDir, ServeFile}; use tower_http::services::{ServeDir, ServeFile};
use tower_http::set_header::SetResponseHeaderLayer; use tower_http::set_header::SetResponseHeaderLayer;
use crate::parse::get_org_mode_version;
mod error; mod error;
mod owner_tree; mod owner_tree;
mod parse; mod parse;
@ -16,7 +18,7 @@ mod rtrim_iterator;
mod sexp; mod sexp;
#[tokio::main] #[tokio::main]
async fn main() { async fn main() -> Result<(), Box<dyn std::error::Error>> {
let static_files_service = { let static_files_service = {
let serve_dir = let serve_dir =
ServeDir::new("static").not_found_service(ServeFile::new("static/index.html")); ServeDir::new("static").not_found_service(ServeFile::new("static/index.html"));
@ -32,9 +34,15 @@ async fn main() {
.route("/parse", post(parse_org_mode)) .route("/parse", post(parse_org_mode))
.fallback_service(static_files_service); .fallback_service(static_files_service);
let listener = tokio::net::TcpListener::bind("0.0.0.0:3000").await.unwrap(); let emacs_version = get_emacs_version().await?;
let org_mode_version = get_org_mode_version().await?;
println!("Using emacs version: {}", emacs_version.trim());
println!("Using org-mode version: {}", org_mode_version.trim());
let listener = tokio::net::TcpListener::bind("0.0.0.0:3000").await?;
println!("Listening on port 3000. Pop open your browser to http://127.0.0.1:3000/ ."); println!("Listening on port 3000. Pop open your browser to http://127.0.0.1:3000/ .");
axum::serve(listener, app).await.unwrap(); axum::serve(listener, app).await?;
Ok(())
} }
async fn parse_org_mode(body: String) -> Result<impl IntoResponse, (StatusCode, String)> { async fn parse_org_mode(body: String) -> Result<impl IntoResponse, (StatusCode, String)> {

View File

@ -51,3 +51,40 @@ where
} }
output output
} }
pub async fn get_emacs_version() -> Result<String, Box<dyn std::error::Error>> {
let elisp_script = r#"(progn
(message "%s" (version))
)"#;
let mut cmd = Command::new("emacs");
let proc = cmd
.arg("-q")
.arg("--no-site-file")
.arg("--no-splash")
.arg("--batch")
.arg("--eval")
.arg(elisp_script);
let out = proc.output().await?;
out.status.exit_ok()?;
Ok(String::from_utf8(out.stderr)?)
}
pub async fn get_org_mode_version() -> Result<String, Box<dyn std::error::Error>> {
let elisp_script = r#"(progn
(org-mode)
(message "%s" (org-version nil t nil))
)"#;
let mut cmd = Command::new("emacs");
let proc = cmd
.arg("-q")
.arg("--no-site-file")
.arg("--no-splash")
.arg("--batch")
.arg("--eval")
.arg(elisp_script);
let out = proc.output().await?;
out.status.exit_ok()?;
Ok(String::from_utf8(out.stderr)?)
}