Skip to content

v3: fix digest extraction #1024

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/late-steaks-behave.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"trigger.dev": patch
---

v3: fix digest extraction
20 changes: 12 additions & 8 deletions packages/cli-v3/src/commands/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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);
});

Expand Down Expand Up @@ -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;
}
}
}
Expand Down
16 changes: 12 additions & 4 deletions packages/cli-v3/src/utilities/configFiles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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;
}