fix(backend): capture up all lockfile issues

This commit is contained in:
Ruben Fiszel
2022-11-02 14:04:44 +01:00
parent 14c296dbb8
commit 35868ef9bf
6 changed files with 70 additions and 60 deletions
@@ -176,7 +176,8 @@ fn constant_to_value(c: &Constant) -> serde_json::Value {
}
static PYTHON_IMPORTS_REPLACEMENT: phf::Map<&'static str, &'static str> = phf_map! {
"psycopg2" => "psycopg2-binary"
"psycopg2" => "psycopg2-binary",
"git" => "GitPython"
};
fn replace_import(x: String) -> String {
+46 -35
View File
@@ -1268,7 +1268,7 @@ async fn handle_python_job(
"".to_string()
} else {
pip_compile(job, &requirements, logs, job_dir, envs, db, timeout)
.await?
.await
.map_err(|e| {
Error::ExecutionErr(format!("pip compile failed: {}", e.to_string()))
})?
@@ -1551,37 +1551,7 @@ async fn handle_dependency_job(
timeout: i32,
envs: &Envs,
) -> error::Result<serde_json::Value> {
let content: Result<String, String> = match job.language {
Some(ScriptLang::Python3) => {
create_dependencies_dir(job_dir).await;
let requirements = &job
.raw_code
.as_ref()
.ok_or_else(|| Error::ExecutionErr("missing requirements".to_string()))?
.clone();
pip_compile(job, requirements, logs, job_dir, envs, db, timeout).await?
}
Some(ScriptLang::Go) => {
let requirements = job
.raw_code
.as_ref()
.ok_or_else(|| Error::ExecutionErr("missing requirements".to_string()))?;
install_go_dependencies(
&job.id,
&requirements,
logs,
job_dir,
db,
timeout,
&envs.go_path,
false,
)
.await
.map_err(|e| e.to_string())
}
_ => Err("Language incompatible with dep job".to_string()),
};
let content = capture_dependency_job(job, logs, job_dir, db, timeout, envs).await;
match content {
Ok(content) => {
sqlx::query!(
@@ -1608,6 +1578,47 @@ async fn handle_dependency_job(
}
}
async fn capture_dependency_job(
job: &QueuedJob,
logs: &mut String,
job_dir: &str,
db: &sqlx::Pool<sqlx::Postgres>,
timeout: i32,
envs: &Envs,
) -> error::Result<String> {
match job.language {
Some(ScriptLang::Python3) => {
create_dependencies_dir(job_dir).await;
let requirements = &job
.raw_code
.as_ref()
.ok_or_else(|| Error::ExecutionErr("missing requirements".to_string()))?
.clone();
pip_compile(job, requirements, logs, job_dir, envs, db, timeout).await
}
Some(ScriptLang::Go) => {
let requirements = job
.raw_code
.as_ref()
.ok_or_else(|| Error::ExecutionErr("missing requirements".to_string()))?;
install_go_dependencies(
&job.id,
&requirements,
logs,
job_dir,
db,
timeout,
&envs.go_path,
false,
)
.await
}
_ => Err(error::Error::ExecutionErr(
"Language incompatible with dep job".to_string(),
)),
}
}
async fn pip_compile(
job: &QueuedJob,
requirements: &str,
@@ -1616,7 +1627,7 @@ async fn pip_compile(
Envs { pip_extra_index_url, pip_index_url, pip_trusted_host, .. }: &Envs,
db: &Pool<Postgres>,
timeout: i32,
) -> Result<Result<String, String>, Error> {
) -> error::Result<String> {
logs.push_str(&format!("content of requirements:\n{}\n", requirements));
let file = "requirements.in";
write_file(job_dir, file, &requirements).await?;
@@ -1643,12 +1654,12 @@ async fn pip_compile(
let mut file = File::open(path_lock).await?;
let mut req_content = "".to_string();
file.read_to_string(&mut req_content).await?;
Ok(Ok(req_content
Ok(req_content
.lines()
.filter(|x| !x.trim_start().starts_with('#'))
.map(|x| x.to_string())
.collect::<Vec<String>>()
.join("\n")))
.join("\n"))
}
async fn install_go_dependencies(
@@ -162,7 +162,7 @@
</div>
</Pane>
<Pane size={67}>
<div class="px-2 py-1">
<div class="px-2 py-1 w-full">
{#if testIsLoading}
<Button
on:click={testJobLoader?.cancelJob}
@@ -60,7 +60,7 @@
ButtonType.SpacingClasses[spacingSize],
'focus:ring-4 font-semibold',
'rounded-md',
'flex justify-center items-center text-center whitespace-nowrap',
'justify-center items-center text-center whitespace-nowrap inline-flex',
btnClasses
),
disabled,
@@ -91,23 +91,21 @@
$: endIconClass = classNames(iconOnly ? undefined : isSmall ? 'ml-1' : 'ml-2', endIcon?.classes)
</script>
<div class="inline-flex">
<svelte:element
this={href ? 'a' : 'button'}
bind:this={element}
on:click={onClick}
on:focus
on:blur
{...buttonProps}
>
{#if startIcon}
<Icon data={startIcon.icon} class={startIconClass} scale={ButtonType.IconScale[size]} />
{/if}
{#if !iconOnly}
<slot />
{/if}
{#if endIcon}
<Icon data={endIcon.icon} class={endIconClass} scale={ButtonType.IconScale[size]} />
{/if}
</svelte:element>
</div>
<svelte:element
this={href ? 'a' : 'button'}
bind:this={element}
on:click={onClick}
on:focus
on:blur
{...buttonProps}
>
{#if startIcon}
<Icon data={startIcon.icon} class={startIconClass} scale={ButtonType.IconScale[size]} />
{/if}
{#if !iconOnly}
<slot />
{/if}
{#if endIcon}
<Icon data={endIcon.icon} class={endIconClass} scale={ButtonType.IconScale[size]} />
{/if}
</svelte:element>
@@ -75,8 +75,7 @@
if (pathName != '/user/login') {
logoutWithRedirect(pathName + $page.url.search)
}
}
if (status == '403') {
} else if (status == '403') {
sendUserToast('An endpoint required a privilege which you do not have', true)
} else {
if (body) {
@@ -101,6 +101,7 @@
{/each}
<div class="flex flex-row-reverse pt-4">
<Button
size="sm"
href="/user/create_workspace{rd ? `?rd=${encodeURIComponent(rd)}` : ''}"
variant="border"
>+&nbsp;Create a new workspace