Skip to content

Commit dd49e2f

Browse files
committed
Merge branch 'feat/docker-validator' into chore/all-my-stuffs
# Conflicts: # package.json # pnpm-lock.yaml # src/tools/index.ts
2 parents 8d5fc99 + 729a10c commit dd49e2f

File tree

6 files changed

+107
-0
lines changed

6 files changed

+107
-0
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@
122122
"countries-and-timezones": "^3.7.2",
123123
"countries-and-timezones": "^3.6.0",
124124
"convert": "^5.4.1",
125+
"composeverter": "^1.7.2",
125126
"country-code-lookup": "^0.1.0",
126127
"crc": "^4.3.2",
127128
"countries-and-timezones": "^3.6.0",

pnpm-lock.yaml

Lines changed: 3 additions & 0 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
@@ -108,6 +108,7 @@ import { tool as asciiTextDrawer } from './ascii-text-drawer';
108108
import { tool as textToUnicode } from './text-to-unicode';
109109
import { tool as csrGenerator } from './csr-generator';
110110
import { tool as dockerRunToKubernetesConverter } from './docker-run-to-kubernetes';
111+
import { tool as dockerComposeValidator } from './docker-compose-validator';
111112
import { tool as pdfSignatureChecker } from './pdf-signature-checker';
112113
import { tool as numeronymGenerator } from './numeronym-generator';
113114
import { tool as macAddressGenerator } from './mac-address-generator';
@@ -347,6 +348,7 @@ export const toolsByCategory: ToolCategory[] = [
347348
dockerComposeToDockerRunConverter,
348349
dockerComposeToKubernetesConverter,
349350
dockerRunToKubernetesConverter,
351+
dockerComposeValidator,
350352
xmlFormatter,
351353
xsltTester,
352354
yamlViewer,

0 commit comments

Comments
 (0)