Files
big-brother/api/app/controllers/compose_controller.ts
T
RutraandClaude Opus 5.5 c106fcfc62 Édition du docker-compose.yml depuis la page d'un conteneur
Vérification par docker compose config avant écriture, application avec
docker compose up -d et retour à la version précédente en cas d'échec.
Historique des versions par fichier. Le Caddyfile et le compose gardent
un retour à la ligne final.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-12 18:31:33 +02:00

56 lines
1.6 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import type { HttpContext } from '@adonisjs/core/http'
import composeService from '#services/compose_service'
import { actor, audit } from '#services/audit'
import { updateComposeValidator } from '#validators/compose'
const SAVE_ACTION = 'Modification du docker-compose.yml'
/**
* The docker-compose.yml of a container, from the container page.
*/
export default class ComposeController {
async show({ params }: HttpContext) {
return composeService.show(params.id)
}
async version({ params }: HttpContext) {
return composeService.version(params.id, Number(params.versionId))
}
async update(ctx: HttpContext) {
const { content, reason, apply } = await ctx.request.validateUsing(updateComposeValidator)
const target = await composeService.locate(ctx.params.id)
const result = await composeService.save(target, content, {
...actor(ctx),
reason: reason || 'Modification manuelle',
apply,
})
if (!result.ok) {
await audit(ctx, {
action: SAVE_ACTION,
target: target.file,
status: 'error',
output: result.output,
})
return ctx.response.unprocessableEntity({
message: 'docker compose a refusé le fichier : rien n’a été modifié.',
output: result.output,
})
}
/**
* When applied, the job records the action itself.
*/
if (result.changed && result.jobId === null) {
await audit(ctx, {
action: SAVE_ACTION,
target: target.file,
status: 'success',
output: result.output || null,
})
}
return result
}
}