fix: volume names for undefined volume names in compose
This commit is contained in:
parent
47c0d522db
commit
66276be1d2
@ -38,9 +38,10 @@ export default async function (data) {
|
|||||||
if (!dockerComposeYaml.services) {
|
if (!dockerComposeYaml.services) {
|
||||||
throw 'No Services found in docker-compose file.'
|
throw 'No Services found in docker-compose file.'
|
||||||
}
|
}
|
||||||
const envs = [
|
const envs = [];
|
||||||
`PORT=${port}`
|
if (Object.entries(dockerComposeYaml.services).length === 1) {
|
||||||
];
|
envs.push(`PORT=${port}`)
|
||||||
|
}
|
||||||
if (secrets.length > 0) {
|
if (secrets.length > 0) {
|
||||||
secrets.forEach((secret) => {
|
secrets.forEach((secret) => {
|
||||||
if (pullmergeRequestId) {
|
if (pullmergeRequestId) {
|
||||||
@ -65,30 +66,36 @@ export default async function (data) {
|
|||||||
//
|
//
|
||||||
}
|
}
|
||||||
const composeVolumes = [];
|
const composeVolumes = [];
|
||||||
|
if (volumes.length > 0) {
|
||||||
for (const volume of volumes) {
|
for (const volume of volumes) {
|
||||||
let [v, _] = volume.split(':');
|
let [v, path] = volume.split(':');
|
||||||
composeVolumes[v] = {
|
composeVolumes[v] = {
|
||||||
name: v,
|
name: v,
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
let networks = {}
|
let networks = {}
|
||||||
for (let [key, value] of Object.entries(dockerComposeYaml.services)) {
|
for (let [key, value] of Object.entries(dockerComposeYaml.services)) {
|
||||||
value['container_name'] = `${applicationId}-${key}`
|
value['container_name'] = `${applicationId}-${key}`
|
||||||
value['env_file'] = envFound ? [`${workdir}/.env`] : []
|
value['env_file'] = envFound ? [`${workdir}/.env`] : []
|
||||||
value['labels'] = labels
|
value['labels'] = labels
|
||||||
// TODO: If we support separated volume for each service, we need to add it here
|
// TODO: If we support separated volume for each service, we need to add it here
|
||||||
if (value['volumes'].length > 0) {
|
if (value['volumes']?.length > 0) {
|
||||||
value['volumes'] = value['volumes'].map((volume) => {
|
value['volumes'] = value['volumes'].map((volume) => {
|
||||||
let [v, path, permission] = volume.split(':');
|
let [v, path, permission] = volume.split(':');
|
||||||
|
if (!path) {
|
||||||
|
path = v;
|
||||||
|
v = `${applicationId}${v.replace(/\//gi, '-')}`
|
||||||
|
} else {
|
||||||
v = `${applicationId}-${v}`
|
v = `${applicationId}-${v}`
|
||||||
|
}
|
||||||
composeVolumes[v] = {
|
composeVolumes[v] = {
|
||||||
name: v
|
name: v
|
||||||
}
|
}
|
||||||
return `${v}:${path}${permission ? ':' + permission : ''}`
|
return `${v}:${path}${permission ? ':' + permission : ''}`
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
if (volumes.length > 0) {
|
if (volumes.length > 0) {
|
||||||
for (const volume of volumes) {
|
for (const volume of volumes) {
|
||||||
value['volumes'].push(volume)
|
value['volumes'].push(volume)
|
||||||
@ -106,6 +113,7 @@ export default async function (data) {
|
|||||||
}
|
}
|
||||||
value['networks'] = [...value['networks'] || '', network]
|
value['networks'] = [...value['networks'] || '', network]
|
||||||
dockerComposeYaml.services[key] = { ...dockerComposeYaml.services[key], restart: defaultComposeConfiguration(network).restart, deploy: defaultComposeConfiguration(network).deploy }
|
dockerComposeYaml.services[key] = { ...dockerComposeYaml.services[key], restart: defaultComposeConfiguration(network).restart, deploy: defaultComposeConfiguration(network).deploy }
|
||||||
|
|
||||||
}
|
}
|
||||||
if (Object.keys(composeVolumes).length > 0) {
|
if (Object.keys(composeVolumes).length > 0) {
|
||||||
dockerComposeYaml['volumes'] = { ...composeVolumes }
|
dockerComposeYaml['volumes'] = { ...composeVolumes }
|
||||||
|
@ -35,7 +35,12 @@
|
|||||||
if (service?.volumes) {
|
if (service?.volumes) {
|
||||||
for (const [_, volumeName] of Object.entries(service.volumes)) {
|
for (const [_, volumeName] of Object.entries(service.volumes)) {
|
||||||
let [volume, target] = volumeName.split(':');
|
let [volume, target] = volumeName.split(':');
|
||||||
|
if (!target) {
|
||||||
|
target = volume;
|
||||||
|
volume = `${application.id}${volume.replace(/\//gi, '-')}`;
|
||||||
|
} else {
|
||||||
volume = `${application.id}-${volume}`;
|
volume = `${application.id}-${volume}`;
|
||||||
|
}
|
||||||
predefinedVolumes.push({ id: volume, path: target, predefined: true });
|
predefinedVolumes.push({ id: volume, path: target, predefined: true });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user