2023-05-28 23:13:24 +02:00
|
|
|
<script setup lang="ts">
|
2024-01-21 23:11:30 +01:00
|
|
|
import composerize from 'composerize';
|
2023-05-28 23:13:24 +02:00
|
|
|
import { useDownloadFileFromBase64 } from '@/composable/downloadBase64';
|
|
|
|
import { textToBase64 } from '@/utils/base64';
|
|
|
|
import TextareaCopyable from '@/components/TextareaCopyable.vue';
|
|
|
|
|
2024-01-21 23:11:30 +01:00
|
|
|
const dockerRuns = ref(
|
2023-05-28 23:13:24 +02:00
|
|
|
'docker run -p 80:80 -v /var/run/docker.sock:/tmp/docker.sock:ro --restart always --log-opt max-size=1g nginx',
|
|
|
|
);
|
2024-01-21 23:11:30 +01:00
|
|
|
const indentSize = useStorage('docker-run-to-compose:indent-size', 4);
|
2023-05-28 23:13:24 +02:00
|
|
|
|
2024-01-21 23:11:30 +01:00
|
|
|
const existingDockerComposeFile = ref(
|
|
|
|
'',
|
2023-05-28 23:13:24 +02:00
|
|
|
);
|
2024-01-21 23:11:30 +01:00
|
|
|
const format = useStorage('docker-run-to-compose:format', 'latest');
|
|
|
|
const formatOptions = [
|
|
|
|
{ value: 'v2x', label: 'V2 - 2.x' },
|
|
|
|
{ value: 'v3x', label: 'V2 - 3.x' },
|
|
|
|
{ value: 'latest', label: 'CommonSpec' },
|
|
|
|
];
|
|
|
|
|
|
|
|
const conversionResult = computed(() => {
|
|
|
|
try {
|
|
|
|
return { yaml: composerize(dockerRuns.value.trim(), existingDockerComposeFile.value, format.value, indentSize.value), errors: [] };
|
|
|
|
}
|
|
|
|
catch (e: any) {
|
|
|
|
return { yaml: '#see error messages', errors: e.toString().split('\n') };
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2023-05-28 23:13:24 +02:00
|
|
|
const dockerCompose = computed(() => conversionResult.value.yaml);
|
2024-01-21 23:11:30 +01:00
|
|
|
const errors = computed(() => conversionResult.value.errors);
|
|
|
|
|
2023-05-28 23:13:24 +02:00
|
|
|
const dockerComposeBase64 = computed(() => `data:application/yaml;base64,${textToBase64(dockerCompose.value)}`);
|
|
|
|
const { download } = useDownloadFileFromBase64({ source: dockerComposeBase64, filename: 'docker-compose.yml' });
|
2024-01-21 23:11:30 +01:00
|
|
|
|
|
|
|
const MONACO_EDITOR_OPTIONS = {
|
|
|
|
automaticLayout: true,
|
|
|
|
formatOnType: true,
|
|
|
|
formatOnPaste: true,
|
|
|
|
};
|
2023-05-28 23:13:24 +02:00
|
|
|
</script>
|
|
|
|
|
2023-03-27 17:31:13 +02:00
|
|
|
<template>
|
|
|
|
<div>
|
2023-06-25 15:00:50 +02:00
|
|
|
<c-input-text
|
2024-01-21 23:11:30 +01:00
|
|
|
v-model:value="dockerRuns"
|
|
|
|
label="Your docker run command(s):"
|
2023-06-25 15:00:50 +02:00
|
|
|
style="font-family: monospace"
|
|
|
|
multiline
|
|
|
|
raw-text
|
|
|
|
monospace
|
2024-01-21 23:11:30 +01:00
|
|
|
placeholder="Your docker run command(s) to convert..."
|
|
|
|
rows="4"
|
2023-06-25 15:00:50 +02:00
|
|
|
/>
|
2023-03-27 17:31:13 +02:00
|
|
|
|
|
|
|
<n-divider />
|
|
|
|
|
2024-01-21 23:11:30 +01:00
|
|
|
<c-label label="Eventually, paste your existing Docker Compose:">
|
|
|
|
<div relative w-full>
|
|
|
|
<c-monaco-editor
|
|
|
|
v-model:value="existingDockerComposeFile"
|
|
|
|
theme="vs-dark"
|
|
|
|
language="yaml"
|
|
|
|
height="100px"
|
|
|
|
:options="MONACO_EDITOR_OPTIONS"
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</c-label>
|
|
|
|
|
|
|
|
<n-divider />
|
|
|
|
|
|
|
|
<n-grid cols="4" x-gap="12" w-full>
|
|
|
|
<n-gi span="2">
|
|
|
|
<c-select
|
|
|
|
v-model:value="format"
|
|
|
|
label-position="top"
|
|
|
|
label="Docker Compose format:"
|
|
|
|
:options="formatOptions"
|
|
|
|
placeholder="Select Docker Compose format"
|
|
|
|
/>
|
|
|
|
</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 />
|
|
|
|
|
2023-05-28 23:13:24 +02:00
|
|
|
<TextareaCopyable :value="dockerCompose" language="yaml" />
|
2023-04-19 22:44:22 +02:00
|
|
|
|
2023-05-27 17:36:15 +02:00
|
|
|
<div mt-5 flex justify-center>
|
2023-05-28 23:13:24 +02:00
|
|
|
<c-button :disabled="dockerCompose === ''" secondary @click="download">
|
|
|
|
Download docker-compose.yml
|
|
|
|
</c-button>
|
2023-05-27 17:36:15 +02:00
|
|
|
</div>
|
2023-04-06 00:10:19 +02:00
|
|
|
|
|
|
|
<div v-if="errors.length > 0">
|
2023-04-19 22:44:22 +02:00
|
|
|
<n-alert title="The following errors occured" type="error" mt-5>
|
2023-04-06 00:16:32 +02:00
|
|
|
<ul>
|
2023-05-28 23:13:24 +02:00
|
|
|
<li v-for="(message, index) of errors" :key="index">
|
|
|
|
{{ message }}
|
|
|
|
</li>
|
2023-04-06 00:16:32 +02:00
|
|
|
</ul>
|
2023-04-06 00:10:19 +02:00
|
|
|
</n-alert>
|
|
|
|
</div>
|
2023-03-27 17:31:13 +02:00
|
|
|
</div>
|
|
|
|
</template>
|