Skip to content
Merged
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
41 changes: 37 additions & 4 deletions apps/webapp/app/v3/services/finalizeDeploymentV2.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,14 @@ export class FinalizeDeploymentV2Service extends BaseService {
friendlyId: id,
environmentId: authenticatedEnv.id,
},
include: {
select: {
status: true,
id: true,
version: true,
externalBuildData: true,
environment: true,
worker: {
include: {
tasks: true,
select: {
project: true,
},
},
Expand Down Expand Up @@ -84,6 +87,14 @@ export class FinalizeDeploymentV2Service extends BaseService {
throw new ServiceValidationError("Missing depot token");
}

const digest = extractImageDigest(body.imageReference);

logger.debug("Pushing image to registry", {
id,
deployment,
digest,
});

const pushResult = await executePushToRegistry(
{
depot: {
Expand All @@ -110,17 +121,39 @@ export class FinalizeDeploymentV2Service extends BaseService {
throw new ServiceValidationError(pushResult.error);
}

const fullImage = digest ? `${pushResult.image}@${digest}` : pushResult.image;

logger.debug("Image pushed to registry", {
id,
deployment,
body,
fullImage,
});

const finalizeService = new FinalizeDeploymentService();

const finalizedDeployment = await finalizeService.call(authenticatedEnv, id, {
imageReference: pushResult.image,
imageReference: fullImage,
skipRegistryProxy: true,
});

return finalizedDeployment;
}
}

// Extracts the sha256 digest from an image reference
// For example the image ref "registry.depot.dev/gn57tl6chn:8qfjm8w83w@sha256:aa6fd2bdcbbd611556747e72d0b57797f03aa9b39dc910befc83eea2b08a5b85"
// would return "sha256:aa6fd2bdcbbd611556747e72d0b57797f03aa9b39dc910befc83eea2b08a5b85"
function extractImageDigest(image: string) {
const digestIndex = image.lastIndexOf("@");

if (digestIndex === -1) {
return;
}

return image.substring(digestIndex + 1);
}

type ExecutePushToRegistryOptions = {
depot: {
buildId: string;
Expand Down