Skip to content

Commit

Permalink
Add Dockerfile and docker-compose
Browse files Browse the repository at this point in the history
  • Loading branch information
jimouris committed Feb 9, 2024
1 parent 9cd3ef2 commit cc4cf48
Show file tree
Hide file tree
Showing 5 changed files with 107 additions and 11 deletions.
20 changes: 20 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
FROM rust:latest AS build

ENV BASE /usr/local
ADD . /opt/mastic
WORKDIR /opt/mastic
RUN cargo build --release --workspace --target-dir /opt/mastic/bin

# cleanup everything except binaries
RUN mkdir -p /opt/mastic/exec && \
cp bin/release/server exec && \
cp bin/release/driver exec

# Thin container with binaries base image is taken from
# https://hub.docker.com/_/debian/
FROM debian:stable-slim AS mastic
COPY --from=build /opt/mastic/exec /opt/mastic/bin
COPY --from=build /opt/mastic/src/configs/attribute-based-metrics.toml /opt/mastic/bin/
COPY --from=build /opt/mastic/src/configs/plain-metrics.toml /opt/mastic/bin/
COPY --from=build /opt/mastic/src/configs/weighted-heavy-hitters.toml /opt/mastic/bin/
WORKDIR /opt/mastic
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,18 @@
<a href="https://github.com/TrustworthyComputing/mastic/blob/main/LICENSE"><img src="https://img.shields.io/badge/license-MIT-blue.svg"></a>
</h1>

## Build & Run With Docker Compose
The following runs two aggregators and the leader each in a different container
for weighted heavy hitters:
```bash
❯❯ CONFIG=weighted-heavy-hitters.toml docker compose up
```
Similarly, for the two other modes that Mastic supports:
```bash
❯❯ CONFIG=attribute-based-metrics.toml docker compose up
❯❯ CONFIG=plain-metrics.toml docker compose up
```

## Building

First, make sure that you have a working Rust installation:
Expand Down
42 changes: 42 additions & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
version: '3.0'

services:
aggregator-0:
container_name: 'aggregator-0'
image: mastic
build:
context: .
dockerfile: Dockerfile
entrypoint: '/opt/mastic/bin/server'
command: >-
--config bin/${CONFIG}
--server_id 0
aggregator-1:
container_name: 'aggregator-1'
image: mastic
build:
context: .
dockerfile: Dockerfile
entrypoint: '/opt/mastic/bin/server'
command: >-
--config bin/${CONFIG}
--server_id 1
driver:
container_name: 'driver'
depends_on:
aggregator-0:
condition: service_started
aggregator-1:
condition: service_started
image: mastic
build:
context: .
dockerfile: Dockerfile
entrypoint: '/opt/mastic/bin/driver'
command: >-
--config bin/${CONFIG}
--server-0 aggregator-0:8000
--server-1 aggregator-1:8001
-n 1000
4 changes: 2 additions & 2 deletions src/bin/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -692,12 +692,12 @@ async fn main() -> io::Result<()> {
println!("Running with {}% malicious clients", malicious * 100.0);
let client_0 = CollectorClient::new(
client::Config::default(),
tcp::connect(cfg.server_0, Bincode::default).await?,
tcp::connect(cfg.server_0.clone(), Bincode::default).await?,
)
.spawn();
let client_1 = CollectorClient::new(
client::Config::default(),
tcp::connect(cfg.server_1, Bincode::default).await?,
tcp::connect(cfg.server_1.clone(), Bincode::default).await?,
)
.spawn();

Expand Down
40 changes: 31 additions & 9 deletions src/config.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::{fs, net::SocketAddr};
use std::fs;

use clap::{App, Arg};
use serde::Deserialize;
Expand Down Expand Up @@ -51,10 +51,10 @@ pub struct Config {
pub zipf_exponent: f64,

/// The `IP:port` tuple for server 0.
pub server_0: SocketAddr,
pub server_0: String,

/// The `IP:port` tuple for server 1.
pub server_1: SocketAddr,
pub server_1: String,
}

pub fn get_config(filename: &str) -> Config {
Expand All @@ -79,6 +79,24 @@ pub fn get_args(
.help("Location of JSON config file")
.required(true)
.takes_value(true),
)
.arg(
Arg::with_name("server0")
.short("s0")
.long("server-0")
.value_name("STRING")
.help("Aggregator 0 host path to connect to, e.g., 0.0.0.0:8000")
.required(false)
.takes_value(true),
)
.arg(
Arg::with_name("server1")
.short("s0")
.long("server-1")
.value_name("STRING")
.help("Aggregator 1 host path to connect to, e.g., 0.0.0.0:8001")
.required(false)
.takes_value(true),
);
if get_server_id {
flags = flags.arg(
Expand Down Expand Up @@ -115,10 +133,19 @@ pub fn get_args(
}

let flags = flags.get_matches();
let mut config = get_config(flags.value_of("config").unwrap());

let mut server_id = -1;
if get_server_id {
server_id = flags.value_of("server_id").unwrap().parse().unwrap();
} else {
// If it's the leader.
if flags.is_present("server0") {
config.server_0 = flags.value_of("server0").unwrap().parse().unwrap();
}
if flags.is_present("server1") {
config.server_1 = flags.value_of("server1").unwrap().parse().unwrap();
}
}

let mut n_reqs = 0;
Expand All @@ -131,10 +158,5 @@ pub fn get_args(
malicious = flags.value_of("malicious").unwrap().parse::<f32>().unwrap();
}

(
get_config(flags.value_of("config").unwrap()),
server_id,
n_reqs,
malicious,
)
(config, server_id, n_reqs, malicious)
}

0 comments on commit cc4cf48

Please sign in to comment.