Skip to content

Commit f5c4727

Browse files
alpetricellipsis-dev[bot]HugoCasarubenfiszel
authored
feat(worker): support workers to run natively on windows (#4446)
* minimal code change to get windmill worker on windows for bun and python + rustfmt * adding support for powershell * compiling error on unix * rust linting comments * comments hugo: PSModulePath * comments ruben, refactor to simplify * adding build workflow * editing workflow * editing workflow * editing workflow * editing workflow * editing workflow * skip migration env, ee fixes * improvements powershell * testing windows runner * testing windows runner * testing windows runner * testing windows runner * testing windows runner * install postgres on runner * install postgres on runner * install postgres on runner * install postgres on runner * install postgres on runner * install postgres on runner * install postgres on runner * install postgres on runner * killing process tree in windows * sqlx_offline * install openssl for github windows runner * used pre-installed openssl * used pre-installed openssl * build ee * build ee * build ee * build ee * adding commented out steps for artifact publishing * build on tag matchinv v* pattern * ren instead of mv on Windows Co-authored-by: ellipsis-dev[bot] <65095814+ellipsis-dev[bot]@users.noreply.github.com> * fix merging issue * gate imports for windows * fixing default cargo home path... * fixing default cargo home path... * comments ruben * make pwsh default modules loading more robust on unix (#4448) Co-authored-by: Ruben Fiszel <[email protected]> --------- Co-authored-by: ellipsis-dev[bot] <65095814+ellipsis-dev[bot]@users.noreply.github.com> Co-authored-by: HugoCasa <[email protected]> Co-authored-by: Ruben Fiszel <[email protected]>
1 parent 1d8e361 commit f5c4727

File tree

15 files changed

+404
-56
lines changed

15 files changed

+404
-56
lines changed
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
name: Build and Publish Windows Worker
2+
3+
on:
4+
push:
5+
tags:
6+
- "v*"
7+
8+
env:
9+
CARGO_INCREMENTAL: 0
10+
SQLX_OFFLINE: true
11+
DISABLE_EMBEDDING: true
12+
RUST_LOG: info
13+
14+
jobs:
15+
cargo_build_windows:
16+
runs-on: windows-latest
17+
steps:
18+
- uses: actions/checkout@v4
19+
20+
- name: Read EE repo commit hash
21+
shell: pwsh
22+
run: |
23+
$ee_repo_ref = Get-Content .\backend\ee-repo-ref.txt
24+
echo "ee_repo_ref=$ee_repo_ref" | Out-File -FilePath $env:GITHUB_ENV -Append
25+
26+
- name: Checkout windmill-ee-private repository
27+
uses: actions/checkout@v4
28+
with:
29+
repository: windmill-labs/windmill-ee-private
30+
path: ./windmill-ee-private
31+
ref: ${{ env.ee_repo_ref }}
32+
token: ${{ secrets.WINDMILL_EE_PRIVATE_ACCESS }}
33+
fetch-depth: 0
34+
35+
- name: Substitute EE code
36+
shell: bash
37+
run: |
38+
./backend/substitute_ee_code.sh --copy --dir ./windmill-ee-private
39+
40+
- name: Cargo build windows
41+
timeout-minutes: 60
42+
run: |
43+
$env:OPENSSL_DIR = "${Env:ProgramFiles}\OpenSSL"
44+
mkdir frontend/build && cd backend
45+
New-Item -Path . -Name "windmill-api/openapi-deref.yaml" -ItemType "File" -Force
46+
cargo build --release --features=enterprise,stripe,embedding,parquet,prometheus,openidconnect,cloud,jemalloc,tantivy
47+
48+
- name: Rename binary with corresponding architecture
49+
run: |
50+
ren ./backend/target/release/windmill.exe ./backend/target/release/windmill-ee.exe
51+
52+
- name: Attach binary to release
53+
uses: softprops/action-gh-release@v2
54+
with:
55+
files: |
56+
./backend/target/release/windmill-ee.exe

backend/parsers/windmill-parser-yaml/src/lib.rs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -399,15 +399,11 @@ fn parse_ansible_options(opts: &Vec<Yaml>) -> AnsiblePlaybookOptions {
399399
if c > 0 && c <= 6 {
400400
ret.verbosity = Some("v".repeat(c.min(6)));
401401
}
402-
403402
}
404403
}
405-
_ => ()
406-
404+
_ => (),
407405
}
408406
}
409-
410-
411407
}
412408
}
413409

@@ -422,10 +418,10 @@ fn count_consecutive_vs(s: &str) -> usize {
422418
if c == 'v' {
423419
current_count += 1;
424420
if current_count == 6 {
425-
return 6; // Stop early if we reach 6
421+
return 6; // Stop early if we reach 6
426422
}
427423
} else {
428-
current_count = 0; // Reset count if the character is not 'v'
424+
current_count = 0; // Reset count if the character is not 'v'
429425
}
430426
max_count = max_count.max(current_count);
431427
}

backend/src/main.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -364,8 +364,16 @@ async fn windmill_main() -> anyhow::Result<()> {
364364
let is_agent = mode == Mode::Agent;
365365

366366
if !is_agent {
367-
// migration code to avoid break
368-
windmill_api::migrate_db(&db).await?;
367+
let skip_migration = std::env::var("SKIP_MIGRATION")
368+
.map(|val| val == "true")
369+
.unwrap_or(false);
370+
371+
if !skip_migration {
372+
// migration code to avoid break
373+
windmill_api::migrate_db(&db).await?;
374+
} else {
375+
tracing::info!("SKIP_MIGRATION set, skipping db migration...")
376+
}
369377
}
370378

371379
let (killpill_tx, mut killpill_rx) = tokio::sync::broadcast::channel::<()>(2);

backend/windmill-api/src/jobs.rs

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@ use axum::http::HeaderValue;
1111
use quick_cache::sync::Cache;
1212
use serde_json::value::RawValue;
1313
use sqlx::Pool;
14-
use windmill_common::error::JsonResult;
1514
use std::collections::HashMap;
1615
#[cfg(feature = "prometheus")]
1716
use std::sync::atomic::Ordering;
1817
use tokio::io::AsyncReadExt;
1918
#[cfg(feature = "prometheus")]
2019
use tokio::time::Instant;
2120
use tower::ServiceBuilder;
21+
use windmill_common::error::JsonResult;
2222
use windmill_common::flow_status::{JobResult, RestartedFrom};
2323
use windmill_common::jobs::{
2424
format_completed_job_result, format_result, CompletedJobWithFormattedResult, FormattedResult,
@@ -293,11 +293,8 @@ pub fn workspace_unauthed_service() -> Router {
293293

294294
pub fn global_root_service() -> Router {
295295
Router::new()
296-
.route("/db_clock", get(get_db_clock))
297-
.route(
298-
"/completed/count_by_tag",
299-
get(count_by_tag),
300-
)
296+
.route("/db_clock", get(get_db_clock))
297+
.route("/completed/count_by_tag", get(count_by_tag))
301298
}
302299

303300
#[derive(Deserialize)]
@@ -4683,8 +4680,8 @@ async fn get_job_update(
46834680
.fetch_optional(&db)
46844681
.await?;
46854682

4686-
let progress: Option<i32> = if get_progress == Some(true){
4687-
sqlx::query_scalar!(
4683+
let progress: Option<i32> = if get_progress == Some(true) {
4684+
sqlx::query_scalar!(
46884685
"SELECT scalar_int FROM job_stats WHERE workspace_id = $1 AND job_id = $2 AND metric_id = $3",
46894686
&w_id,
46904687
job_id,
@@ -5115,8 +5112,6 @@ async fn get_completed_job_result(
51155112
Ok(Json(result).into_response())
51165113
}
51175114

5118-
5119-
51205115
#[derive(Deserialize)]
51215116
struct CountByTagQuery {
51225117
horizon_secs: Option<i64>,
@@ -5130,7 +5125,7 @@ struct TagCount {
51305125
}
51315126

51325127
async fn count_by_tag(
5133-
ApiAuthed { email, ..}: ApiAuthed,
5128+
ApiAuthed { email, .. }: ApiAuthed,
51345129
Extension(db): Extension<DB>,
51355130
Query(query): Query<CountByTagQuery>,
51365131
) -> JsonResult<Vec<TagCount>> {

backend/windmill-api/src/resources.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,10 @@ pub fn workspaced_service() -> Router {
5858
.route("/type/exists/:name", get(exists_resource_type))
5959
.route("/type/update/:name", post(update_resource_type))
6060
.route("/type/delete/:name", delete(delete_resource_type))
61-
.route("/file_resource_type_to_file_ext_map", get(file_resource_ext_to_resource_type))
61+
.route(
62+
"/file_resource_type_to_file_ext_map",
63+
get(file_resource_ext_to_resource_type),
64+
)
6265
.route("/type/create", post(create_resource_type))
6366
}
6467

backend/windmill-common/src/worker.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -449,10 +449,13 @@ pub async fn save_cache(
449449
fn write_binary_file(main_path: &str, byts: &mut bytes::Bytes) -> error::Result<()> {
450450
use std::fs::{File, Permissions};
451451
use std::io::Write;
452+
453+
#[cfg(unix)]
452454
use std::os::unix::fs::PermissionsExt;
453455

454456
let mut file = File::create(main_path)?;
455457
file.write_all(byts)?;
458+
#[cfg(unix)]
456459
file.set_permissions(Permissions::from_mode(0o755))?;
457460
file.flush()?;
458461
Ok(())

backend/windmill-indexer/src/indexer_ee.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1+
use anyhow::anyhow;
12
use sqlx::{Pool, Postgres};
23
use windmill_common::error::Error;
3-
use anyhow::anyhow;
44

55
#[derive(Clone)]
66
pub struct IndexReader;

backend/windmill-worker/src/ansible_executor.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,18 @@
1+
#[cfg(unix)]
12
use std::{
23
collections::HashMap,
34
os::unix::fs::PermissionsExt,
45
path::{Path, PathBuf},
56
process::Stdio,
67
};
78

9+
#[cfg(windows)]
10+
use std::{
11+
collections::HashMap,
12+
path::{Path, PathBuf},
13+
process::Stdio,
14+
};
15+
816
use anyhow::anyhow;
917
use itertools::Itertools;
1018
use serde_json::value::RawValue;
@@ -378,6 +386,7 @@ fi
378386

379387
let file = write_file(job_dir, "wrapper.sh", &wrapper)?;
380388

389+
#[cfg(unix)]
381390
file.metadata()?.permissions().set_mode(0o777);
382391
// let mut nsjail_cmd = Command::new(NSJAIL_PATH.as_str());
383392
let mut nsjail_cmd = Command::new(NSJAIL_PATH.as_str());

0 commit comments

Comments
 (0)