add MODE env variable

This commit is contained in:
Ruben Fiszel
2023-10-16 15:20:50 +02:00
parent f9e48ddcba
commit b18ab1d154
4 changed files with 55 additions and 16 deletions
+5 -4
View File
@@ -229,8 +229,9 @@ We publish helm charts at:
### Run from binaries
Each release includes the corresponding binaries for x86_64. You can simply download the
Each release includes the corresponding binaries for x86_64. You can simply download the
latest `windmill` binary using the following set of bash commands.
```bash
BINARY_NAME='windmill-amd64' # or windmill-ee-amd64 for the enterprise edition
LATEST_RELEASE=$(curl -L -s -H 'Accept: application/json' https://github.com/windmill-labs/windmill/releases/latest)
@@ -266,19 +267,18 @@ You will also want to import all the approved resource types from
[WindmillHub](https://hub.windmill.dev). A setup script will prompt you to have
it being synced automatically everyday.
## Environment Variables
| Environment Variable name | Default | Description | Api Server/Worker/All |
| --------------------------------------------- | ------------------------------------------ | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------- |
| DATABASE_URL | | The Postgres database url. | All |
| WORKER_GROUP | default | The worker group the worker belongs to and get its configuration pulled from | Worker |
| MODE | standalone | The mode if the binary. Possible values: standalone, worker, server | All |
| SERVER_BIND_ADDR | 0.0.0.0 | IP Address on which to bind listening socket | Server |
| PORT | 8000 | Exposed port | Server |
| DISABLE_SERVER | false | Disable the external API, operate as a worker only instance | Worker |
| METRICS_ADDR | None | (ee only) The socket addr at which to expose Prometheus metrics at the /metrics path. Set to "true" to expose it on port 8001 | All |
| JSON_FMT | false | Output the logs in json format instead of logfmt | All |
| BASE_URL | http://localhost:8000 | The base url that is exposed publicly to access your instance | Server |
| BASE_URL | http://localhost:8000 | The base url that is exposed publicly to access your instance. Is overriden by the instance settings if any. | Server |
| TIMEOUT | 60 _ 60 _ 24 \* 7 (1 week) | The maximum time of execution of a script. When reached, the job is failed as having timedout. |
| SCRIPT_TOKEN_EXPIRY | 900 | The default duration period of the ephemeral-token generated at the beginning of a script | Worker |
| ZOMBIE_JOB_TIMEOUT | 30 | The timeout after which a job is considered to be zombie if the worker did not send pings about processing the job (every server check for zombie jobs every 30s) | Server |
@@ -344,6 +344,7 @@ it being synced automatically everyday.
| SECRET_SALT | None | Secret Salt used for encryption and decryption of secrets. If defined, the secrets will not be decryptable unless the right salt is passed in, which is the case for the workers and the server | Server + Worker |
| OPENAI_AZURE_BASE_PATH | None | Azure OpenAI API base path (no trailing slash) | Server |
| DISABLE_NSJAIL | true | Disable Nsjail Sandboxing | Worker |
| DISABLE_SERVER | false | Disable the external API, operate as a worker only instance | Worker |
## Run a local dev setup
+45 -6
View File
@@ -9,6 +9,7 @@
use gethostname::gethostname;
use git_version::git_version;
use rand::Rng;
use serde::Deserialize;
use sqlx::{postgres::PgListener, Pool, Postgres};
use std::{
net::{IpAddr, Ipv4Addr, SocketAddr},
@@ -50,6 +51,14 @@ const DEFAULT_SERVER_BIND_ADDR: Ipv4Addr = Ipv4Addr::new(0, 0, 0, 0);
mod ee;
mod monitor;
#[derive(Deserialize, PartialEq)]
#[serde(rename_all = "lowercase")]
pub enum Mode {
Worker,
Server,
Standalone,
}
#[tokio::main]
async fn main() -> anyhow::Result<()> {
dotenv::dotenv().ok();
@@ -60,20 +69,50 @@ async fn main() -> anyhow::Result<()> {
#[cfg(feature = "flamegraph")]
let _guard = windmill_common::tracing_init::setup_flamegraph();
let num_workers = std::env::var("NUM_WORKERS")
.ok()
.and_then(|x| x.parse::<i32>().ok())
.unwrap_or(DEFAULT_NUM_WORKERS as i32);
let mode = std::env::var("MODE")
.map(|x| x.to_lowercase())
.map(|x| {
if &x == "server" {
tracing::info!("Binary is in 'server' mode");
Mode::Server
} else if &x == "worker" {
tracing::info!("Binary is in 'worker' mode");
Mode::Worker
} else {
if &x != "standalone" {
tracing::error!("mode not recognized, defaulting to standalone: {x}");
} else {
tracing::info!("Binary is in 'standalone' mode");
}
Mode::Standalone
}
})
.unwrap_or_else(|_| {
tracing::info!("Mode not specified, defaulting to standalone");
Mode::Standalone
});
let num_workers = if mode == Mode::Server {
0
} else {
std::env::var("NUM_WORKERS")
.ok()
.and_then(|x| x.parse::<i32>().ok())
.unwrap_or(DEFAULT_NUM_WORKERS as i32)
};
if num_workers > 1 {
tracing::warn!("We STRONGLY recommend using at most 1 worker per container, unless this worker is dedicated to native jobs only. ");
tracing::warn!(
"We STRONGLY recommend using at most 1 worker per container, use at your own risks"
);
}
let metrics_addr: Option<SocketAddr> = *METRICS_ADDR;
let server_mode = !std::env::var("DISABLE_SERVER")
.ok()
.and_then(|x| x.parse::<bool>().ok())
.unwrap_or(false);
.unwrap_or(false)
&& mode != Mode::Worker;
let server_bind_address: IpAddr = if server_mode {
std::env::var("SERVER_BIND_ADDR")
@@ -10,7 +10,7 @@ pub const EXTRA_PIP_INDEX_URL_SETTING: &str = "pip_extra_index_url";
pub const ENV_SETTINGS: [&str; 54] = [
"DISABLE_NSJAIL",
"DISABLE_SERVER",
"MODE",
"NUM_WORKERS",
"METRICS_ADDR",
"JSON_FMT",
+4 -5
View File
@@ -31,9 +31,8 @@ services:
environment:
- DATABASE_URL=${DATABASE_URL}
- RUST_LOG=info
- MODE=server
## You can set the number of workers to 1 and not need any separate worker service but not recommended
- NUM_WORKERS=0
- DISABLE_SERVER=false
- METRICS_ADDR=false # (ee only, if set to true, metrics will be exposed on port 8001)
depends_on:
db:
@@ -52,7 +51,7 @@ services:
environment:
- DATABASE_URL=${DATABASE_URL}
- RUST_LOG=info
- DISABLE_SERVER=true
- MODE=worker
- KEEP_JOB_DIR=false
- METRICS_ADDR=false
- WORKER_GROUP=default
@@ -80,9 +79,9 @@ services:
environment:
- DATABASE_URL=${DATABASE_URL}
- RUST_LOG=info
- DISABLE_SERVER=true
- METRICS_ADDR=false # (ee only, if set to true, metrics will be exposed on port 8001)
- MODE=worker
- WORKER_GROUP=native
- METRICS_ADDR=false # (ee only, if set to true, metrics will be exposed on port 8001)
depends_on:
db:
condition: service_healthy