Skip to content

Commit

Permalink
Permissions and tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
kayabaNerve committed Feb 4, 2024
1 parent 7468898 commit 9bdab21
Show file tree
Hide file tree
Showing 14 changed files with 38 additions and 23 deletions.
Empty file modified orchestration/dev/coins/bitcoin/scripts/run.sh
100644 → 100755
Empty file.
Empty file modified orchestration/dev/coins/ethereum/scripts/run.sh
100644 → 100755
Empty file.
Empty file modified orchestration/dev/coins/monero-wallet-rpc/scripts/run.sh
100644 → 100755
Empty file.
Empty file modified orchestration/dev/coins/monero/scripts/run.sh
100644 → 100755
Empty file.
Empty file modified orchestration/dev/serai/scripts/run.sh
100644 → 100755
Empty file.
9 changes: 6 additions & 3 deletions orchestration/src/coins/bitcoin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ use std::{path::Path};

use crate::{Network, Os, mimalloc, os, write_dockerfile};

#[rustfmt::skip]
pub fn bitcoin(orchestration_path: &Path, network: Network) {
#[rustfmt::skip]
const DOWNLOAD_BITCOIN: &str = r#"
FROM alpine:latest as bitcoin
Expand Down Expand Up @@ -31,14 +31,17 @@ RUN mv bitcoin-${BITCOIN_VERSION}/bin/bitcoind .

let setup = mimalloc(Os::Debian).to_string() + DOWNLOAD_BITCOIN;

let run_bitcoin = format!(r#"
let run_bitcoin = format!(
r#"
COPY --from=bitcoin --chown=bitcoin bitcoind /bin
EXPOSE 8332 8333
ADD /orchestration/{}/coins/bitcoin/scripts /scripts
CMD ["/scripts/run.sh"]
"#, network.folder());
"#,
network.folder()
);

let run = os(Os::Debian, "", "bitcoin") + &run_bitcoin;
let res = setup + &run;
Expand Down
1 change: 0 additions & 1 deletion orchestration/src/coins/ethereum.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use std::path::Path;

#[rustfmt::skip]
pub fn ethereum(_orchestration_path: &Path) {
// TODO
}
26 changes: 17 additions & 9 deletions orchestration/src/coins/monero.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,15 @@ use std::{path::Path};

use crate::{Network, Os, mimalloc, write_dockerfile};

#[rustfmt::skip]
fn monero_internal(network: Network, os: Os, orchestration_path: &Path, folder: &str, monero_binary: &str, ports: &str) {
fn monero_internal(
network: Network,
os: Os,
orchestration_path: &Path,
folder: &str,
monero_binary: &str,
ports: &str,
) {
#[rustfmt::skip]
const DOWNLOAD_MONERO: &str = r#"
FROM alpine:latest as monero
Expand Down Expand Up @@ -32,20 +39,21 @@ RUN tar -xvjf monero-linux-x64-v${MONERO_VERSION}.tar.bz2 --strip-components=1

let setup = mimalloc(os).to_string() + DOWNLOAD_MONERO;

let run_monero = format!(r#"
let run_monero = format!(
r#"
COPY --from=monero --chown=monero {monero_binary} /bin
EXPOSE {ports}
ADD /orchestration/{}/coins/{folder}/scripts /scripts
CMD ["/scripts/run.sh"]
"#, network.folder());
"#,
network.folder()
);

let run = crate::os(
os,
if os == Os::Alpine { "RUN apk --no-cache add gcompat" } else { "" },
"monero"
) + &run_monero;
let run =
crate::os(os, if os == Os::Alpine { "RUN apk --no-cache add gcompat" } else { "" }, "monero") +
&run_monero;
let res = setup + &run;

let mut monero_path = orchestration_path.to_path_buf();
Expand Down
20 changes: 12 additions & 8 deletions orchestration/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,10 @@ enum Os {
Debian,
}

#[rustfmt::skip]
fn os(os: Os, additional_root: &str, user: &str) -> String {
match os {
Os::Alpine => format!(r#"
Os::Alpine => format!(
r#"
FROM alpine:latest as image
COPY --from=mimalloc-alpine libmimalloc.so /usr/lib
Expand All @@ -74,9 +74,11 @@ RUN adduser -S -s /sbin/nologin -D {user}
USER {user}
WORKDIR /home/{user}
"#),
"#
),

Os::Debian => format!(r#"
Os::Debian => format!(
r#"
FROM debian:bookworm-slim as image
COPY --from=mimalloc-debian libmimalloc.so /usr/lib
Expand All @@ -90,16 +92,17 @@ RUN useradd --system --create-home --shell /sbin/nologin {user}
USER {user}
WORKDIR /home/{user}
"#),
"#
),
}
}

#[rustfmt::skip]
fn build_serai_service(release: bool, features: &str, package: &str) -> String {
let profile = if release { "release" } else { "debug" };
let profile_flag = if release { "--release" } else { "" };

format!(r#"
format!(
r#"
FROM rust:1.75-slim-bookworm as builder
COPY --from=mimalloc-debian libmimalloc.so /usr/lib
Expand Down Expand Up @@ -142,7 +145,8 @@ RUN --mount=type=cache,target=/root/.cargo \
mkdir /serai/bin && \
cargo build {profile_flag} --features "{features}" -p {package} && \
mv /serai/target/{profile}/{package} /serai/bin
"#)
"#
)
}

pub fn write_dockerfile(path: PathBuf, dockerfile: &str) {
Expand Down
1 change: 0 additions & 1 deletion orchestration/src/mimalloc.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use crate::Os;

#[rustfmt::skip]
pub fn mimalloc(os: Os) -> &'static str {
const ALPINE_MIMALLOC: &str = r#"
FROM alpine:latest as mimalloc-alpine
Expand Down
Empty file modified orchestration/testnet/coins/bitcoin/scripts/run.sh
100644 → 100755
Empty file.
Empty file modified orchestration/testnet/coins/ethereum/scripts/run.sh
100644 → 100755
Empty file.
Empty file modified orchestration/testnet/coins/monero/scripts/run.sh
100644 → 100755
Empty file.
4 changes: 3 additions & 1 deletion tests/docker/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,9 @@ pub fn build(name: String) {

let mut orchestration_path = repo_path.clone();
orchestration_path.push("orchestration");
orchestration_path.push("dev");
if name != "runtime" {
orchestration_path.push("dev");
}

let mut dockerfile_path = orchestration_path.clone();
if HashSet::from(["bitcoin", "ethereum", "monero"]).contains(name.as_str()) {
Expand Down

0 comments on commit 9bdab21

Please sign in to comment.