From afac8a73f0a76850ff9eca0e368db0e3ec793328 Mon Sep 17 00:00:00 2001 From: wendrul <53628737+wendrul@users.noreply.github.com> Date: Fri, 13 Dec 2024 09:36:17 +0100 Subject: [PATCH] fix: c#: nsjail image, default langs and feature cage imports (#4917) * fix: nsjail image, default langs and feature cage csharp imports * Fix unused imports with csharp flag --- .../windmill-worker/src/csharp_executor.rs | 33 ++++++++++++++----- docker/DockerfileNsjail | 3 ++ .../common/languageIcons/LanguageIcon.svelte | 2 +- frontend/src/lib/scripts.ts | 2 +- 4 files changed, 30 insertions(+), 10 deletions(-) diff --git a/backend/windmill-worker/src/csharp_executor.rs b/backend/windmill-worker/src/csharp_executor.rs index e880a0fa81..b265f7cc3b 100644 --- a/backend/windmill-worker/src/csharp_executor.rs +++ b/backend/windmill-worker/src/csharp_executor.rs @@ -1,39 +1,56 @@ use anyhow::anyhow; use serde_json::value::RawValue; -use std::{collections::HashMap, io, path::Path, process::Stdio}; +#[cfg(feature = "csharp")] +use std::{io, path::Path, process::Stdio}; + +use std::collections::HashMap; use uuid::Uuid; #[cfg(feature = "csharp")] use windmill_parser_csharp::parse_csharp_reqs; +#[cfg(feature = "csharp")] use itertools::Itertools; +#[cfg(feature = "csharp")] use tokio::{fs::File, io::AsyncReadExt, process::Command}; +#[cfg(feature = "csharp")] use windmill_common::{ - error::{self, Error}, - jobs::QueuedJob, utils::calculate_hash, worker::{save_cache, write_file}, }; -use windmill_queue::{append_logs, CanceledBy}; +use windmill_common::error::{self, Error}; +use windmill_common::jobs::QueuedJob; +#[cfg(feature = "csharp")] +use windmill_queue::append_logs; + +use windmill_queue::CanceledBy; + +#[cfg(feature = "csharp")] use crate::{ common::{ check_executor_binary_exists, create_args_and_out_file, get_reserved_variables, - read_result, start_child_process, OccupancyMetrics, + read_result, start_child_process, }, handle_child::handle_child, - AuthedClientBackgroundTask, CSHARP_CACHE_DIR, DISABLE_NSJAIL, DISABLE_NUSER, DOTNET_PATH, - HOME_ENV, NSJAIL_PATH, NUGET_CONFIG, PATH_ENV, TZ_ENV, + CSHARP_CACHE_DIR, DISABLE_NSJAIL, DISABLE_NUSER, DOTNET_PATH, HOME_ENV, NSJAIL_PATH, + NUGET_CONFIG, PATH_ENV, TZ_ENV, }; +use crate::common::OccupancyMetrics; +use crate::AuthedClientBackgroundTask; + #[cfg(windows)] use crate::SYSTEM_ROOT; +#[cfg(feature = "csharp")] const NSJAIL_CONFIG_RUN_CSHARP_CONTENT: &str = include_str!("../nsjail/run.csharp.config.proto"); +#[cfg(feature = "csharp")] lazy_static::lazy_static! { static ref HOME_DIR: String = std::env::var("HOME").expect("Could not find the HOME environment variable"); } +#[cfg(feature = "csharp")] const CSHARP_OBJECT_STORE_PREFIX: &str = "csharpbin/"; #[cfg(feature = "csharp")] @@ -109,7 +126,6 @@ pub async fn generate_nuget_lockfile( Err(anyhow!("C# is not available because the feature is not enabled").into()) } - #[cfg(feature = "csharp")] fn gen_cs_proj( code: &str, @@ -327,6 +343,7 @@ async fn build_cs_proj( } } +#[cfg(feature = "csharp")] fn remove_lines_from_text(contents: &str, indices_to_remove: Vec) -> String { let mut result = Vec::new(); diff --git a/docker/DockerfileNsjail b/docker/DockerfileNsjail index f0a26279c7..9032b5b4ea 100644 --- a/docker/DockerfileNsjail +++ b/docker/DockerfileNsjail @@ -30,4 +30,7 @@ COPY --from=rust:1.80.1 /usr/local/rustup /usr/local/rustup RUN pip3 install ansible +COPY --from=bitnami/dotnet-sdk:9.0.101-debian-12-r0 /opt/bitnami/dotnet-sdk /opt/dotnet-sdk +RUN ln -s /opt/dotnet-sdk/bin/dotnet /usr/bin/dotnet + COPY --from=nsjail /nsjail/nsjail /bin/nsjail diff --git a/frontend/src/lib/components/common/languageIcons/LanguageIcon.svelte b/frontend/src/lib/components/common/languageIcons/LanguageIcon.svelte index 9bf4241891..565865d821 100644 --- a/frontend/src/lib/components/common/languageIcons/LanguageIcon.svelte +++ b/frontend/src/lib/components/common/languageIcons/LanguageIcon.svelte @@ -52,7 +52,7 @@ php: 'PHP', rust: 'Rust', ansible: 'Ansible Playbook', - csharp: 'C sharpo' + csharp: 'C#' } const langToComponent: Record< diff --git a/frontend/src/lib/scripts.ts b/frontend/src/lib/scripts.ts index f741b71775..dcbb1dfc1c 100644 --- a/frontend/src/lib/scripts.ts +++ b/frontend/src/lib/scripts.ts @@ -128,7 +128,7 @@ export function processLangs(selected: string | undefined, langs: string[]): str let ls = langs.filter((lang) => lang !== 'nativets') //those languages are newer and may not be in the saved list - let nl = ['bunnative', 'rust', 'ansible'] + let nl = ['bunnative', 'rust', 'ansible', 'csharp'] nl.forEach((lang) => { if (!ls.includes(lang)) { ls.push(lang)