Skip to content
Merged
Show file tree
Hide file tree
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
22 changes: 19 additions & 3 deletions apps/client/src/components/EnvironmentForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ const props = withDefaults(defineProps<{
cpu: undefined,
gpu: undefined,
memory: undefined,
autosync: true,
stageId: undefined,
clusterId: undefined,
}),
Expand All @@ -46,7 +47,7 @@ const props = withDefaults(defineProps<{

const emit = defineEmits<{
addEnvironment: [environment: Omit<CreateEnvironmentBody, 'projectId'>]
putEnvironment: [environment: Pick<Environment, 'cpu' | 'gpu' | 'memory'>]
putEnvironment: [environment: Pick<Environment, 'cpu' | 'gpu' | 'memory' | 'autosync'>]
deleteEnvironment: [environmentId: Environment['id']]
cancel: []
}>()
Expand All @@ -67,10 +68,10 @@ const chosenZoneDescription = computed(() => zoneStore.zonesById[zoneId.value ??

const schema = computed(() => {
if (localEnvironment.value?.id) {
const schemaValidation = EnvironmentSchema.pick({ id: true, cpu: true, gpu: true, memory: true }).safeParse(localEnvironment.value)
const schemaValidation = EnvironmentSchema.pick({ id: true, cpu: true, gpu: true, memory: true, autosync: true }).safeParse(localEnvironment.value)
return schemaValidation
} else {
const schemaValidation = EnvironmentSchema.pick({ clusterId: true, name: true, cpu: true, gpu: true, memory: true, stageId: true }).safeParse(localEnvironment.value)
const schemaValidation = EnvironmentSchema.pick({ clusterId: true, name: true, cpu: true, gpu: true, memory: true, autosync: true, stageId: true }).safeParse(localEnvironment.value)
return schemaValidation
}
})
Expand Down Expand Up @@ -277,6 +278,21 @@ watch(localEnvironment.value, () => {
:placeholder="ONE_TENTH_STR"
@update:model-value="(value: string) => localEnvironment.gpu = localeParseFloat(value)"
/>
<DsfrCheckbox
id="autosyncCbx"
v-model="localEnvironment.autosync"
value="localEnvironment.autosync"
label="Synchronisation automatique"
hint="Activation ou désactivation de la synchronisation automatique des déploiements."
name="isAutosync"
/>
<DsfrAlert
v-if="!localEnvironment.autosync"
data-testid="noAutosyncAlert"
description="La synchronisation automatique est désactivée. Les déploiements devront être synchronisés manuellement."
type="warning"
small
/>
<div
v-if="localEnvironment.id && canManage"
class="flex space-x-10 mt-5"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-- AlterTable
ALTER TABLE "Environment" ADD COLUMN "autosync" BOOLEAN NOT NULL DEFAULT true;
1 change: 1 addition & 0 deletions apps/server/src/prisma/schema/project.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ model Environment {
memory Float @db.Real
cpu Float @db.Real
gpu Float @db.Real
autosync Boolean @default(true)
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
clusterId String @db.Uuid
Expand Down
8 changes: 7 additions & 1 deletion apps/server/src/resources/environment/business.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ interface CreateEnvironmentParam {
cpu: Environment['cpu']
gpu: Environment['gpu']
memory: Environment['memory']
autosync: Environment['autosync']
clusterId: Environment['clusterId']
stageId: Stage['id']
requestId: string
Expand All @@ -37,6 +38,7 @@ interface CreateEnvironmentResult {
cpu: Environment['cpu']
gpu: Environment['gpu']
memory: Environment['memory']
autosync: Environment['autosync']
clusterId: Environment['clusterId']
stageId: Stage['id']
}
Expand All @@ -48,11 +50,12 @@ export async function createEnvironment({
cpu,
gpu,
memory,
autosync,
clusterId,
stageId,
requestId,
}: CreateEnvironmentParam): Promise<Result<CreateEnvironmentResult>> {
const environment = await initializeEnvironment({ projectId, name, cpu, gpu, memory, clusterId, stageId })
const environment = await initializeEnvironment({ projectId, name, cpu, gpu, memory, autosync, clusterId, stageId })

const { results } = await hook.project.upsert(projectId)
await addLogs({ action: 'Create Environment', data: results, userId, requestId, projectId })
Expand All @@ -72,6 +75,7 @@ interface UpdateEnvironmentParam {
cpu: Environment['cpu']
gpu: Environment['gpu']
memory: Environment['memory']
autosync: Environment['autosync']
requestId: string
}

Expand All @@ -82,12 +86,14 @@ export async function updateEnvironment({
cpu,
gpu,
memory,
autosync,
}: UpdateEnvironmentParam) {
const env = await updateEnvironmentQuery({
id: environmentId,
cpu,
gpu,
memory,
autosync,
})
const { results } = await hook.project.upsert(env.projectId)
await addLogs({ action: 'Update Environment', data: results, userId: user.id, requestId, projectId: env.projectId })
Expand Down
3 changes: 2 additions & 1 deletion apps/server/src/resources/environment/queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export function initializeEnvironment(data: Prisma.EnvironmentUncheckedCreateInp
})
}

export function updateEnvironment({ id, cpu, gpu, memory }: { id: Environment['id'], cpu: Environment['cpu'], gpu: Environment['gpu'], memory: Environment['memory'] }) {
export function updateEnvironment({ id, cpu, gpu, memory, autosync }: { id: Environment['id'], cpu: Environment['cpu'], gpu: Environment['gpu'], memory: Environment['memory'], autosync: Environment['autosync'] }) {
return prisma.environment.update({
where: {
id,
Expand All @@ -80,6 +80,7 @@ export function updateEnvironment({ id, cpu, gpu, memory }: { id: Environment['i
cpu,
gpu,
memory,
autosync,
},
})
}
Expand Down
2 changes: 2 additions & 0 deletions apps/server/src/resources/environment/router.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ describe('environmentRouter tests', () => {
cpu: faker.number.float({ min: 0, max: 10, fractionDigits: 1 }),
gpu: faker.number.float({ min: 0, max: 10, fractionDigits: 1 }),
memory: faker.number.float({ min: 0, max: 10, fractionDigits: 1 }),
autosync: faker.datatype.boolean(),
clusterId: faker.string.uuid(),
stageId: faker.string.uuid(),
}
Expand Down Expand Up @@ -178,6 +179,7 @@ describe('environmentRouter tests', () => {
cpu: faker.number.float({ min: 0, max: 10, fractionDigits: 1 }),
gpu: faker.number.float({ min: 0, max: 10, fractionDigits: 1 }),
memory: faker.number.float({ min: 0, max: 10, fractionDigits: 1 }),
autosync: faker.datatype.boolean(),
}
})
it('should update environment for authorized user', async () => {
Expand Down
2 changes: 2 additions & 0 deletions apps/server/src/resources/environment/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export function environmentRouter() {
cpu: requestBody.cpu,
gpu: requestBody.gpu,
memory: requestBody.memory,
autosync: requestBody.autosync,
stageId: requestBody.stageId,
requestId: req.id,
})
Expand Down Expand Up @@ -71,6 +72,7 @@ export function environmentRouter() {
cpu: requestBody.cpu,
gpu: requestBody.gpu,
memory: requestBody.memory,
autosync: requestBody.autosync,
requestId: req.id,
})
if (result.isError) {
Expand Down
1 change: 1 addition & 0 deletions packages/hooks/src/hooks/hook-project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export interface Environment {
gpu: number
memory: number
stage: string
autosync: boolean
permissions: {
userId: UserObject['id']
permissions: {
Expand Down
2 changes: 1 addition & 1 deletion packages/shared/src/contracts/environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export const environmentContract = contractInstance.router({
environmentId: z.string()
.uuid(),
}),
body: EnvironmentSchema.pick({ cpu: true, gpu: true, memory: true }),
body: EnvironmentSchema.pick({ cpu: true, gpu: true, memory: true, autosync: true }),
responses: {
200: EnvironmentSchema,
400: ErrorSchema,
Expand Down
1 change: 1 addition & 0 deletions packages/shared/src/schemas/environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export const EnvironmentSchema = z.object({
cpu: z.coerce.number().gte(0),
gpu: z.coerce.number().gte(0),
memory: z.coerce.number().gte(0),
autosync: z.boolean(),
}).extend(AtDatesToStringExtend)

export type Environment = Zod.infer<typeof EnvironmentSchema>
1 change: 1 addition & 0 deletions packages/shared/src/utils/schemas.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ describe('schemas utils', () => {
cpu: faker.number.float({ min: 0, max: 10, fractionDigits: 1 }),
gpu: faker.number.float({ min: 0, max: 10, fractionDigits: 1 }),
memory: faker.number.float({ min: 0, max: 10, fractionDigits: 1 }),
autosync: faker.datatype.boolean(),
projectId: faker.string.uuid(),
clusterId: faker.string.uuid(),
stageId: faker.string.uuid(),
Expand Down
29 changes: 29 additions & 0 deletions playwright/e2e-tests/environments.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -302,4 +302,33 @@ test.describe('Environments page', { tag: '@e2e' }, () => {
page.getByTestId('showDeleteEnvironmentBtn'),
).not.toBeVisible()
})

test('should show a warning if autosync is deactivated', async ({
page,
}) => {
await page.goto(clientURL)
await signInCloudPiNative({ page, credentials: testUser })
await addProject({ page })
const envName = await addEnvToProject({
page,
zone: 'publique',
customStageName: 'dev',
customClusterName: 'public1',
})
await expect(page.getByRole('cell', { name: envName })).toBeVisible()

// Verify warning message
await page.getByTestId(`environmentTr-${envName}`).click()
await expect(page.getByTestId('input-checkbox-autosyncCbx')).toBeVisible()
await expect(page.getByTestId('input-checkbox-autosyncCbx')).toBeChecked()
await expect(page.getByTestId('noAutosyncAlert')).not.toBeVisible()

// Act - Uncheck auto-sync to trigger warning message
await page.getByTestId('input-checkbox-autosyncCbx').uncheck({
force: true,
})
await expect(page.getByTestId('noAutosyncAlert')).toBeVisible()
await expect(page.getByTestId('noAutosyncAlert'))
.toHaveText('La synchronisation automatique est désactivée. Les déploiements devront être synchronisés manuellement.')
})
})
3 changes: 2 additions & 1 deletion plugins/argocd/src/functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ async function ensureInfraEnvValues(project: Project, environment: Environment,
cluster: inClusterLabel,
namespace: getConfig().namespace,
project: appProjectName,
envChartVersion: process.env.DSO_ENV_CHART_VERSION ?? 'dso-env-1.5.2',
envChartVersion: process.env.DSO_ENV_CHART_VERSION ?? 'dso-env-1.6.0',
nsChartVersion: process.env.DSO_NS_CHART_VERSION ?? 'dso-ns-1.1.4',
},
environment: {
Expand All @@ -257,6 +257,7 @@ async function ensureInfraEnvValues(project: Project, environment: Environment,
namespace: appNamespace,
name: cluster.label,
},
autosync: environment.autosync,
vault: vaultCredentials,
repositories,
},
Expand Down
Loading