mirror of
https://github.com/CorentinTh/it-tools.git
synced 2025-05-05 13:57:10 -04:00
feat(new tool): Docker Compose Validator
New tool to validate docker-compose.yml files against Docker Compose Specification Fix part of #540
This commit is contained in:
parent
d3b32cc14e
commit
c49ff00c31
6 changed files with 141 additions and 11 deletions
19
src/tools/docker-compose-validator/composeverter.d.ts
vendored
Normal file
19
src/tools/docker-compose-validator/composeverter.d.ts
vendored
Normal file
|
@ -0,0 +1,19 @@
|
|||
declare module 'composeverter' {
|
||||
interface Configuration {
|
||||
expandVolumes?: boolean;
|
||||
expandPorts?: boolean;
|
||||
indent?: number;
|
||||
}
|
||||
interface DockerComposeValidatioError {
|
||||
line?: number;
|
||||
message: string;
|
||||
helpLink?: string;
|
||||
}
|
||||
export function validateDockerComposeToCommonSpec(content: string): DockerComposeValidatioError[];
|
||||
export function migrateFromV2xToV3x(content: string, configuration?: Configuration = null): string;
|
||||
export function migrateFromV3xToV2x(content: string, configuration?: Configuration = null): string;
|
||||
export function migrateFromV1ToV2x(content: string, configuration?: Configuration = null): string;
|
||||
export function migrateToCommonSpec(content: string, configuration?: Configuration = null): string;
|
||||
export function migrateFromV2xToV3x(content: string, configuration?: Configuration = null): string;
|
||||
export function getDockerComposeSchemaWithoutFormats(): object;
|
||||
}
|
|
@ -0,0 +1,70 @@
|
|||
<script setup lang="ts">
|
||||
import {
|
||||
validateDockerComposeToCommonSpec,
|
||||
} from 'composeverter';
|
||||
|
||||
const dockerCompose = ref(
|
||||
`version: '3.3'
|
||||
services:
|
||||
nginx:
|
||||
ports:
|
||||
- '80:80'
|
||||
volumes:
|
||||
- '/var/run/docker.sock:/tmp/docker.sock:ro'
|
||||
restart: always
|
||||
logging:
|
||||
options:
|
||||
max-size: 1g
|
||||
image: nginx`,
|
||||
);
|
||||
|
||||
const conversionResult = computed(() => {
|
||||
try {
|
||||
return validateDockerComposeToCommonSpec(dockerCompose.value);
|
||||
}
|
||||
catch (e: any) {
|
||||
return e.toString().split('\n').map((err: string) => ({ line: -1, message: err, helpLink: '' }));
|
||||
}
|
||||
});
|
||||
|
||||
const errors = computed(() => conversionResult.value);
|
||||
|
||||
const MONACO_EDITOR_OPTIONS = {
|
||||
automaticLayout: true,
|
||||
formatOnType: true,
|
||||
formatOnPaste: true,
|
||||
};
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div>
|
||||
<c-label label="Paste your Docker Compose file content:">
|
||||
<div relative w-full>
|
||||
<c-monaco-editor
|
||||
v-model:value="dockerCompose"
|
||||
theme="vs-dark"
|
||||
language="yaml"
|
||||
height="250px"
|
||||
:options="MONACO_EDITOR_OPTIONS"
|
||||
/>
|
||||
</div>
|
||||
</c-label>
|
||||
|
||||
<div v-if="errors.length > 0">
|
||||
<n-alert title="The following errors occured" type="error" mt-5>
|
||||
<ul>
|
||||
<li v-for="(message, index) of errors" :key="index">
|
||||
{{ message.message }} (<n-a v-if="message.helpLink" target="_blank" rel="noreferer noopener">
|
||||
See Docker Compose help
|
||||
</n-a>)
|
||||
</li>
|
||||
</ul>
|
||||
</n-alert>
|
||||
</div>
|
||||
<div v-else>
|
||||
<n-alert type="success" mt-5>
|
||||
Validation successful!
|
||||
</n-alert>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
12
src/tools/docker-compose-validator/index.ts
Normal file
12
src/tools/docker-compose-validator/index.ts
Normal file
|
@ -0,0 +1,12 @@
|
|||
import { BrandDocker } from '@vicons/tabler';
|
||||
import { defineTool } from '../tool';
|
||||
|
||||
export const tool = defineTool({
|
||||
name: 'Docker Compose Validator',
|
||||
path: '/docker-compose-validator',
|
||||
description: 'Validate Docker Compose files against CommonSpec schema',
|
||||
keywords: ['docker', 'compose', 'validator', 'commonspec'],
|
||||
component: () => import('./docker-compose-validator.vue'),
|
||||
icon: BrandDocker,
|
||||
createdAt: new Date('2024-01-25'),
|
||||
});
|
|
@ -6,6 +6,7 @@ import { tool as asciiTextDrawer } from './ascii-text-drawer';
|
|||
|
||||
import { tool as textToUnicode } from './text-to-unicode';
|
||||
import { tool as safelinkDecoder } from './safelink-decoder';
|
||||
import { tool as dockerComposeValidator } from './docker-compose-validator';
|
||||
import { tool as pdfSignatureChecker } from './pdf-signature-checker';
|
||||
import { tool as numeronymGenerator } from './numeronym-generator';
|
||||
import { tool as macAddressGenerator } from './mac-address-generator';
|
||||
|
@ -146,6 +147,7 @@ export const toolsByCategory: ToolCategory[] = [
|
|||
sqlPrettify,
|
||||
chmodCalculator,
|
||||
dockerRunToDockerComposeConverter,
|
||||
dockerComposeValidator,
|
||||
xmlFormatter,
|
||||
yamlViewer,
|
||||
],
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue