v3: fix digest extraction (#1024)

* fix image digest extraction

* fix project ref cli arg override

* Create late-steaks-behave.md

---------

Co-authored-by: Eric Allam <eric@trigger.dev>
This commit is contained in:
nicktrn
2024-04-12 11:10:52 +01:00
committed by GitHub
parent efd970a901
commit 63a643b7c9
3 changed files with 29 additions and 12 deletions
+5
View File
@@ -0,0 +1,5 @@
---
"trigger.dev": patch
---
v3: fix digest extraction
+12 -8
View File
@@ -94,7 +94,7 @@ export function configureDeployCommand(program: Command) {
.option("-c, --config <config file>", "The name of the config file, found at [path]")
.option(
"-p, --project-ref <project ref>",
"The project ref. Required if there is no config file."
"The project ref. Required if there is no config file. This will override the project specified in the config file."
)
)
.addOption(
@@ -688,7 +688,10 @@ async function buildAndPushImage(
childProcess.stderr?.on("data", (data: Buffer) => {
const text = data.toString();
errors.push(text);
// Emitted data chunks can contain multiple lines. Remove empty lines.
const lines = text.split("\n").filter(Boolean);
errors.push(...lines);
logger.debug(text);
});
@@ -896,14 +899,15 @@ async function buildAndPushSelfHostedImage(
}
function extractImageDigest(outputs: string[]) {
const imageDigestRegex = /sha256:[a-f0-9]{64}/;
const imageDigestRegex = /pushing manifest for .+(?<digest>sha256:[a-f0-9]{64})/;
for (const line of outputs) {
if (line.includes("pushing manifest")) {
const imageDigestMatch = line.match(imageDigestRegex);
if (imageDigestMatch) {
return imageDigestMatch[0];
}
const imageDigestMatch = line.match(imageDigestRegex);
const digest = imageDigestMatch?.groups?.digest;
if (digest) {
return digest;
}
}
}
+12 -4
View File
@@ -164,9 +164,13 @@ export async function readConfig(
// import the config file
const userConfigModule = await import(builtConfigFileHref);
// The --project-ref CLI arg will always override the project specified in the config file
const rawConfig = await normalizeConfig(
userConfigModule ? userConfigModule.config : { project: options?.projectRef }
userConfigModule?.config,
options?.projectRef ? { project: options?.projectRef } : undefined
);
const config = Config.parse(rawConfig);
return {
@@ -198,10 +202,14 @@ export async function resolveConfig(path: string, config: Config): Promise<Resol
return config as ResolvedConfig;
}
export async function normalizeConfig(config: any): Promise<any> {
export async function normalizeConfig(config: any, overrides?: Record<string, any>): Promise<any> {
let normalized = config;
if (typeof config === "function") {
config = config();
normalized = await config();
}
return await config;
normalized = { ...normalized, ...overrides };
return normalized;
}