fix: resolve repository hosts outside AgentOS
This commit is contained in:
@@ -1,3 +1,5 @@
|
|||||||
|
import { Resolver } from "node:dns/promises";
|
||||||
|
|
||||||
import { parseAgentEnv } from "@code/env/agent";
|
import { parseAgentEnv } from "@code/env/agent";
|
||||||
import { agentOS, setup } from "@rivet-dev/agentos";
|
import { agentOS, setup } from "@rivet-dev/agentos";
|
||||||
import { createClient } from "@rivet-dev/agentos/client";
|
import { createClient } from "@rivet-dev/agentos/client";
|
||||||
@@ -84,11 +86,32 @@ const classifyRuntimeFailure = (cause: unknown): WorkAttemptExecutionError => {
|
|||||||
return executionError(message, "HarnessFailed", false);
|
return executionError(message, "HarnessFailed", false);
|
||||||
};
|
};
|
||||||
|
|
||||||
const gitAuthEnv = (username: string, credential: string) => ({
|
const gitAuthEnv = (
|
||||||
GIT_CONFIG_COUNT: "1",
|
username: string,
|
||||||
|
credential: string,
|
||||||
|
repositoryUrl: string,
|
||||||
|
repositoryAddress: string
|
||||||
|
) => {
|
||||||
|
const { hostname } = new URL(repositoryUrl);
|
||||||
|
return {
|
||||||
|
GIT_CONFIG_COUNT: "2",
|
||||||
GIT_CONFIG_KEY_0: "http.extraHeader",
|
GIT_CONFIG_KEY_0: "http.extraHeader",
|
||||||
|
GIT_CONFIG_KEY_1: "http.curloptResolve",
|
||||||
GIT_CONFIG_VALUE_0: `Authorization: Basic ${Buffer.from(`${username}:${credential}`).toString("base64")}`,
|
GIT_CONFIG_VALUE_0: `Authorization: Basic ${Buffer.from(`${username}:${credential}`).toString("base64")}`,
|
||||||
});
|
GIT_CONFIG_VALUE_1: `${hostname}:443:${repositoryAddress}`,
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
const resolveRepositoryAddress = async (repositoryUrl: string) => {
|
||||||
|
const { hostname } = new URL(repositoryUrl);
|
||||||
|
const resolver = new Resolver();
|
||||||
|
resolver.setServers(["1.1.1.1", "8.8.8.8"]);
|
||||||
|
const [address] = await resolver.resolve4(hostname);
|
||||||
|
if (!address) {
|
||||||
|
throw new Error(`Repository host ${hostname} did not resolve`);
|
||||||
|
}
|
||||||
|
return address;
|
||||||
|
};
|
||||||
|
|
||||||
export const executeAgentOsAttempt = async (
|
export const executeAgentOsAttempt = async (
|
||||||
rawInput: unknown
|
rawInput: unknown
|
||||||
@@ -113,7 +136,9 @@ export const executeAgentOsAttempt = async (
|
|||||||
const authEnv = gitAuthEnv(
|
const authEnv = gitAuthEnv(
|
||||||
input.auth.username ??
|
input.auth.username ??
|
||||||
(input.auth.provider === "github" ? "x-access-token" : "git"),
|
(input.auth.provider === "github" ? "x-access-token" : "git"),
|
||||||
input.auth.credential
|
input.auth.credential,
|
||||||
|
input.repositoryUrl,
|
||||||
|
await resolveRepositoryAddress(input.repositoryUrl)
|
||||||
);
|
);
|
||||||
|
|
||||||
await vm.mkdir("/workspace", { recursive: true });
|
await vm.mkdir("/workspace", { recursive: true });
|
||||||
|
|||||||
Reference in New Issue
Block a user