fix: handle log format volumes

This commit is contained in:
Andras Bacsai 2023-03-07 11:46:23 +01:00
parent 05fb26a49b
commit 2adad3a7bd
3 changed files with 104 additions and 56 deletions

View File

@ -78,6 +78,7 @@ export default async function (data) {
// TODO: If we support separated volume for each service, we need to add it here
if (value['volumes']?.length > 0) {
value['volumes'] = value['volumes'].map((volume) => {
if (typeof volume === 'string') {
let [v, path, permission] = volume.split(':');
if (
v.startsWith('.') ||
@ -86,7 +87,7 @@ export default async function (data) {
v.startsWith('~') ||
v.startsWith('$PWD')
) {
v = v.replace('$.', `~`).replace('$..', '~').replace('$$PWD', '~');
v = v.replace(/^\./, `~`).replace(/^\.\./, '~').replace(/^\$PWD/, '~');
} else {
if (!path) {
path = v;
@ -98,8 +99,33 @@ export default async function (data) {
name: v
};
}
return `${v}:${path}${permission ? ':' + permission : ''}`;
}
if (typeof volume === 'object') {
let { source, target, mode } = volume;
if (
source.startsWith('.') ||
source.startsWith('..') ||
source.startsWith('/') ||
source.startsWith('~') ||
source.startsWith('$PWD')
) {
source = source.replace(/^\./, `~`).replace(/^\.\./, '~').replace(/^\$PWD/, '~');
console.log({source})
} else {
if (!target) {
target = source;
source = `${applicationId}${source.replace(/\//gi, '-').replace(/\./gi, '')}`;
} else {
source = `${applicationId}${source.replace(/\//gi, '-').replace(/\./gi, '')}`;
}
}
return `${source}:${target}${mode ? ':' + mode : ''}`;
}
});
}
if (volumes.length > 0) {

View File

@ -427,29 +427,6 @@
</svg> Stop
</button>
{:else if $isDeploymentEnabled && !$page.url.pathname.startsWith(`/applications/${id}/configuration/`)}
{#if $status.application.overallStatus === 'degraded'}
<button
on:click={stopApplication}
type="submit"
disabled={!$isDeploymentEnabled || !$appSession.isAdmin}
class="btn btn-sm gap-2"
>
<svg
xmlns="http://www.w3.org/2000/svg"
class="w-6 h-6 text-error"
viewBox="0 0 24 24"
stroke-width="1.5"
stroke="currentColor"
fill="none"
stroke-linecap="round"
stroke-linejoin="round"
>
<path stroke="none" d="M0 0h24v24H0z" fill="none" />
<rect x="6" y="5" width="4" height="14" rx="1" />
<rect x="14" y="5" width="4" height="14" rx="1" />
</svg> Stop
</button>
{/if}
<button
class="btn btn-sm gap-2"
disabled={!$isDeploymentEnabled || !$appSession.isAdmin}
@ -493,6 +470,29 @@
: 'Redeploy Stack'
: 'Deploy'}
</button>
{#if $status.application.overallStatus === 'degraded'}
<button
on:click={stopApplication}
type="submit"
disabled={!$isDeploymentEnabled || !$appSession.isAdmin}
class="btn btn-sm gap-2"
>
<svg
xmlns="http://www.w3.org/2000/svg"
class="w-6 h-6 text-error"
viewBox="0 0 24 24"
stroke-width="1.5"
stroke="currentColor"
fill="none"
stroke-linecap="round"
stroke-linejoin="round"
>
<path stroke="none" d="M0 0h24v24H0z" fill="none" />
<rect x="6" y="5" width="4" height="14" rx="1" />
<rect x="14" y="5" width="4" height="14" rx="1" />
</svg> Stop
</button>
{/if}
{/if}
{#if $location && $status.application.overallStatus === 'healthy'}
<a href={$location} target="_blank noreferrer" class="btn btn-sm gap-2 text-sm bg-primary"

View File

@ -35,6 +35,7 @@
for (const [_, service] of Object.entries(composeJson.services)) {
if (service?.volumes) {
for (const [_, volumeName] of Object.entries(service.volumes)) {
if (typeof volumeName === 'string') {
let [volume, target] = volumeName.split(':');
if (
volume.startsWith('.') ||
@ -43,7 +44,7 @@
volume.startsWith('~') ||
volume.startsWith('$PWD')
) {
volume = volume.replace('$.', `~`).replace('$..', '~').replace('$$PWD', '~');
volume = volume.replace(/^\./, `~`).replace(/^\.\./, '~').replace(/^\$PWD/, '~');
} else {
if (!target) {
target = volume;
@ -54,6 +55,27 @@
}
predefinedVolumes.push({ id: volume, path: target, predefined: true });
}
if (typeof volumeName === 'object') {
let { source, target } = volumeName;
if (
source.startsWith('.') ||
source.startsWith('..') ||
source.startsWith('/') ||
source.startsWith('~') ||
source.startsWith('$PWD')
) {
source = source.replace(/^\./, `~`).replace(/^\.\./, '~').replace(/^\$PWD/, '~');
} else {
if (!target) {
target = source;
source = `${application.id}${source.replace(/\//gi, '-').replace(/\./gi, '')}`;
} else {
source = `${application.id}${source.replace(/\//gi, '-').replace(/\./gi, '')}`;
}
}
predefinedVolumes.push({ id: source, path: target, predefined: true });
}
}
}
}
}