Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Handle pip install by uv #4517

Open
wants to merge 27 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
d6a654a
feat: Handle `pip install` by `uv`
pyranota Oct 10, 2024
e881ed5
Merge branch 'main' into python-uv
pyranota Oct 17, 2024
13896a5
Integrate with NSJAIL and prepare fallbacks
pyranota Oct 21, 2024
7985a7b
Refactor fallback
pyranota Oct 21, 2024
bd7607d
Remove `--disable-pip-version-check`
pyranota Oct 21, 2024
5805554
Fix backend compilation error
pyranota Oct 22, 2024
a0c86ef
Pip fallback overwrite UV's cache
pyranota Oct 22, 2024
60e7fa7
Initially refactor cache (No S3)
pyranota Oct 22, 2024
5390975
Support S3
pyranota Oct 22, 2024
414b9c3
Remove unused import
pyranota Oct 22, 2024
1271a65
Handle flags for NSJAIL
pyranota Oct 22, 2024
59e8004
Return deleted flag
pyranota Oct 22, 2024
54698b3
Merge branch 'main' into python-uv
pyranota Oct 23, 2024
c21182f
Update Dockerfile
rubenfiszel Oct 23, 2024
a446660
Update docker-image.yml
rubenfiszel Oct 23, 2024
1ad54e8
Update docker-image.yml
rubenfiszel Oct 23, 2024
b1a4f2a
Add --link-mode=copy and remove -v
pyranota Oct 23, 2024
b1bcdae
Merge branch 'python-uv' of github.com:windmill-labs/windmill into py…
pyranota Oct 23, 2024
a01c26f
Merge branch 'main' into python-uv
pyranota Oct 29, 2024
af70339
Fix NSJAIL INDEX_URL
pyranota Oct 29, 2024
2534520
Merge branch 'python-uv' of github.com:windmill-labs/windmill into py…
pyranota Oct 29, 2024
c839bae
Fix flock and windows
pyranota Oct 29, 2024
63340e6
Merge branch 'main' into python-uv
pyranota Oct 31, 2024
d0bad93
Merge branch 'main' into python-uv
pyranota Oct 31, 2024
e0040fe
Merge branch 'main' into python-uv
pyranota Oct 31, 2024
844acbf
Merge branch 'main' into python-uv
rubenfiszel Nov 2, 2024
eff3e1c
Update python_executor.rs
rubenfiszel Nov 3, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/docker-image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ env:
name: Build windmill:main
on:
push:
branches: [main]
branches: [main, python-uv]
tags: ["*"]
pull_request:
types: [opened, synchronize, reopened]
Expand Down Expand Up @@ -438,7 +438,7 @@ jobs:
build_ee_nsjail:
needs: [build_ee]
runs-on: ubicloud
if: (github.event_name != 'issue_comment') || (github.event_name != 'pull_request') || (contains(github.event.comment.body, '/buildimage_nsjail') || contains(github.event.comment.body, '/buildimage_all'))
if: (github.event_name != 'issue_comment') || (contains(github.event.comment.body, '/buildimage_nsjail') || contains(github.event.comment.body, '/buildimage_all'))
steps:
- uses: actions/checkout@v4
with:
Expand Down
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# trigger CI
ARG DEBIAN_IMAGE=debian:bookworm-slim
ARG RUST_IMAGE=rust:1.80-slim-bookworm
ARG PYTHON_IMAGE=python:3.11.10-slim-bookworm
Expand Down
5 changes: 2 additions & 3 deletions backend/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ use windmill_common::global_settings::OBJECT_STORE_CACHE_CONFIG_SETTING;
use windmill_worker::{
get_hub_script_content_and_requirements, BUN_BUNDLE_CACHE_DIR, BUN_CACHE_DIR,
BUN_DEPSTAR_CACHE_DIR, DENO_CACHE_DIR, DENO_CACHE_DIR_DEPS, DENO_CACHE_DIR_NPM,
GO_BIN_CACHE_DIR, GO_CACHE_DIR, LOCK_CACHE_DIR, PIP_CACHE_DIR, POWERSHELL_CACHE_DIR,
RUST_CACHE_DIR, TAR_PIP_CACHE_DIR, TMP_LOGS_DIR, UV_CACHE_DIR,
GO_BIN_CACHE_DIR, GO_CACHE_DIR, LOCK_CACHE_DIR, POWERSHELL_CACHE_DIR, RUST_CACHE_DIR,
TAR_PIP_CACHE_DIR, TMP_LOGS_DIR, UV_CACHE_DIR,
};

use crate::monitor::{
Expand Down Expand Up @@ -955,7 +955,6 @@ pub async fn run_workers<R: rsmq_async::RsmqConnection + Send + Sync + Clone + '
for x in [
LOCK_CACHE_DIR,
TMP_LOGS_DIR,
PIP_CACHE_DIR,
UV_CACHE_DIR,
TAR_PIP_CACHE_DIR,
DENO_CACHE_DIR,
Expand Down
2 changes: 2 additions & 0 deletions backend/windmill-common/src/worker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,8 @@ fn parse_file<T: FromStr>(path: &str) -> Option<T> {
pub struct PythonAnnotations {
pub no_cache: bool,
pub no_uv: bool,
pub no_uv_install: bool,
pub no_uv_compile: bool,
}

#[annotations("//")]
Expand Down
93 changes: 93 additions & 0 deletions backend/windmill-worker/nsjail/download.py.pip.config.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
name: "python download pip"

mode: ONCE
hostname: "python"
log_level: ERROR
time_limit: 900

rlimit_as: 2048
rlimit_cpu: 1000
rlimit_fsize: 1024
rlimit_nofile: 64

envar: "HOME=/user"
envar: "LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH"

cwd: "/tmp"

clone_newnet: false
clone_newuser: {CLONE_NEWUSER}

keep_caps: true
keep_env: true

mount {
src: "/bin"
dst: "/bin"
is_bind: true
}

mount {
src: "/lib"
dst: "/lib"
is_bind: true
}

mount {
src: "/lib64"
dst: "/lib64"
is_bind: true
mandatory: false
}

mount {
src: "/usr"
dst: "/usr"
is_bind: true
}

mount {
src: "/etc"
dst: "/etc"
is_bind: true
}

mount {
src: "/dev/null"
dst: "/dev/null"
is_bind: true
rw: true
}

mount {
dst: "/tmp"
fstype: "tmpfs"
rw: true
options: "size=500000000"
}


mount {
src: "{WORKER_DIR}/download_deps.py.pip.sh"
dst: "/download_deps.sh"
is_bind: true
}

mount {
src: "{CACHE_DIR}"
dst: "{CACHE_DIR}"
is_bind: true
rw: true
}

mount {
src: "/dev/urandom"
dst: "/dev/urandom"
is_bind: true
}

exec_bin {
path: "/bin/sh"
arg: "/download_deps.sh"
}

24 changes: 24 additions & 0 deletions backend/windmill-worker/nsjail/download_deps.py.pip.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#/bin/sh

INDEX_URL_ARG=$([ -z "$INDEX_URL" ] && echo ""|| echo "--index-url $INDEX_URL" )
EXTRA_INDEX_URL_ARG=$([ -z "$EXTRA_INDEX_URL" ] && echo ""|| echo "--extra-index-url $EXTRA_INDEX_URL" )
TRUSTED_HOST_ARG=$([ -z "$TRUSTED_HOST" ] && echo "" || echo "--trusted-host $TRUSTED_HOST")

if [ ! -z "$INDEX_URL" ]
then
echo "\$INDEX_URL is set to $INDEX_URL"
fi

if [ ! -z "$EXTRA_INDEX_URL" ]
then
echo "\$EXTRA_INDEX_URL is set to $EXTRA_INDEX_URL"
fi

if [ ! -z "$TRUSTED_HOST" ]
then
echo "\$TRUSTED_HOST is set to $TRUSTED_HOST"
fi

CMD="/usr/local/bin/python3 -m pip install -v \"$REQ\" -I -t \"$TARGET\" --no-cache --no-color --no-deps --isolated --no-warn-conflicts --disable-pip-version-check $INDEX_URL_ARG $EXTRA_INDEX_URL_ARG $TRUSTED_HOST_ARG"
echo $CMD
eval $CMD
15 changes: 14 additions & 1 deletion backend/windmill-worker/nsjail/download_deps.py.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,19 @@ then
echo "\$TRUSTED_HOST is set to $TRUSTED_HOST"
fi

CMD="/usr/local/bin/python3 -m pip install -v \"$REQ\" -I -t \"$TARGET\" --no-cache --no-color --no-deps --isolated --no-warn-conflicts --disable-pip-version-check $INDEX_URL_ARG $EXTRA_INDEX_URL_ARG $TRUSTED_HOST_ARG"
CMD="/usr/local/bin/uv pip install
\"$REQ\"
--target \"$TARGET\"
--no-cache
--no-config
--no-color
--no-deps
--link-mode=copy
-p 3.11
$INDEX_URL_ARG $EXTRA_INDEX_URL_ARG $TRUSTED_HOST_ARG
--index-strategy unsafe-best-match
--system
"

echo $CMD
eval $CMD
1 change: 1 addition & 0 deletions backend/windmill-worker/src/ansible_executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ async fn handle_ansible_python_deps(
job_dir,
worker_dir,
&mut Some(occupancy_metrics),
false,
)
.await?;
additional_python_paths.append(&mut venv_path);
Expand Down
26 changes: 22 additions & 4 deletions backend/windmill-worker/src/global_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,21 @@ use std::sync::Arc;
pub async fn build_tar_and_push(
s3_client: Arc<dyn ObjectStore>,
folder: String,
no_uv: bool,
) -> error::Result<()> {
use object_store::path::Path;

use crate::PY311_CACHE_DIR;

tracing::info!("Started building and pushing piptar {folder}");
let start = Instant::now();
let folder_name = folder.split("/").last().unwrap();
let tar_path = format!("{PIP_CACHE_DIR}/{folder_name}_tar.tar",);
let prefix = if no_uv {
PIP_CACHE_DIR
} else {
PY311_CACHE_DIR
};
let tar_path = format!("{prefix}/{folder_name}_tar.tar",);

let tar_file = std::fs::File::create(&tar_path)?;
let mut tar = tar::Builder::new(tar_file);
Expand All @@ -46,7 +54,10 @@ pub async fn build_tar_and_push(
// })?;
if let Err(e) = s3_client
.put(
&Path::from(format!("/tar/pip/{folder_name}.tar")),
&Path::from(format!(
"/tar/{}/{folder_name}.tar",
if no_uv { "pip" } else { "python_311" }
)),
std::fs::read(&tar_path)?.into(),
)
.await
Expand All @@ -71,15 +82,22 @@ pub async fn build_tar_and_push(
}

#[cfg(all(feature = "enterprise", feature = "parquet"))]
pub async fn pull_from_tar(client: Arc<dyn ObjectStore>, folder: String) -> error::Result<()> {
pub async fn pull_from_tar(
client: Arc<dyn ObjectStore>,
folder: String,
no_uv: bool,
) -> error::Result<()> {
use windmill_common::s3_helpers::attempt_fetch_bytes;

let folder_name = folder.split("/").last().unwrap();

tracing::info!("Attempting to pull piptar {folder_name} from bucket");

let start = Instant::now();
let tar_path = format!("tar/pip/{folder_name}.tar");
let tar_path = format!(
"tar/{}/{folder_name}.tar",
if no_uv { "pip" } else { "python_311" }
);
let bytes = attempt_fetch_bytes(client, &tar_path).await?;

// tracing::info!("B: {target} {folder}");
Expand Down
Loading
Loading