Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions crates/cli/src/docker_init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ use cb_common::{
SIGNER_DIR_SECRETS_ENV, SIGNER_KEYS_ENV, SIGNER_MODULE_NAME, SIGNER_PORT_ENV,
SIGNER_URL_ENV,
},
pbs::{BUILDER_API_PATH, GET_STATUS_PATH},
signer::{ProxyStore, SignerLoader},
types::ModuleId,
utils::random_jwt,
Expand Down Expand Up @@ -295,6 +296,17 @@ pub async fn handle_docker_init(config_path: String, output_dir: String) -> Resu
networks: pbs_networs,
volumes: pbs_volumes,
environment: Environment::KvPair(pbs_envs),
healthcheck: Some(Healthcheck {
test: Some(HealthcheckTest::Single(format!(
"curl -f http://localhost:{}{}{}",
cb_config.pbs.pbs_config.port, BUILDER_API_PATH, GET_STATUS_PATH
))),
interval: Some("30s".into()),
timeout: Some("5s".into()),
retries: 3,
start_period: Some("5s".into()),
disable: false,
}),
..Service::default()
};

Expand Down Expand Up @@ -413,10 +425,10 @@ pub async fn handle_docker_init(config_path: String, output_dir: String) -> Resu
test: Some(HealthcheckTest::Single(format!(
"curl -f http://localhost:{signer_port}/status"
))),
interval: Some("5s".into()),
interval: Some("30s".into()),
timeout: Some("5s".into()),
retries: 5,
start_period: Some("0s".into()),
retries: 3,
start_period: Some("5s".into()),
disable: false,
}),
..Service::default()
Expand Down
33 changes: 27 additions & 6 deletions crates/pbs/src/service.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
use cb_common::constants::COMMIT_BOOST_VERSION;
use std::time::Duration;

use cb_common::{
constants::COMMIT_BOOST_VERSION,
pbs::{BUILDER_API_PATH, GET_STATUS_PATH},
};
use cb_metrics::provider::MetricsProvider;
use eyre::{Context, Result};
use eyre::{bail, Context, Result};
use prometheus::core::Collector;
use tokio::net::TcpListener;
use tracing::info;
use url::Url;

use crate::{
api::BuilderApi,
Expand All @@ -16,15 +22,30 @@ pub struct PbsService;

impl PbsService {
pub async fn run<S: BuilderApiState, A: BuilderApi<S>>(state: PbsState<S>) -> Result<()> {
let address = state.config.endpoint;
let addr = state.config.endpoint;
let events_subs =
state.config.event_publisher.as_ref().map(|e| e.n_subscribers()).unwrap_or_default();
info!(version = COMMIT_BOOST_VERSION, ?address, events_subs, chain =? state.config.chain, "starting PBS service");
info!(version = COMMIT_BOOST_VERSION, ?addr, events_subs, chain =? state.config.chain, "starting PBS service");

let app = create_app_router::<S, A>(state);
let listener = TcpListener::bind(address).await?;
let listener = TcpListener::bind(addr).await?;

let task =
tokio::spawn(
async move { axum::serve(listener, app).await.wrap_err("PBS server exited") },
);

// wait for the server to start
tokio::time::sleep(Duration::from_millis(250)).await;
let local_url =
Url::parse(&format!("http://{}{}{}", addr, BUILDER_API_PATH, GET_STATUS_PATH))?;

let status = reqwest::get(local_url).await?;
if !status.status().is_success() {
bail!("PBS server failed to start. Are the relays properly configured?");
}

axum::serve(listener, app).await.wrap_err("PBS server exited")
task.await?
}

pub fn register_metric(c: Box<dyn Collector>) {
Expand Down
1 change: 1 addition & 0 deletions docker/pbs.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ RUN apt-get update && apt-get install -y \
ca-certificates \
libssl3 \
libssl-dev \
curl \
&& apt-get clean autoclean \
&& rm -rf /var/lib/apt/lists/*

Expand Down
Loading