diff --git a/web/crux-ui/src/validations/container.ts b/web/crux-ui/src/validations/container.ts index ba08d42c1..5789693c1 100644 --- a/web/crux-ui/src/validations/container.ts +++ b/web/crux-ui/src/validations/container.ts @@ -14,15 +14,11 @@ import { ContainerNetworkMode, ContainerPort, ContainerRestartPolicyType, - EnvironmentRule, Metrics, - UniqueKeyValue, VolumeType, - UniqueSecretKeyValue, } from '@app/models' import * as yup from 'yup' import { matchNoLeadingOrTrailingWhitespaces, matchNoWhitespace } from './common' -import { parseDyrectorioEnvRules } from './labels' // Official regex from Docker daemon export const CONTAINER_NAME_REGEX = /^[a-zA-Z0-9][a-zA-Z0-9_.-]+$/g @@ -430,6 +426,8 @@ const expectedContainerStateRule = yup .optional() .label('container:dagent.expectedState') +// TODO(@robot9706): Fix labels & config bundles conflicting +/* type KeyValueLike = { key: string value: string @@ -544,20 +542,21 @@ const testSecretRules = return true } +*/ +// eslint-disable-next-line @typescript-eslint/no-unused-vars const createContainerConfigBaseSchema = (imageLabels: Record) => yup.object().shape({ name: matchContainerName(yup.string().nullable().optional().label('container:common.containerName')), - environment: uniqueKeyValuesSchema - .default(null) - .nullable() - .optional() - .label('container:common.environment') - .test( + environment: uniqueKeyValuesSchema.default(null).nullable().optional().label('container:common.environment'), + // TODO(@robot9706): Fix labels & config bundles conflicting + /* + .test( 'labelRules', 'Environment variables must match their image label rules.', testEnvironmentRules(imageLabels), ), + */ routing: routingRule, expose: exposeRule, user: yup.number().default(null).min(UID_MIN).max(UID_MAX).nullable().optional().label('container:common.user'), @@ -605,10 +604,7 @@ export const createContainerConfigSchema = (imageLabels: Record) export const createConcreteContainerConfigSchema = (imageLabels: Record) => createContainerConfigBaseSchema(imageLabels).shape({ - secrets: uniqueKeyValuesSchema - .default(null) - .nullable() - .optional() - .label('container:common.secrets') - .test('secretRules', 'Secrets must match their image label rules.', testSecretRules(imageLabels)), + secrets: uniqueKeyValuesSchema.default(null).nullable().optional().label('container:common.secrets'), + // TODO(@robot9706): Fix labels & config bundles conflicting + // .test('secretRules', 'Secrets must match their image label rules.', testSecretRules(imageLabels)), }) diff --git a/web/crux/src/app/image/image.service.ts b/web/crux/src/app/image/image.service.ts index d55206abc..54e5d91e7 100644 --- a/web/crux/src/app/image/image.service.ts +++ b/web/crux/src/app/image/image.service.ts @@ -1,21 +1,18 @@ import { Injectable } from '@nestjs/common' import { EventEmitter2 } from '@nestjs/event-emitter' import { Identity } from '@ory/kratos-client' -import { Prisma } from '@prisma/client' -import { UniqueKeyValue, UniqueSecretKey } from 'src/domain/container' import { IMAGE_EVENT_ADD, IMAGE_EVENT_DELETE, ImageDeletedEvent, ImagesAddedEvent } from 'src/domain/domain-events' -import { EnvironmentRule, parseDyrectorioEnvRules } from 'src/domain/image' import PrismaService from 'src/services/prisma.service' -import { v4 as uuid } from 'uuid' import ContainerConfigService from '../container/container-config.service' -import RegistryClientProvider from '../registry/registry-client.provider' -import TeamRepository from '../team/team.repository' import { AddImagesDto, ImageDetailsDto, PatchImageDto } from './image.dto' import ImageMapper from './image.mapper' +// TODO(@robot9706): Fix labels & config bundles conflicting +/* type LabelMap = Record type ImageLabelMap = Record type RegistryLabelMap = Record +*/ @Injectable() export default class ImageService { @@ -23,10 +20,10 @@ export default class ImageService { private readonly prisma: PrismaService, private readonly mapper: ImageMapper, private readonly containerConfigService: ContainerConfigService, - private readonly events: EventEmitter2, - private readonly teamRepository: TeamRepository, - private readonly registryClients: RegistryClientProvider, - ) {} + private readonly events: EventEmitter2, // TODO(@robot9706): Fix labels & config bundles conflicting + // private readonly registryClients: RegistryClientProvider, + ) // private readonly teamRepository: TeamRepository, + {} async getImagesByVersionId(versionId: string): Promise { const images = await this.prisma.image.findMany({ @@ -56,11 +53,14 @@ export default class ImageService { } async addImagesToVersion( + // eslint-disable-next-line @typescript-eslint/no-unused-vars teamSlug: string, versionId: string, request: AddImagesDto[], identity: Identity, ): Promise { + // TODO(@robot9706): Fix labels & config bundles conflicting + /* const teamId = await this.teamRepository.getTeamIdBySlug(teamSlug) const labelLookupPromises = request.map(async it => { @@ -93,6 +93,7 @@ export default class ImageService { }, {} as ImageLabelMap) return map }, {} as RegistryLabelMap) + */ const images = await this.prisma.$transaction(async prisma => { const lastImageOrder = await this.prisma.image.findFirst({ @@ -138,6 +139,8 @@ export default class ImageService { return await Promise.all(imgs) }) + // TODO(@robot9706): Fix labels & config bundles conflicting + /* await this.prisma.$transaction(prisma => Promise.all( images.map(it => { @@ -181,6 +184,7 @@ export default class ImageService { }), ), ) + */ const dtos = images.map(it => this.mapper.toDetailsDto(it)) @@ -212,6 +216,8 @@ export default class ImageService { ) } + // TODO(@robot9706): Fix labels & config bundles conflicting + /* let labels: Record let configUpdate: Prisma.ContainerConfigUpdateOneRequiredWithoutImageNestedInput = null if (request.tag) { @@ -243,6 +249,7 @@ export default class ImageService { }, } } + */ await this.prisma.image.update({ where: { @@ -253,10 +260,11 @@ export default class ImageService { registry: true, }, data: { - labels: labels ?? undefined, + // TODO(@robot9706): Fix labels & config bundles conflicting + // labels: labels ?? undefined, + // config: configUpdate ?? undefined, tag: request.tag ?? undefined, updatedBy: identity.id, - config: configUpdate ?? undefined, }, }) } @@ -307,6 +315,8 @@ export default class ImageService { return [imageName, imageTag] } + // TODO(@robot9706): Fix labels & config bundles conflicting + /* private static mergeEnvironmentsRules( environment: UniqueKeyValue[], rules: Record, @@ -361,4 +371,5 @@ export default class ImageService { return Object.values(mergedSecrets) } + */ } diff --git a/web/crux/src/domain/validation.ts b/web/crux/src/domain/validation.ts index d8177b3ab..a6aa4ade9 100644 --- a/web/crux/src/domain/validation.ts +++ b/web/crux/src/domain/validation.ts @@ -1,5 +1,5 @@ import { ContainerConfigPortRangeDto } from 'src/app/container/container.dto' -import { EnvironmentRule, ImageValidation } from 'src/app/image/image.dto' +import { ImageValidation } from 'src/app/image/image.dto' import { ContainerPort } from 'src/app/node/node.dto' import { CruxBadRequestException } from 'src/exception/crux-exception' import { UID_MAX, UID_MIN } from 'src/shared/const' @@ -20,7 +20,6 @@ import { ContainerVolumeType, Metrics, PORT_MAX, - UniqueKeyValue, } from './container' export const nameRuleOptional = yup.string().trim().min(3).max(70) @@ -363,6 +362,8 @@ export const concreteContainerConfigSchema = yup.object().shape({ metrics: metricsRule.optional().nullable(), }) +// TODO(@robot9706): Fix labels & config bundles conflicting +/* type KeyValueLike = { key: string value: string @@ -439,7 +440,9 @@ const testRules = (rules: [string, EnvironmentRule][], arr: UniqueKeyValue[], fi return null } +*/ +// eslint-disable-next-line @typescript-eslint/no-unused-vars export const createStartDeploymentSchema = (instanceValidation: Record) => yup.object({ config: containerConfigSchema, @@ -461,7 +464,9 @@ export const createStartDeploymentSchema = (instanceValidation: Record new Set(instances.map(it => it.config.name)).size === instances.length, - ) + ), + // TODO(@robot9706): Fix labels & config bundles conflicting + /* .test('instanceLabelRules', 'Instance must match their image label rules.', instances => { const errors = instances .map(it => { @@ -490,6 +495,7 @@ export const createStartDeploymentSchema = (instanceValidation: Record