Skip to content

Commit c49ff00

Browse files
committed
feat(new tool): Docker Compose Validator
New tool to validate docker-compose.yml files against Docker Compose Specification Fix part of CorentinTh#540
1 parent d3b32cc commit c49ff00

File tree

6 files changed

+141
-11
lines changed

6 files changed

+141
-11
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
"change-case": "^4.1.2",
5252
"colord": "^2.9.3",
5353
"composerize-ts": "^0.6.2",
54+
"composeverter": "^1.7.2",
5455
"country-code-lookup": "^0.1.0",
5556
"cron-validator": "^1.3.1",
5657
"cronstrue": "^2.26.0",

pnpm-lock.yaml

Lines changed: 37 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
declare module 'composeverter' {
2+
interface Configuration {
3+
expandVolumes?: boolean;
4+
expandPorts?: boolean;
5+
indent?: number;
6+
}
7+
interface DockerComposeValidatioError {
8+
line?: number;
9+
message: string;
10+
helpLink?: string;
11+
}
12+
export function validateDockerComposeToCommonSpec(content: string): DockerComposeValidatioError[];
13+
export function migrateFromV2xToV3x(content: string, configuration?: Configuration = null): string;
14+
export function migrateFromV3xToV2x(content: string, configuration?: Configuration = null): string;
15+
export function migrateFromV1ToV2x(content: string, configuration?: Configuration = null): string;
16+
export function migrateToCommonSpec(content: string, configuration?: Configuration = null): string;
17+
export function migrateFromV2xToV3x(content: string, configuration?: Configuration = null): string;
18+
export function getDockerComposeSchemaWithoutFormats(): object;
19+
}
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
<script setup lang="ts">
2+
import {
3+
validateDockerComposeToCommonSpec,
4+
} from 'composeverter';
5+
6+
const dockerCompose = ref(
7+
`version: '3.3'
8+
services:
9+
nginx:
10+
ports:
11+
- '80:80'
12+
volumes:
13+
- '/var/run/docker.sock:/tmp/docker.sock:ro'
14+
restart: always
15+
logging:
16+
options:
17+
max-size: 1g
18+
image: nginx`,
19+
);
20+
21+
const conversionResult = computed(() => {
22+
try {
23+
return validateDockerComposeToCommonSpec(dockerCompose.value);
24+
}
25+
catch (e: any) {
26+
return e.toString().split('\n').map((err: string) => ({ line: -1, message: err, helpLink: '' }));
27+
}
28+
});
29+
30+
const errors = computed(() => conversionResult.value);
31+
32+
const MONACO_EDITOR_OPTIONS = {
33+
automaticLayout: true,
34+
formatOnType: true,
35+
formatOnPaste: true,
36+
};
37+
</script>
38+
39+
<template>
40+
<div>
41+
<c-label label="Paste your Docker Compose file content:">
42+
<div relative w-full>
43+
<c-monaco-editor
44+
v-model:value="dockerCompose"
45+
theme="vs-dark"
46+
language="yaml"
47+
height="250px"
48+
:options="MONACO_EDITOR_OPTIONS"
49+
/>
50+
</div>
51+
</c-label>
52+
53+
<div v-if="errors.length > 0">
54+
<n-alert title="The following errors occured" type="error" mt-5>
55+
<ul>
56+
<li v-for="(message, index) of errors" :key="index">
57+
{{ message.message }} (<n-a v-if="message.helpLink" target="_blank" rel="noreferer noopener">
58+
See Docker Compose help
59+
</n-a>)
60+
</li>
61+
</ul>
62+
</n-alert>
63+
</div>
64+
<div v-else>
65+
<n-alert type="success" mt-5>
66+
Validation successful!
67+
</n-alert>
68+
</div>
69+
</div>
70+
</template>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { BrandDocker } from '@vicons/tabler';
2+
import { defineTool } from '../tool';
3+
4+
export const tool = defineTool({
5+
name: 'Docker Compose Validator',
6+
path: '/docker-compose-validator',
7+
description: 'Validate Docker Compose files against CommonSpec schema',
8+
keywords: ['docker', 'compose', 'validator', 'commonspec'],
9+
component: () => import('./docker-compose-validator.vue'),
10+
icon: BrandDocker,
11+
createdAt: new Date('2024-01-25'),
12+
});

src/tools/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { tool as asciiTextDrawer } from './ascii-text-drawer';
66

77
import { tool as textToUnicode } from './text-to-unicode';
88
import { tool as safelinkDecoder } from './safelink-decoder';
9+
import { tool as dockerComposeValidator } from './docker-compose-validator';
910
import { tool as pdfSignatureChecker } from './pdf-signature-checker';
1011
import { tool as numeronymGenerator } from './numeronym-generator';
1112
import { tool as macAddressGenerator } from './mac-address-generator';
@@ -146,6 +147,7 @@ export const toolsByCategory: ToolCategory[] = [
146147
sqlPrettify,
147148
chmodCalculator,
148149
dockerRunToDockerComposeConverter,
150+
dockerComposeValidator,
149151
xmlFormatter,
150152
yamlViewer,
151153
],

0 commit comments

Comments
 (0)