Skip to content

Commit

Permalink
fix: remove label processing
Browse files Browse the repository at this point in the history
  • Loading branch information
robot9706 committed Dec 16, 2024
1 parent f59f9a6 commit e0857c0
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 31 deletions.
28 changes: 12 additions & 16 deletions web/crux-ui/src/validations/container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -544,20 +542,21 @@ const testSecretRules =
return true
}
*/

// eslint-disable-next-line @typescript-eslint/no-unused-vars
const createContainerConfigBaseSchema = (imageLabels: Record<string, string>) =>
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'),
Expand Down Expand Up @@ -605,10 +604,7 @@ export const createContainerConfigSchema = (imageLabels: Record<string, string>)

export const createConcreteContainerConfigSchema = (imageLabels: Record<string, string>) =>
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)),
})
35 changes: 23 additions & 12 deletions web/crux/src/app/image/image.service.ts
Original file line number Diff line number Diff line change
@@ -1,32 +1,29 @@
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<string, string>
type ImageLabelMap = Record<string, LabelMap>
type RegistryLabelMap = Record<string, ImageLabelMap>
*/

@Injectable()
export default class ImageService {
constructor(
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<ImageDetailsDto[]> {
const images = await this.prisma.image.findMany({
Expand Down Expand Up @@ -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<ImageDetailsDto[]> {
// TODO(@robot9706): Fix labels & config bundles conflicting
/*
const teamId = await this.teamRepository.getTeamIdBySlug(teamSlug)
const labelLookupPromises = request.map(async it => {
Expand Down Expand Up @@ -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({
Expand Down Expand Up @@ -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 => {
Expand Down Expand Up @@ -181,6 +184,7 @@ export default class ImageService {
}),
),
)
*/

const dtos = images.map(it => this.mapper.toDetailsDto(it))

Expand Down Expand Up @@ -212,6 +216,8 @@ export default class ImageService {
)
}

// TODO(@robot9706): Fix labels & config bundles conflicting
/*
let labels: Record<string, string>
let configUpdate: Prisma.ContainerConfigUpdateOneRequiredWithoutImageNestedInput = null
if (request.tag) {
Expand Down Expand Up @@ -243,6 +249,7 @@ export default class ImageService {
},
}
}
*/

await this.prisma.image.update({
where: {
Expand All @@ -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,
},
})
}
Expand Down Expand Up @@ -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<string, EnvironmentRule>,
Expand Down Expand Up @@ -361,4 +371,5 @@ export default class ImageService {
return Object.values(mergedSecrets)
}
*/
}
12 changes: 9 additions & 3 deletions web/crux/src/domain/validation.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -20,7 +20,6 @@ import {
ContainerVolumeType,
Metrics,
PORT_MAX,
UniqueKeyValue,
} from './container'

export const nameRuleOptional = yup.string().trim().min(3).max(70)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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<string, ImageValidation>) =>
yup.object({
config: containerConfigSchema,
Expand All @@ -461,7 +464,9 @@ export const createStartDeploymentSchema = (instanceValidation: Record<string, I
'containerNameAreUnique',
'Container names must be unique',
instances => 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 => {
Expand Down Expand Up @@ -490,6 +495,7 @@ export const createStartDeploymentSchema = (instanceValidation: Record<string, I
return true
}),
*/
})

const templateRegistrySchema = yup.object().shape({
Expand Down

0 comments on commit e0857c0

Please sign in to comment.