Skip to content

Commit

Permalink
fix: container name defaults
Browse files Browse the repository at this point in the history
  • Loading branch information
m8vago committed Dec 3, 2024
1 parent 353b164 commit 038495d
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 5 deletions.
11 changes: 10 additions & 1 deletion web/crux-ui/src/models/image.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,13 @@ export type ImageMessage = VersionImage

export const imageNameOf = (image: VersionImage): string => imageName(image.name, image.tag)

export const containerNameOfImage = (image: VersionImage) => image.config.name ?? image.name
export const registryImageNameToContainerName = (name: string) => {
if (name.includes('/')) {
return name.split('/').pop()
}

return name
}

export const containerNameOfImage = (image: VersionImage) =>
image.config.name ?? registryImageNameToContainerName(image.name)
3 changes: 2 additions & 1 deletion web/crux/src/domain/container.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { NetworkMode } from '@prisma/client'
import { registryImageNameToContainerName } from './image'

export const PORT_MIN = 0
export const PORT_MAX = 65535
Expand Down Expand Up @@ -278,4 +279,4 @@ type InstanceWithConfigAndImageConfig = {
}

export const nameOfInstance = (instance: InstanceWithConfigAndImageConfig) =>
instance.config.name ?? instance.image.config.name ?? instance.image.name
instance.config.name ?? instance.image.config.name ?? registryImageNameToContainerName(instance.image.name)
8 changes: 8 additions & 0 deletions web/crux/src/domain/image.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,11 @@ export const parseDyrectorioEnvRules = (labels: Record<string, string>): Record<
}
}, {})
}

export const registryImageNameToContainerName = (name: string) => {
if (name.includes('/')) {
return name.split('/').pop()
}

return name
}
6 changes: 3 additions & 3 deletions web/crux/src/domain/start-deployment.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ContainerConfig, DeploymentStatusEnum, VersionTypeEnum } from '@prisma/client'
import { ConcreteContainerConfigData, ContainerConfigData, UniqueSecretKeyValue } from './container'
import { ConcreteContainerConfigData, ContainerConfigData, UniqueSecretKeyValue, nameOfInstance } from './container'
import { mergeConfigsWithConcreteConfig, mergeInstanceConfigWithDeploymentConfig } from './container-merge'
import { DeploymentWithConfig } from './deployment'

Expand Down Expand Up @@ -122,11 +122,11 @@ export const instanceConfigOf = (

// then we merge and override the rest with the instance config
const instanceConfig = instance.config as any as ConcreteContainerConfigData
const result = mergeInstanceConfigWithDeploymentConfig(mergedDeploymentConfig, instanceConfig)
const result = mergeInstanceConfigWithDeploymentConfig(mergedDeploymentConfig, instanceConfig)

// set defaults
if (!result.name) {
result.name = instance.image.name
result.name = nameOfInstance(instance)
}

return result
Expand Down

0 comments on commit 038495d

Please sign in to comment.