Skip to content

Commit

Permalink
fix: respect spec.publishId for publishing image
Browse files Browse the repository at this point in the history
  • Loading branch information
shumailxyz committed Jul 12, 2023
1 parent da64efe commit 2408933
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 4 deletions.
19 changes: 17 additions & 2 deletions core/src/plugins/container/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { ContainerBuildAction, ContainerBuildOutputs, defaultDockerfileName } fr
import { joinWithPosix } from "../../util/fs"
import { Resolved } from "../../actions/types"
import dedent from "dedent"
import { splitFirst } from "../../util/string"

export const getContainerBuildStatus: BuildActionHandler<"getStatus", ContainerBuildAction> = async ({
ctx,
Expand Down Expand Up @@ -62,6 +63,11 @@ export const buildContainer: BuildActionHandler<"build", ContainerBuildAction> =

const cmdOpts = ["build", "-t", identifier, ...getDockerBuildFlags(action), "--file", dockerfilePath]

// if deploymentImageId is different from localImageId, tag the image with deploymentImageId as well.
if (outputs.deploymentImageId && identifier !== outputs.deploymentImageId) {
cmdOpts.push(...["-t", outputs.deploymentImageId])
}

const logEventContext = {
origin: "docker build",
level: "verbose" as const,
Expand Down Expand Up @@ -93,15 +99,24 @@ export const buildContainer: BuildActionHandler<"build", ContainerBuildAction> =
export function getContainerBuildActionOutputs(action: Resolved<ContainerBuildAction>): ContainerBuildOutputs {
const buildName = action.name
const localId = action.getSpec("localId")
const explicitImage = action.getSpec("publishId")
let imageId = localId
if (explicitImage) {
// override imageId if publishId is set
const imageTag = splitFirst(explicitImage, ":")[1]
const parsedImage = containerHelpers.parseImageId(explicitImage)
const tag = imageTag || action.versionString()
imageId = containerHelpers.unparseImageId({ ...parsedImage, tag })
}
const version = action.moduleVersion()

const localImageName = containerHelpers.getLocalImageName(buildName, localId)
const localImageId = containerHelpers.getLocalImageId(buildName, localId, version)

// Note: The deployment image name/ID outputs are overridden by the kubernetes provider, these defaults are
// generally not used.
const deploymentImageName = containerHelpers.getDeploymentImageName(buildName, localId, undefined)
const deploymentImageId = containerHelpers.getBuildDeploymentImageId(buildName, localId, version, undefined)
const deploymentImageName = containerHelpers.getDeploymentImageName(buildName, imageId, undefined)
const deploymentImageId = containerHelpers.getBuildDeploymentImageId(buildName, imageId, version, undefined)

return {
localImageName,
Expand Down
14 changes: 12 additions & 2 deletions core/src/plugins/kubernetes/container/handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import { containerHelpers } from "../../container/helpers"
import { getContainerModuleOutputs } from "../../container/container"
import { getContainerBuildActionOutputs } from "../../container/build"
import { Resolved } from "../../../actions/types"
import { splitFirst } from "../../../util/string"

async function configure(params: ConfigureModuleParams<ContainerModule>) {
let { moduleConfig } = await params.base!(params)
Expand Down Expand Up @@ -62,15 +63,24 @@ export function k8sGetContainerBuildActionOutputs({
}): ContainerBuildOutputs {
const localId = action.getSpec("localId")
const outputs = getContainerBuildActionOutputs(action)
const explicitImage = action.getSpec("publishId")
let imageId = localId
if (explicitImage) {
// override imageId if publishId is set
const imageTag = splitFirst(explicitImage, ":")[1]
const parsedImage = containerHelpers.parseImageId(explicitImage)
const tag = imageTag || action.versionString()
imageId = containerHelpers.unparseImageId({ ...parsedImage, tag })
}

outputs.deploymentImageName = outputs["deployment-image-name"] = containerHelpers.getDeploymentImageName(
action.name,
localId,
imageId,
provider.config.deploymentRegistry
)
outputs.deploymentImageId = outputs["deployment-image-id"] = containerHelpers.getBuildDeploymentImageId(
action.name,
localId,
imageId,
action.moduleVersion(),
provider.config.deploymentRegistry
)
Expand Down

0 comments on commit 2408933

Please sign in to comment.