fix: migrate legacy runtime image configuration
This commit is contained in:
+26
-7
@@ -2800,6 +2800,21 @@ function hasLegacyImageProfileConfig(env) {
|
||||
return Boolean(`${env?.CODEX_RETRY_GATEWAY_IMAGE_BASE_URL || ""}`.trim());
|
||||
}
|
||||
|
||||
function legacyImageProfileEnvFromConfig(config) {
|
||||
const baseUrl = `${config?.image_base_url || ""}`.trim();
|
||||
if (!baseUrl) {
|
||||
return {};
|
||||
}
|
||||
return {
|
||||
CODEX_RETRY_GATEWAY_IMAGE_BASE_URL: baseUrl,
|
||||
CODEX_RETRY_GATEWAY_IMAGE_AUTH_MODE: config?.image_auth_mode || DEFAULT_CONFIG.image_auth_mode,
|
||||
CODEX_RETRY_GATEWAY_IMAGE_AUTH_ENV: config?.image_auth_env || "",
|
||||
CODEX_RETRY_GATEWAY_IMAGE_AUTH_FILE: config?.image_auth_file || "",
|
||||
CODEX_RETRY_GATEWAY_IMAGE_AUTH_JSON_PATH: config?.image_auth_json_path || "",
|
||||
CODEX_RETRY_GATEWAY_IMAGE_AUTH_JSON_KEY: config?.image_auth_json_key || "",
|
||||
};
|
||||
}
|
||||
|
||||
function buildLegacyImageProfileEnvText(env) {
|
||||
const pairs = IMAGE_PROFILE_ENV_KEYS
|
||||
.filter((key) => env?.[key] !== undefined)
|
||||
@@ -2812,7 +2827,7 @@ function buildLegacyImageProfileEnvText(env) {
|
||||
].join("\n");
|
||||
}
|
||||
|
||||
async function migrateLegacyImageProfile(runtime, textProfileName, textEnv = null) {
|
||||
async function migrateLegacyImageProfile(runtime, textProfileName, textEnv = null, legacyConfig = null) {
|
||||
validateProfileName(textProfileName);
|
||||
const imageProfilePath = path.join(runtime.paths.imageProfilesDir, `${textProfileName}.env`);
|
||||
if (fs.existsSync(imageProfilePath)) {
|
||||
@@ -2822,17 +2837,21 @@ async function migrateLegacyImageProfile(runtime, textProfileName, textEnv = nul
|
||||
let env = textEnv;
|
||||
if (!env) {
|
||||
const textProfilePath = path.join(runtime.paths.profilesDir, `${textProfileName}.env`);
|
||||
if (!fs.existsSync(textProfilePath)) {
|
||||
return null;
|
||||
if (fs.existsSync(textProfilePath)) {
|
||||
env = parseEnvText((await readOptionalText(textProfilePath)) || "");
|
||||
} else {
|
||||
env = {};
|
||||
}
|
||||
env = parseEnvText((await readOptionalText(textProfilePath)) || "");
|
||||
}
|
||||
if (!hasLegacyImageProfileConfig(env)) {
|
||||
const sourceEnv = hasLegacyImageProfileConfig(env)
|
||||
? env
|
||||
: legacyImageProfileEnvFromConfig(legacyConfig);
|
||||
if (!hasLegacyImageProfileConfig(sourceEnv)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
await mkdir(runtime.paths.imageProfilesDir, { recursive: true });
|
||||
await writeFile(imageProfilePath, buildLegacyImageProfileEnvText(env), {
|
||||
await writeFile(imageProfilePath, buildLegacyImageProfileEnvText(sourceEnv), {
|
||||
encoding: "utf8",
|
||||
mode: 0o600,
|
||||
});
|
||||
@@ -3025,7 +3044,7 @@ async function ensureActiveImageProfile(runtime) {
|
||||
let selectedName = candidates.find((name) => fs.existsSync(path.join(runtime.paths.imageProfilesDir, `${name}.env`))) || "";
|
||||
let migration = null;
|
||||
if (!selectedName && /^[A-Za-z0-9_.-]+$/.test(textProfileName)) {
|
||||
migration = await migrateLegacyImageProfile(runtime, textProfileName);
|
||||
migration = await migrateLegacyImageProfile(runtime, textProfileName, null, runtime.config);
|
||||
selectedName = migration?.name || "";
|
||||
}
|
||||
if (!selectedName) {
|
||||
|
||||
Reference in New Issue
Block a user