Skip to content

Commit

Permalink
feat: update dockerfile
Browse files Browse the repository at this point in the history
  • Loading branch information
andrew2003 committed Dec 4, 2024
1 parent edfb5aa commit 640a9fa
Show file tree
Hide file tree
Showing 18 changed files with 153 additions and 151 deletions.
5 changes: 5 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ serde = { version = "1.0.210", features = ["derive"] }
sqlx = { version = "*" }
serde_json = { version = "1.0.128" }
stone-cli = { git = "https://github.com/zksecurity/stone-cli.git" }
starknet-os = { git = "https://github.com/keep-starknet-strange/snos" }
#starknet-os = { git = "https://github.com/keep-starknet-strange/snos", branch = "main"}
tempfile = { version = "3.13.0" }
test-log = { version = "0.2.16" }
testcontainers-modules = { version = "0.11.3" }
Expand All @@ -68,6 +70,9 @@ url = { version = "2.4.0", features = ["serde"] }
uuid = { version = "1.10.0", features = ["v4"] }
reqwest = "0.12.9"
tokio-postgres = "0.7.12"
base64 = "0.22.1"
zip = "0.6.6"


[patch.crates-io]
merlin = { git = "https://github.com/aptos-labs/merlin" }
Expand Down
37 changes: 22 additions & 15 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,35 +1,42 @@
# Using the `rust-musl-builder` as base image, instead of
# the official Rust toolchain
FROM clux/muslrust:stable AS chef
USER root
RUN cargo install cargo-chef

FROM lukemathwalker/cargo-chef:latest-rust-1 AS chef
WORKDIR /app

FROM clux/muslrust:stable AS bunyan
RUN cargo install bunyan

FROM chef AS planner
COPY . .
RUN cargo chef prepare --recipe-path recipe.json

FROM chef AS builder
RUN apt update
RUN apt install -y build-essential libssl-dev pkg-config protobuf-compiler libclang1 clang \
cmake \
libpq-dev \
libdw-dev \
binutils \
lld \
libudev-dev
RUN rm -rf /var/lib/apt/lists/*

COPY --from=planner /app/recipe.json recipe.json
RUN cargo chef cook --release --recipe-path recipe.json
COPY . .
RUN cargo build --release --all
RUN mv target/${CARGO_BUILD_TARGET}/release /out

FROM alpine AS public-dev
FROM debian:bookworm-slim AS public-server
WORKDIR /user
COPY crates/public/config/00-default.toml 00-default.toml
COPY --from=builder /out/cli /usr/local/bin/rust-api-server
COPY --from=bunyan /root/.cargo/bin/bunyan /usr/local/bin/
ENTRYPOINT ["/bin/sh"]
CMD ["-c", "/usr/local/bin/irelia --config-path=*.toml | bunyan"]
RUN apt install -y libssl-dev libpq-dev

FROM scratch AS public-prod
WORKDIR /user
COPY crates/public/config/00-default.toml 00-default.toml
COPY --from=builder /out/irelia /usr/local/bin/irelia
ENTRYPOINT ["/usr/local/bin/irelia", "--config-path=*.toml"]

FROM debian:bookworm-slim AS public-worker
WORKDIR /user
RUN apt update
RUN apt install -y libssl-dev libpq-dev

COPY crates/worker/config/00-default.toml 00-default.toml
COPY --from=builder /out/irelia_worker /usr/local/bin/irelia_worker
ENTRYPOINT ["/usr/local/bin/irelia_worker", "--config-path=*.toml"]
1 change: 1 addition & 0 deletions crates/core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@ regex = { workspace = true }
serde = { workspace = true, features = ["derive"] }
serde_json = { workspace = true }
stone-cli = { workspace = true }
starknet-os = { workspace = true }
thiserror = { workspace = true }
uuid = { workspace = true, features = ["v4", "serde"] }
46 changes: 2 additions & 44 deletions crates/core/src/entities/job.rs
Original file line number Diff line number Diff line change
@@ -1,51 +1,9 @@
use std::fmt;
use std::str::FromStr;

use serde::{Deserialize, Serialize};
use starknet_os::sharp::CairoJobStatus;
use uuid::Uuid;

#[derive(Serialize, Deserialize, PartialEq, Debug, Clone)]
pub enum JobStatus {
Failed, // Stone failed
Invalid, // Wrong pie format
Unknown, //
InProgress, // init status
NotCreated, //
Processed, // stone completed => to submit on chain
Onchain, // stone completed and submit on chain completed
}

impl fmt::Display for JobStatus {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
JobStatus::Failed => write!(f, "FAILED"),
JobStatus::Invalid => write!(f, "INVALID"),
JobStatus::Unknown => write!(f, "UNKNOWN"),
JobStatus::InProgress => write!(f, "IN_PROGRESS"),
JobStatus::NotCreated => write!(f, "NOT_CREATED"),
JobStatus::Processed => write!(f, "PROCESSED"),
JobStatus::Onchain => write!(f, "ONCHAIN"),
}
}
}

impl FromStr for JobStatus {
type Err = String;

fn from_str(s: &str) -> Result<Self, Self::Err> {
match s.to_uppercase().as_str() {
"FAILED" => Ok(JobStatus::Failed),
"INVALID" => Ok(JobStatus::Invalid),
"UNKNOWN" => Ok(JobStatus::Unknown),
"IN_PROGRESS" => Ok(JobStatus::InProgress),
"NOT_CREATED" => Ok(JobStatus::NotCreated),
"PROCESSED" => Ok(JobStatus::Processed),
"ONCHAIN" => Ok(JobStatus::Onchain),
_ => Err(format!("'{}' is not a valid value of job status", s)),
}
}
}

#[derive(Debug, Eq, Hash, PartialEq, Serialize, Deserialize, Clone)]
pub struct JobId(pub Uuid);

Expand All @@ -54,7 +12,7 @@ pub struct JobEntity {
pub id: JobId,
pub customer_id: String,
pub cairo_job_key: String,
pub status: JobStatus,
pub status: CairoJobStatus,
pub invalid_reason: String,
pub error_log: String,
pub validation_done: bool,
Expand Down
37 changes: 0 additions & 37 deletions crates/core/src/entities/worker_job.rs
Original file line number Diff line number Diff line change
@@ -1,45 +1,8 @@
use serde::{Deserialize, Serialize};
use uuid::Uuid;

#[derive(Serialize, Deserialize, PartialEq, Debug, Clone)]
pub enum ProofLayout {
Plain,
Small,
Dex,
Recursive,
Starknet,
StarknetWithKeccak,
RecursiveLargeOutput,
RecursiveWithPoseidon,
AllSolidity,
AllCairo,
Dynamic,
}

impl std::str::FromStr for ProofLayout {
type Err = ();

fn from_str(s: &str) -> Result<Self, Self::Err> {
match s {
"plain" => Ok(ProofLayout::Plain),
"small" => Ok(ProofLayout::Small),
"dex" => Ok(ProofLayout::Dex),
"recursive" => Ok(ProofLayout::Recursive),
"starknet" => Ok(ProofLayout::Starknet),
"starknet_with_keccak" => Ok(ProofLayout::StarknetWithKeccak),
"recursive_large_output" => Ok(ProofLayout::RecursiveLargeOutput),
"recursive_with_poseidon" => Ok(ProofLayout::RecursiveWithPoseidon),
"all_solidity" => Ok(ProofLayout::AllSolidity),
"all_cairo" => Ok(ProofLayout::AllCairo),
"dynamic" => Ok(ProofLayout::Dynamic),
_ => Err(()),
}
}
}

#[derive(Clone, Debug, PartialEq)]
pub enum WorkerJobStatus {
FaultyCairoPie,
IncorrectLayout,
AdditionalBadFlag,
NoCairoJobId,
Expand Down
4 changes: 4 additions & 0 deletions crates/public/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ readonly = { workspace = true }
reqwest = { workspace = true, features = ["json"] }
serde = { workspace = true, features = ["derive"] }
serde_json = { workspace = true }
stone-cli = { workspace = true }
starknet-os = { workspace = true }
thiserror = { workspace = true }
tokio = { workspace = true, features = ["full"] }
tokio-postgres = { workspace = true }
Expand All @@ -34,3 +36,5 @@ tower-http = { workspace = true, features = ["timeout", "trace"] }
tracing = { workspace = true }
tracing-opentelemetry = { workspace = true }
uuid = { workspace = true }
base64 = { workspace = true }
zip = { workspace = true }
4 changes: 2 additions & 2 deletions crates/public/config/00-default.toml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
exporter_endpoint = "http://localhost:7281"
exporter_endpoint = "http://0.0.0.0:7281"
service_name = "irelia-rest-api"

[pg]
max_size = 10
url = "postgres://postgres:changeme@localhost:5432/postgres"
url = "postgres://postgres:changeme@0.0.0.0:5432/postgres"

[server]
port = 8000
Expand Down
1 change: 1 addition & 0 deletions crates/public/src/assets/test_data/encoded_cairo_pie.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
UEsDBBQAAAAIAAAAIQB4ytupXQEAAKMDAAANAAAAbWV0YWRhdGEuanNvbq2S24rCQAyGX0V67UXOk+yrLCJd7UphraIVZMV339QDylLvhKGkyTf//JPJqdruNqtdva4+JqeM23WTERu6AhV3M0NGQrYoTJlhCIUCCGrECIVQmVHDLCIRCMoKsnohIBDH6aRa1n2dqp8UwIIiEhii4RzTSdbFkK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MTy0GsWp1FJQSS0qKMpNKS6AitbUAUEsDBBQAAAAIAAAAIQBhYoo8TwAAAFcAAAAYAAAAZXhlY3V0aW9uX3Jlc291cmNlcy5qc29uq1bKiy8uSS0oVrJSMDfSUVBKKs3MKcnMi8/MKy5JzEtOjU/OL80rSS0Cylcr5ZeWFJSWxEPVAIWMaoFa8uJzU3PziyrjM/JzUkEGGdQCAFBLAwQUAAAACAAAACEA2YDFkhYAAAAUAAAADAAAAHZlcnNpb24uanNvbqtWSk7MLMqPL8hMVbJSUDLUM1SqBQBQSwECFAMUAAAACAAAACEAeMrbqV0BAACjAwAADQAAAAAAAAAAAAAAgAEAAAAAbWV0YWRhdGEuanNvblBLAQIUAxQAAAAIAAAAIQCGwnm91QEAAMANAAAKAAAAAAAAAAAAAACAAYgBAABtZW1vcnkuYmluUEsBAhQDFAAAAAgAAAAhAKwgWIQtAAAAMwAAABQAAAAAAAAAAAAAAIABhQMAAGFkZGl0aW9uYWxfZGF0YS5qc29uUEsBAhQDFAAAAAgAAAAhAGFiijxPAAAAVwAAABgAAAAAAAAAAAAAAIAB5AMAAGV4ZWN1dGlvbl9yZXNvdXJjZXMuanNvblBLAQIUAxQAAAAIAAAAIQDZgMWSFgAAABQAAAAMAAAAAAAAAAAAAACAAWkEAAB2ZXJzaW9uLmpzb25QSwUGAAAAAAUABQA1AQAAqQQAAAAA
1 change: 1 addition & 0 deletions crates/public/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ pub mod options;
pub mod router;
pub mod services;
pub mod tests;
pub mod utils;
2 changes: 0 additions & 2 deletions crates/public/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ use tracing::info;
#[tokio::main]
async fn main() {
let options: Options = CliArgs::default_run_or_get_options(env!("APP_VERSION"));
println!("options: {:?}", options);

init_telemetry(
options.service_name.as_str(),
options.exporter_endpoint.as_str(),
Expand Down
3 changes: 2 additions & 1 deletion crates/public/src/services/job.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use std::sync::Arc;
use irelia_core::entities::job::{JobEntity, JobId, JobStatus};
use irelia_core::ports::job::JobPort;
use serde::{Deserialize, Serialize};
use starknet_os::sharp::CairoJobStatus;
use tracing::log::info;
use uuid::Uuid;

Expand All @@ -22,7 +23,7 @@ impl JobService {
pub async fn add_job(
&self,
params: NewWorkerJob,
job_status: JobStatus,
job_status: CairoJobStatus,
validation_done_value: bool,
) -> Result<(), AppError> {
let job = self
Expand Down
21 changes: 14 additions & 7 deletions crates/public/src/services/worker_job.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
use std::{str::FromStr, sync::Arc};

use irelia_core::entities::job::JobStatus::InProgress;
use irelia_core::entities::worker_job::WorkerJobStatus::{
AdditionalBadFlag, IncorrectLayout, IncorrectOffchainProof, NoCairoJobId, Successfully,
};
use irelia_core::entities::worker_job::{
ProofLayout, WorkerJobEntity, WorkerJobId, WorkerJobStatus,
WorkerJobEntity, WorkerJobId, WorkerJobStatus,
};
use irelia_core::ports::worker::WorkerPort;
use serde::{Deserialize, Serialize};
use stone_cli::args::LayoutName;
use starknet_os::sharp::CairoJobStatus::IN_PROGRESS;
use uuid::Uuid;

use crate::controllers::worker_job::{CairoPieReq, NewWorkerJob};
use crate::errors::AppError;
use crate::services::job::JobService;
use crate::utils::save_cairo_pie;

const SUCCESSFULLY_CODE: &str = "JOB_RECEIVED_SUCCESSFULLY";
const INTERNAL_SERVER_ERROR_CODE: &str = "500";
Expand Down Expand Up @@ -43,6 +45,11 @@ impl WorkerJobService {
return Ok(WorkerJobResponse::get_worker_job_response(response_code));
}

let cairo_pie = save_cairo_pie(&req.request.cairo_pie, &*params.clone().cairo_job_key.unwrap())
.expect("Failed to save cairo pie")
.to_string_lossy()
.to_string();

let _ = self
.worker_job
.add(WorkerJobEntity {
Expand All @@ -51,21 +58,22 @@ impl WorkerJobService {
cairo_job_key: params.clone().cairo_job_key.unwrap(),
offchain_proof: params.clone().offchain_proof,
proof_layout: params.clone().proof_layout,
cairo_pie: req.request.cairo_pie,
cairo_pie
})
.await?;

if response_code == AdditionalBadFlag {
let _ = job_service.add_job(params.clone(), InProgress, true).await;
let _ = job_service.add_job(params.clone(), IN_PROGRESS, true).await;
return Ok(WorkerJobResponse::get_worker_job_response(response_code))
}
let _ = job_service.add_job(params, InProgress, false).await;

let _ = job_service.add_job(params, IN_PROGRESS, false).await;
Ok(WorkerJobResponse::get_worker_job_response(response_code))
}

pub fn check_job(params: NewWorkerJob) -> WorkerJobStatus {
// Check incorrect layout
match ProofLayout::from_str(params.proof_layout.to_lowercase().as_str()) {
match LayoutName::from_str(params.proof_layout.to_lowercase().as_str()) {
Ok(_) => (),
_ => {
return IncorrectLayout;
Expand Down Expand Up @@ -115,7 +123,6 @@ impl WorkerJobResponse {

pub fn get_worker_job_response(code: WorkerJobStatus) -> Self {
match code {
WorkerJobStatus::FaultyCairoPie => Self::successfully(),
IncorrectLayout => Self::internal_server_error(),
AdditionalBadFlag => Self::successfully(),
NoCairoJobId => Self::internal_server_error(),
Expand Down
Loading

0 comments on commit 640a9fa

Please sign in to comment.