2024-02-09 07:48:44 +00:00
|
|
|
use std::{path::Path};
|
|
|
|
|
2024-03-22 20:06:56 +00:00
|
|
|
use zeroize::Zeroizing;
|
|
|
|
use ciphersuite::{group::ff::PrimeField, Ciphersuite, Ristretto};
|
|
|
|
|
2024-02-09 07:48:44 +00:00
|
|
|
use crate::{Network, Os, mimalloc, os, build_serai_service, write_dockerfile};
|
|
|
|
|
2024-03-22 20:06:56 +00:00
|
|
|
pub fn serai(
|
|
|
|
orchestration_path: &Path,
|
|
|
|
network: Network,
|
|
|
|
serai_key: &Zeroizing<<Ristretto as Ciphersuite>::F>,
|
|
|
|
) {
|
2024-02-09 07:48:44 +00:00
|
|
|
// Always builds in release for performance reasons
|
|
|
|
let setup = mimalloc(Os::Debian).to_string() + &build_serai_service(true, "", "serai-node");
|
2024-02-24 19:51:06 +00:00
|
|
|
let setup_fast_epoch =
|
|
|
|
mimalloc(Os::Debian).to_string() + &build_serai_service(true, "fast-epoch", "serai-node");
|
2024-02-09 07:48:44 +00:00
|
|
|
|
2024-03-22 20:06:56 +00:00
|
|
|
let env_vars = [("KEY", hex::encode(serai_key.to_repr()))];
|
|
|
|
let mut env_vars_str = String::new();
|
|
|
|
for (env_var, value) in env_vars {
|
2024-03-22 21:11:44 +00:00
|
|
|
env_vars_str += &format!(r#"{env_var}=${{{env_var}:="{value}"}} "#);
|
2024-03-22 20:06:56 +00:00
|
|
|
}
|
|
|
|
|
2024-02-09 07:48:44 +00:00
|
|
|
let run_serai = format!(
|
|
|
|
r#"
|
|
|
|
# Copy the Serai binary and relevant license
|
|
|
|
COPY --from=builder --chown=serai /serai/bin/serai-node /bin/
|
|
|
|
COPY --from=builder --chown=serai /serai/AGPL-3.0 .
|
|
|
|
|
|
|
|
# Run the Serai node
|
2024-03-22 20:06:56 +00:00
|
|
|
EXPOSE 30333 9944
|
2024-02-09 07:48:44 +00:00
|
|
|
|
|
|
|
ADD /orchestration/{}/serai/run.sh /
|
2024-03-22 20:06:56 +00:00
|
|
|
CMD {env_vars_str} "/run.sh"
|
2024-02-09 07:48:44 +00:00
|
|
|
"#,
|
2024-03-22 06:19:09 +00:00
|
|
|
network.label(),
|
2024-02-09 07:48:44 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
let run = os(Os::Debian, "", "serai") + &run_serai;
|
|
|
|
let res = setup + &run;
|
2024-02-24 19:51:06 +00:00
|
|
|
let res_fast_epoch = setup_fast_epoch + &run;
|
2024-02-09 07:48:44 +00:00
|
|
|
|
|
|
|
let mut serai_path = orchestration_path.to_path_buf();
|
|
|
|
serai_path.push("serai");
|
2024-02-24 19:51:06 +00:00
|
|
|
|
|
|
|
let mut serai_fast_epoch_path = serai_path.clone();
|
|
|
|
|
2024-02-09 07:48:44 +00:00
|
|
|
serai_path.push("Dockerfile");
|
2024-02-24 19:51:06 +00:00
|
|
|
serai_fast_epoch_path.push("Dockerfile.fast-epoch");
|
2024-02-09 07:48:44 +00:00
|
|
|
|
|
|
|
write_dockerfile(serai_path, &res);
|
2024-02-24 19:51:06 +00:00
|
|
|
write_dockerfile(serai_fast_epoch_path, &res_fast_epoch);
|
2024-02-09 07:48:44 +00:00
|
|
|
}
|