Merge branch 'feat/dockver-compose-converter' into chore/all-my-stuffs

# Conflicts:
#	package.json
#	pnpm-lock.yaml
#	src/tools/index.ts
This commit is contained in:
ShareVB committed 2024-11-03 22:45:03 +01:00
commit 8e373d232e
6 files changed
+179 -1

No files matched your search

+1
View File
@@ -126,6 +126,7 @@
"country-code-lookup": "^0.1.0",
"crc": "^4.3.2",
"countries-and-timezones": "^3.6.0",
"composeverter": "^1.6.2",
"country-code-lookup": "^0.1.0",
"cron-parser": "^4.9.0",
"cron-validator": "^1.3.1",
+1 -1
View File
@@ -192,7 +192,7 @@ dependencies:
specifier: ^0.6.2
version: 0.6.2
composeverter:
specifier: ^1.7.2
specifier: ^1.6.2
version: 1.7.2
convert:
specifier: ^5.4.1
+19
View 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,144 @@
<script setup lang="ts">
import Composeverter from 'composeverter';
import { useDownloadFileFromBase64 } from '@/composable/downloadBase64';
import { textToBase64 } from '@/utils/base64';
import TextareaCopyable from '@/components/TextareaCopyable.vue';
const dockerCompose = ref(
`nginx:
ports:
- '80:80'
volumes:
- '/var/run/docker.sock:/tmp/docker.sock:ro'
image: nginx`,
);
const indentSize = useStorage('docker-compose-converter:indent-size', 4);
const expandVolumes = ref(
false,
);
const expandPorts = ref(
false,
);
const conversion = useStorage('docker-compose-converter:conversion', 'latest');
const conversionOptions = [
{ value: 'v1ToV2x', label: 'V1 to V2 2.x' },
{ value: 'v1ToV3x', label: 'V1 to V2 3.x' },
{ value: 'v2xToV3x', label: 'V2 - 2.x to 3.x' },
{ value: 'v3xToV2x', label: 'V2 - 3.x to 2.x' },
{ value: 'latest', label: 'To CommonSpec' },
];
const conversionResult = computed(() => {
try {
let convertedDockerCompose = '';
const config = {
expandPorts: expandPorts.value,
expandVolumes: expandVolumes.value,
indent: indentSize.value,
};
switch (conversion.value) {
case 'latest':
convertedDockerCompose = Composeverter.migrateToCommonSpec(dockerCompose.value, config);
break;
case 'v1ToV2x':
convertedDockerCompose = Composeverter.migrateFromV1ToV2x(dockerCompose.value, config);
break;
case 'v1ToV3x':
convertedDockerCompose = Composeverter.migrateFromV2xToV3x(Composeverter.migrateFromV1ToV2x(dockerCompose.value), config);
break;
case 'v2xToV3x':
convertedDockerCompose = Composeverter.migrateFromV2xToV3x(dockerCompose.value, config);
break;
case 'v3xToV2x':
convertedDockerCompose = Composeverter.migrateFromV3xToV2x(dockerCompose.value, config);
break;
default:
throw new Error(`Unknown conversion '${conversion}'`);
}
return { yaml: convertedDockerCompose, errors: [] };
}
catch (e: any) {
return { yaml: '#see error messages', errors: e.toString().split('\n') };
}
});
const convertedDockerCompose = computed(() => conversionResult.value.yaml);
const errors = computed(() => conversionResult.value.errors);
const convertedDockerComposeBase64 = computed(() => `data:application/yaml;base64,${textToBase64(convertedDockerCompose.value)}`);
const { download } = useDownloadFileFromBase64({ source: convertedDockerComposeBase64, filename: 'docker-compose.yml' });
const MONACO_EDITOR_OPTIONS = {
automaticLayout: true,
formatOnType: true,
formatOnPaste: true,
};
</script>
<template>
<div>
<c-label label="Paste your existing Docker Compose:">
<div relative w-full>
<c-monaco-editor
v-model:value="dockerCompose"
theme="vs-dark"
language="yaml"
height="200px"
: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 }}
</li>
</ul>
</n-alert>
</div>
<n-divider />
<n-grid cols="4" x-gap="12" w-full>
<n-gi span="2">
<c-select
v-model:value="conversion"
label-position="top"
label="Docker Compose conversion:"
:options="conversionOptions"
placeholder="Select Docker Compose conversion"
/>
</n-gi>
<n-gi span="2">
<n-form-item label="Indent size:" label-placement="top" label-width="100" :show-feedback="false">
<n-input-number v-model:value="indentSize" min="0" max="10" w-100px />
</n-form-item>
</n-gi>
</n-grid>
<n-divider />
<div class="mb-6 flex flex-row items-center gap-2">
<n-checkbox v-model:checked="expandPorts">
Expand Ports
</n-checkbox>
<n-checkbox v-model:checked="expandVolumes">
Expand Volumes
</n-checkbox>
</div>
<n-divider />
<TextareaCopyable :value="convertedDockerCompose" language="yaml" />
<div mt-5 flex justify-center>
<c-button :disabled="dockerCompose === ''" secondary @click="download">
Download converted docker-compose.yml
</c-button>
</div>
</div>
</template>
@@ -0,0 +1,12 @@
import { BrandDocker } from '@vicons/tabler';
import { defineTool } from '../tool';
export const tool = defineTool({
name: 'Docker Compose Format Converter',
path: '/docker-compose-converter',
description: 'Convert Docker Compose file between V1, 2.x, 3.x or CommonSpec and may expand ports/volumes syntaxes',
keywords: ['docker', 'compose', 'converter'],
component: () => import('./docker-compose-converter.vue'),
icon: BrandDocker,
createdAt: new Date('2024-01-04'),
});
+2
View File
@@ -190,6 +190,7 @@ import { tool as pdfEncrypt } from './pdf-encrypt';
import { tool as pdfLinearize } from './pdf-linearize';
import { tool as manyUnitsConverter } from './many-units-converter';
import { tool as powerConverter } from './power-converter';
import { tool as dockerComposeConverter } from './docker-compose-converter';
import { tool as yamlViewer } from './yaml-viewer';
import { tool as barcodeReader } from './barcode-reader';
import { tool as barcodeGenerator } from './barcode-generator';
@@ -349,6 +350,7 @@ export const toolsByCategory: ToolCategory[] = [
dockerComposeToKubernetesConverter,
dockerRunToKubernetesConverter,
dockerComposeValidator,
dockerComposeConverter,
xmlFormatter,
xsltTester,
yamlViewer,