Skip to content

Commit

Permalink
merge: #2715
Browse files Browse the repository at this point in the history
2715: paul/fixup johns pr r=stack72 a=stack72

- feat(si): add sdf-host and sdf-port options to si launcher
- chore: amended minor typo in community check workflow


Co-authored-by: John Watson <[email protected]>
  • Loading branch information
si-bors-ng[bot] and johnrwatson authored Aug 30, 2023
2 parents 83df6f1 + 366ea7e commit 07cda95
Show file tree
Hide file tree
Showing 10 changed files with 89 additions and 20 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/community-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
run: |
PR_AUTHOR="${{ github.event.pull_request.user.login }}"
if ! [[ "${SI_STAFF}" =~ "$PR_AUTHOR" ]]; then
echo "Authored by one of our amazing cmmunity peeps!"
echo "Authored by one of our amazing community peeps!"
echo "requires-community-tag=true" >> $GITHUB_OUTPUT
else
echo "Successfully checked the author against the staff list"
Expand Down
1 change: 1 addition & 0 deletions CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,4 @@ We contributors to System Initiative:
* Dan Miller (@jazzdan)
* Neil Hanlon (@NeilHanlon)
* Matthew Sanabria (@sudomateo)
* John Watson (@johnrwatson)
8 changes: 8 additions & 0 deletions bin/si/src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,14 @@ pub(crate) struct Args {
#[arg(long = "web-port", env = "SI_WEB_PORT", default_value = "8080")]
pub web_port: u32,

/// Allows starting the sdf service and binding to a specific IP
#[arg(long = "sdf-host", env = "SI_SDF_ADDRESS", default_value = "127.0.0.1")]
pub sdf_host: String,

/// Allows starting the sdf service and binding to a specific port
#[arg(long = "sdf-port", env = "SI_SDF_PORT", default_value = "5156")]
pub sdf_port: u32,

/// The engine in which to launch System Initiate Containers
#[arg(value_parser = PossibleValuesParser::new(Engine::variants()))]
#[arg(long, short, env = "SI_CONTAINER_ENGINE", default_value = "docker")]
Expand Down
5 changes: 5 additions & 0 deletions bin/si/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ async fn main() -> Result<()> {
let web_host = args.web_host.clone();
let web_port = args.web_port;

let sdf_host = args.sdf_host.clone();
let sdf_port = args.sdf_port;

let current_version = VERSION.trim();

debug!(arguments =?args, "parsed cli arguments");
Expand All @@ -49,6 +52,8 @@ async fn main() -> Result<()> {
is_preview,
web_host,
web_port,
sdf_host,
sdf_port,
args.with_function_debug_logs,
Arc::from(engine),
);
Expand Down
33 changes: 24 additions & 9 deletions lib/si-cli/src/cmd/launch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,14 @@ use std::{env, thread};

impl AppState {
pub async fn launch(&self, launch_metrics: bool) -> CliResult<()> {
invoke(launch_metrics, self.web_host(), self.web_port()).await?;
invoke(
launch_metrics,
self.web_host(),
self.web_port(),
self.sdf_host(),
self.sdf_port(),
)
.await?;
self.track(
get_user_email().await?,
serde_json::json!({"command-name": "launch-ui"}),
Expand All @@ -17,16 +24,22 @@ impl AppState {
}
}

async fn invoke(launch_metrics: bool, web_host: String, web_port: u32) -> CliResult<()> {
async fn invoke(
launch_metrics: bool,
web_host: String,
web_port: u32,
sdf_host: String,
sdf_port: u32,
) -> CliResult<()> {
let path = if launch_metrics {
"http://localhost:16686".to_string()
} else {
format!("http://{0}:{1}", web_host, web_port)
};

if path == format!("http://{0}:{1}", web_host, web_port) {
check_web(web_port).await?;
check_sdf().await?;
check_web(web_host, web_port).await?;
check_sdf(sdf_host, sdf_port).await?;
}

let output = if cfg!(target_os = "macos") {
Expand All @@ -48,8 +61,8 @@ async fn invoke(launch_metrics: bool, web_host: String, web_port: u32) -> CliRes
Ok(())
}

async fn check_web(web_port: u32) -> CliResult<()> {
let path = format!("http://localhost:{0}", web_port);
async fn check_web(web_host: String, web_port: u32) -> CliResult<()> {
let path = format!("http://{0}:{1}", web_host, web_port);
let resp = reqwest::get(path).await;
if let Err(_e) = resp {
return Err(SiCliError::WebPortal());
Expand All @@ -58,20 +71,22 @@ async fn check_web(web_port: u32) -> CliResult<()> {
Ok(())
}

async fn check_sdf() -> CliResult<()> {
async fn check_sdf(sdf_host: String, sdf_port: u32) -> CliResult<()> {
let spinner_style = ProgressStyle::with_template("{prefix:.bold.dim} {spinner} {wide_msg}")
.unwrap()
.tick_chars("⠁⠂⠄⡀⢀⠠⠐⠈ ");
let sdf_path = "http://localhost:5156/api/";
let sdf_path = format!("http://{0}:{1}/api/", sdf_host, sdf_port);

let mut is_ready = false;
let sdf_path_clone = sdf_path.clone(); // Clone sdf_path for use inside the async block

let h = tokio::spawn(async move {
let count = 200;
let pb = ProgressBar::new(count);
pb.set_style(spinner_style.clone());
while !is_ready {
loop {
match reqwest::get(sdf_path).await {
match reqwest::get(&sdf_path_clone).await {
Ok(x) => {
if x.status().as_u16() == 200 {
is_ready = true;
Expand Down
4 changes: 3 additions & 1 deletion lib/si-cli/src/cmd/start.rs
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,8 @@ async fn invoke(app: &AppState, is_preview: bool) -> CliResult<()> {
.create_sdf(
container_name.clone(),
container.clone(),
app.sdf_host(),
app.sdf_port(),
si_data_dir.clone(),
)
.await?;
Expand Down Expand Up @@ -383,8 +385,8 @@ async fn invoke(app: &AppState, is_preview: bool) -> CliResult<()> {
.create_web(
container_name.clone(),
container.clone(),
app.web_port(),
app.web_host(),
app.web_port(),
)
.await?;
}
Expand Down
11 changes: 9 additions & 2 deletions lib/si-cli/src/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,20 @@ pub trait ContainerEngine {
with_debug_logs: bool,
) -> CliResult<()>;
async fn create_pinga(&self, name: String, image: String, data_dir: PathBuf) -> CliResult<()>;
async fn create_sdf(&self, name: String, image: String, data_dir: PathBuf) -> CliResult<()>;
async fn create_web(
async fn create_sdf(
&self,
name: String,
image: String,
host_ip: String,
host_port: u32,
data_dir: PathBuf,
) -> CliResult<()>;
async fn create_web(
&self,
name: String,
image: String,
host_ip: String,
host_port: u32,
) -> CliResult<()>;
}

Expand Down
16 changes: 13 additions & 3 deletions lib/si-cli/src/engine/docker_engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,14 @@ impl ContainerEngine for DockerEngine {
Ok(())
}

async fn create_sdf(&self, name: String, image: String, data_dir: PathBuf) -> CliResult<()> {
async fn create_sdf(
&self,
name: String,
image: String,
host_ip: String,
host_port: u32,
data_dir: PathBuf,
) -> CliResult<()> {
let create_opts = ContainerCreateOpts::builder()
.name(name)
.image(format!("{0}:stable", image))
Expand All @@ -454,7 +461,10 @@ impl ContainerEngine for DockerEngine {
])
.network_mode("bridge")
.restart_policy("on-failure", 3)
.expose(PublishPort::tcp(5156), HostPort::new(5156))
.expose(
PublishPort::tcp(5156),
HostPort::with_ip(host_port, host_ip),
)
.volumes([
format!(
"{}:/run/sdf/cyclone_encryption.key:z",
Expand All @@ -476,8 +486,8 @@ impl ContainerEngine for DockerEngine {
&self,
name: String,
image: String,
host_port: u32,
host_ip: String,
host_port: u32,
) -> CliResult<()> {
let create_opts = ContainerCreateOpts::builder()
.name(name)
Expand Down
15 changes: 11 additions & 4 deletions lib/si-cli/src/engine/podman_engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -636,7 +636,14 @@ impl ContainerEngine for PodmanEngine {
Ok(())
}

async fn create_sdf(&self, name: String, image: String, data_dir: PathBuf) -> CliResult<()> {
async fn create_sdf(
&self,
name: String,
image: String,
host_ip: String,
host_port: u32,
data_dir: PathBuf,
) -> CliResult<()> {
let create_opts = ContainerCreateOpts::builder()
.name(name.clone())
.image(format!("{0}:stable", image.clone()))
Expand All @@ -660,8 +667,8 @@ impl ContainerEngine for PodmanEngine {
]))
.portmappings(vec![PortMapping {
container_port: Some(5156),
host_port: Some(5156),
host_ip: None,
host_port: Some(host_port.try_into().unwrap()),
host_ip: Some(host_ip),
protocol: None,
range: None,
}])
Expand Down Expand Up @@ -710,8 +717,8 @@ impl ContainerEngine for PodmanEngine {
&self,
name: String,
image: String,
host_port: u32,
host_ip: String,
host_port: u32,
) -> CliResult<()> {
let create_opts = ContainerCreateOpts::builder()
.name(name.clone())
Expand Down
14 changes: 14 additions & 0 deletions lib/si-cli/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ pub struct AppState {
is_preview: bool,
web_host: String,
web_port: u32,
sdf_host: String,
sdf_port: u32,
with_function_debug_logs: bool,
container_engine: Arc<Box<dyn ContainerEngine>>,
}
Expand All @@ -25,6 +27,8 @@ impl AppState {
is_preview: bool,
web_host: String,
web_port: u32,
sdf_host: String,
sdf_port: u32,
with_function_debug_logs: bool,
container_engine: Arc<Box<dyn ContainerEngine>>,
) -> Self {
Expand All @@ -35,6 +39,8 @@ impl AppState {
is_preview,
web_host,
web_port,
sdf_host,
sdf_port,
with_function_debug_logs,
container_engine,
}
Expand Down Expand Up @@ -64,6 +70,14 @@ impl AppState {
self.web_port
}

pub fn sdf_host(&self) -> String {
self.sdf_host.clone()
}

pub fn sdf_port(&self) -> u32 {
self.sdf_port
}

pub fn posthog_client(&self) -> &PosthogClient {
&self.posthog_client
}
Expand Down

0 comments on commit 07cda95

Please sign in to comment.