-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: dockerized proving server + cli (#20)
- Loading branch information
Showing
21 changed files
with
764 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,3 +9,5 @@ Cargo.lock | |
params | ||
.DS_Store | ||
debug/ | ||
.cargo | ||
Dockerfile.cpu |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
use clap::{Parser, Subcommand}; | ||
|
||
use crate::{ | ||
dockerize::DockerizeCmd, run::types::AxiomCircuitRunnerOptions, | ||
server::types::AxiomComputeServerCmd, | ||
}; | ||
|
||
#[derive(Parser)] | ||
#[command(author, version, about, long_about = None)] | ||
pub struct Cli { | ||
#[command(subcommand)] | ||
pub command: Commands, | ||
} | ||
|
||
#[derive(Subcommand)] | ||
pub enum Commands { | ||
/// Run a circuit proving server | ||
Serve(AxiomComputeServerCmd), | ||
/// Run keygen and real/mock proving | ||
Run(AxiomCircuitRunnerOptions), | ||
/// To generate a Dockerfile for running the circuit binary | ||
Dockerize(DockerizeCmd), | ||
} | ||
|
||
#[macro_export] | ||
macro_rules! axiom_main { | ||
($A:ty) => { | ||
axiom_main!($crate::axiom::AxiomCompute<$A>, $A); | ||
}; | ||
($A:ty, $I: ty) => { | ||
$crate::axiom_compute_prover_server!($A); | ||
#[tokio::main] | ||
async fn main() { | ||
env_logger::init(); | ||
let cli = <$crate::cli::Cli as clap::Parser>::parse(); | ||
match cli.command { | ||
$crate::cli::Commands::Serve(args) => { | ||
let _ = server(args).await; | ||
} | ||
$crate::cli::Commands::Run(args) => { | ||
let thread = std::thread::spawn(|| { | ||
$crate::run::run_cli_on_scaffold::<$A, $I>(args); | ||
}); | ||
thread.join().unwrap(); | ||
} | ||
$crate::cli::Commands::Dockerize(args) => { | ||
let env_args: Vec<String> = std::env::args().collect(); | ||
$crate::dockerize::gen_dockerfile(env_args, args); | ||
} | ||
} | ||
} | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
FROM rust:1.74 as builder | ||
|
||
RUN apt-get update && apt-get install -y \ | ||
git \ | ||
openssh-client \ | ||
&& rm -rf /var/lib/apt/lists/* | ||
|
||
RUN apt-get update -y | ||
RUN git config --global url."https://github.com/".insteadOf "[email protected]:" | ||
|
||
WORKDIR /code | ||
COPY . . | ||
|
||
ENV JEMALLOC_SYS_WITH_MALLOC_CONF="background_thread:true,metadata_thp:always,dirty_decay_ms:1000000,muzzy_decay_ms:1000000,abort_conf:true" | ||
ENV RUST_LOG=info | ||
|
||
RUN {{build_command}} | ||
|
||
FROM debian:stable-slim | ||
WORKDIR /code | ||
RUN apt update \ | ||
&& apt install -y openssl ca-certificates \ | ||
&& apt clean \ | ||
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* | ||
|
||
COPY --from=builder {{target_path}} ./bin | ||
EXPOSE 8000 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
use std::{fs::File, io::Write}; | ||
|
||
use clap::{command, Parser}; | ||
|
||
const TEMPLATE: &str = include_str!(concat!( | ||
env!("CARGO_MANIFEST_DIR"), | ||
"/src/dockerize/Dockerfile.template.cpu" | ||
)); | ||
|
||
#[derive(Parser, Debug)] | ||
#[command(author, version, about, long_about = None)] | ||
pub struct DockerizeCmd { | ||
#[arg( | ||
short, | ||
long = "output-path", | ||
help = "For loading build artifacts", | ||
default_value = "Dockerfile.cpu" | ||
)] | ||
/// The path to load build artifacts from | ||
pub output_path: String, | ||
} | ||
|
||
pub fn gen_dockerfile(args: Vec<String>, cmd_args: DockerizeCmd) { | ||
let bin_path = args[0].clone(); | ||
let bin_path_parts: Vec<&str> = bin_path.split(std::path::MAIN_SEPARATOR).collect(); | ||
assert_eq!( | ||
bin_path_parts[0], "target", | ||
"The dockerize command only supports the `target` build directory" | ||
); | ||
if !(bin_path_parts[1] == "debug" || bin_path_parts[1] == "release") { | ||
panic!("The dockerize command only supports `debug` or `release` build profiles"); | ||
} | ||
let is_example = bin_path_parts[2] == "examples"; | ||
let bin_name = if is_example { | ||
bin_path_parts[3] | ||
} else { | ||
bin_path_parts[2] | ||
}; | ||
let build_flag = if is_example { "--example" } else { "--bin" }; | ||
let build_string = format!("cargo build {} {} --release", build_flag, bin_name); | ||
let target_path = if bin_path_parts[1] == "debug" { | ||
bin_path.replace("debug", "release") | ||
} else { | ||
bin_path.clone() | ||
}; | ||
let docker_target_path = format!("/code/{}", target_path); | ||
let modified_template = TEMPLATE | ||
.replace("{{build_command}}", &build_string) | ||
.replace("{{target_path}}", &docker_target_path); | ||
|
||
let mut file = File::create(&cmd_args.output_path).expect("Failed to create Dockerfile"); | ||
file.write_all(modified_template.as_bytes()) | ||
.expect("Failed to write Dockerfile"); | ||
log::info!("Dockerfile written to {}", &cmd_args.output_path); | ||
log::info!("To build the Dockerfile, run:"); | ||
log::info!("docker build -f {} .", &cmd_args.output_path) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
## Usage | ||
|
||
``` | ||
To generate a Dockerfile for running the circuit binary | ||
Usage: <BIN NAME> dockerize [OPTIONS] | ||
Options: | ||
-o, --output-path <OUTPUT_PATH> For loading build artifacts [default: Dockerfile.cpu] | ||
-h, --help Print help | ||
-V, --version Print version | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.