mirror of
https://github.com/cupcakearmy/coolify.git
synced 2024-10-23 00:24:15 +02:00
feat: custom docker compose file location in repo
This commit is contained in:
parent
fffc6b1e4e
commit
067f502d3c
@ -78,6 +78,7 @@ import * as buildpacks from '../lib/buildPacks';
|
|||||||
baseDirectory,
|
baseDirectory,
|
||||||
publishDirectory,
|
publishDirectory,
|
||||||
dockerFileLocation,
|
dockerFileLocation,
|
||||||
|
dockerComposeFileLocation,
|
||||||
dockerComposeConfiguration,
|
dockerComposeConfiguration,
|
||||||
denoMainFile
|
denoMainFile
|
||||||
} = application
|
} = application
|
||||||
@ -158,6 +159,7 @@ import * as buildpacks from '../lib/buildPacks';
|
|||||||
publishDirectory = configuration.publishDirectory;
|
publishDirectory = configuration.publishDirectory;
|
||||||
baseDirectory = configuration.baseDirectory || '';
|
baseDirectory = configuration.baseDirectory || '';
|
||||||
dockerFileLocation = configuration.dockerFileLocation;
|
dockerFileLocation = configuration.dockerFileLocation;
|
||||||
|
dockerComposeFileLocation = configuration.dockerComposeFileLocation;
|
||||||
denoMainFile = configuration.denoMainFile;
|
denoMainFile = configuration.denoMainFile;
|
||||||
const commit = await importers[gitSource.type]({
|
const commit = await importers[gitSource.type]({
|
||||||
applicationId,
|
applicationId,
|
||||||
@ -266,6 +268,7 @@ import * as buildpacks from '../lib/buildPacks';
|
|||||||
pythonVariable,
|
pythonVariable,
|
||||||
dockerFileLocation,
|
dockerFileLocation,
|
||||||
dockerComposeConfiguration,
|
dockerComposeConfiguration,
|
||||||
|
dockerComposeFileLocation,
|
||||||
denoMainFile,
|
denoMainFile,
|
||||||
denoOptions,
|
denoOptions,
|
||||||
baseImage,
|
baseImage,
|
||||||
|
@ -363,6 +363,7 @@ export const setDefaultConfiguration = async (data: any) => {
|
|||||||
publishDirectory,
|
publishDirectory,
|
||||||
baseDirectory,
|
baseDirectory,
|
||||||
dockerFileLocation,
|
dockerFileLocation,
|
||||||
|
dockerComposeFileLocation,
|
||||||
denoMainFile
|
denoMainFile
|
||||||
} = data;
|
} = data;
|
||||||
//@ts-ignore
|
//@ts-ignore
|
||||||
@ -392,6 +393,12 @@ export const setDefaultConfiguration = async (data: any) => {
|
|||||||
} else {
|
} else {
|
||||||
dockerFileLocation = '/Dockerfile';
|
dockerFileLocation = '/Dockerfile';
|
||||||
}
|
}
|
||||||
|
if (dockerComposeFileLocation) {
|
||||||
|
if (!dockerComposeFileLocation.startsWith('/')) dockerComposeFileLocation = `/${dockerComposeFileLocation}`;
|
||||||
|
if (dockerComposeFileLocation.endsWith('/')) dockerComposeFileLocation = dockerComposeFileLocation.slice(0, -1);
|
||||||
|
} else {
|
||||||
|
dockerComposeFileLocation = '/Dockerfile';
|
||||||
|
}
|
||||||
if (!denoMainFile) {
|
if (!denoMainFile) {
|
||||||
denoMainFile = 'main.ts';
|
denoMainFile = 'main.ts';
|
||||||
}
|
}
|
||||||
@ -405,6 +412,7 @@ export const setDefaultConfiguration = async (data: any) => {
|
|||||||
publishDirectory,
|
publishDirectory,
|
||||||
baseDirectory,
|
baseDirectory,
|
||||||
dockerFileLocation,
|
dockerFileLocation,
|
||||||
|
dockerComposeFileLocation,
|
||||||
denoMainFile
|
denoMainFile
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
@ -17,23 +17,11 @@ export default async function (data) {
|
|||||||
secrets,
|
secrets,
|
||||||
pullmergeRequestId,
|
pullmergeRequestId,
|
||||||
port,
|
port,
|
||||||
dockerComposeConfiguration
|
dockerComposeConfiguration,
|
||||||
|
dockerComposeFileLocation
|
||||||
} = data
|
} = data
|
||||||
const fileYml = `${workdir}${baseDirectory}/docker-compose.yml`;
|
const fileYaml = `${workdir}${baseDirectory}${dockerComposeFileLocation}`
|
||||||
const fileYaml = `${workdir}${baseDirectory}/docker-compose.yaml`;
|
const dockerComposeRaw = await fs.readFile(fileYaml, 'utf8');
|
||||||
let dockerComposeRaw = null;
|
|
||||||
let isYml = false;
|
|
||||||
try {
|
|
||||||
dockerComposeRaw = await fs.readFile(`${fileYml}`, 'utf8')
|
|
||||||
isYml = true
|
|
||||||
} catch (error) { }
|
|
||||||
try {
|
|
||||||
dockerComposeRaw = await fs.readFile(`${fileYaml}`, 'utf8')
|
|
||||||
} catch (error) { }
|
|
||||||
|
|
||||||
if (!dockerComposeRaw) {
|
|
||||||
throw ('docker-compose.yml or docker-compose.yaml are not found!');
|
|
||||||
}
|
|
||||||
const dockerComposeYaml = yaml.load(dockerComposeRaw)
|
const dockerComposeYaml = yaml.load(dockerComposeRaw)
|
||||||
if (!dockerComposeYaml.services) {
|
if (!dockerComposeYaml.services) {
|
||||||
throw 'No Services found in docker-compose file.'
|
throw 'No Services found in docker-compose file.'
|
||||||
@ -119,7 +107,7 @@ export default async function (data) {
|
|||||||
dockerComposeYaml['volumes'] = { ...composeVolumes }
|
dockerComposeYaml['volumes'] = { ...composeVolumes }
|
||||||
}
|
}
|
||||||
dockerComposeYaml['networks'] = Object.assign({ ...networks }, { [network]: { external: true } })
|
dockerComposeYaml['networks'] = Object.assign({ ...networks }, { [network]: { external: true } })
|
||||||
await fs.writeFile(`${workdir}/docker-compose.${isYml ? 'yml' : 'yaml'}`, yaml.dump(dockerComposeYaml));
|
await fs.writeFile(fileYaml, yaml.dump(dockerComposeYaml));
|
||||||
await executeDockerCmd({ debug, buildId, applicationId, dockerId, command: `docker compose --project-directory ${workdir} pull` })
|
await executeDockerCmd({ debug, buildId, applicationId, dockerId, command: `docker compose --project-directory ${workdir} pull` })
|
||||||
await saveBuildLog({ line: 'Pulling images from Compose file.', buildId, applicationId });
|
await saveBuildLog({ line: 'Pulling images from Compose file.', buildId, applicationId });
|
||||||
await executeDockerCmd({ debug, buildId, applicationId, dockerId, command: `docker compose --project-directory ${workdir} build --progress plain` })
|
await executeDockerCmd({ debug, buildId, applicationId, dockerId, command: `docker compose --project-directory ${workdir} build --progress plain` })
|
||||||
|
@ -351,6 +351,7 @@ export async function saveApplication(request: FastifyRequest<SaveApplication>,
|
|||||||
publishDirectory,
|
publishDirectory,
|
||||||
baseDirectory,
|
baseDirectory,
|
||||||
dockerFileLocation,
|
dockerFileLocation,
|
||||||
|
dockerComposeFileLocation,
|
||||||
denoMainFile
|
denoMainFile
|
||||||
});
|
});
|
||||||
if (baseDatabaseBranch) {
|
if (baseDatabaseBranch) {
|
||||||
@ -820,7 +821,7 @@ export async function saveRepository(request, reply) {
|
|||||||
let { repository, branch, projectId, autodeploy, webhookToken, isPublicRepository = false } = request.body
|
let { repository, branch, projectId, autodeploy, webhookToken, isPublicRepository = false } = request.body
|
||||||
|
|
||||||
repository = repository.toLowerCase();
|
repository = repository.toLowerCase();
|
||||||
|
|
||||||
projectId = Number(projectId);
|
projectId = Number(projectId);
|
||||||
if (webhookToken) {
|
if (webhookToken) {
|
||||||
await prisma.application.update({
|
await prisma.application.update({
|
||||||
|
@ -82,8 +82,8 @@
|
|||||||
|
|
||||||
let dockerComposeFile = JSON.parse(application.dockerComposeFile) || null;
|
let dockerComposeFile = JSON.parse(application.dockerComposeFile) || null;
|
||||||
let dockerComposeServices: any[] = [];
|
let dockerComposeServices: any[] = [];
|
||||||
let dockerComposeFileLocation = application.dockerComposeFileLocation;
|
|
||||||
let dockerComposeConfiguration = JSON.parse(application.dockerComposeConfiguration) || {};
|
let dockerComposeConfiguration = JSON.parse(application.dockerComposeConfiguration) || {};
|
||||||
|
let originalDockerComposeFileLocation = application.dockerComposeFileLocation;
|
||||||
|
|
||||||
let baseDatabaseBranch: any = application?.connectedDatabase?.hostedDatabaseDBName || null;
|
let baseDatabaseBranch: any = application?.connectedDatabase?.hostedDatabaseDBName || null;
|
||||||
let nonWWWDomain = application.fqdn && getDomain(application.fqdn).replace(/^www\./, '');
|
let nonWWWDomain = application.fqdn && getDomain(application.fqdn).replace(/^www\./, '');
|
||||||
@ -243,8 +243,12 @@
|
|||||||
if (toast) loading.save = true;
|
if (toast) loading.save = true;
|
||||||
try {
|
try {
|
||||||
nonWWWDomain = application.fqdn && getDomain(application.fqdn).replace(/^www\./, '');
|
nonWWWDomain = application.fqdn && getDomain(application.fqdn).replace(/^www\./, '');
|
||||||
if (application.deploymentType)
|
if (application.deploymentType) {
|
||||||
application.deploymentType = application.deploymentType.toLowerCase();
|
application.deploymentType = application.deploymentType.toLowerCase();
|
||||||
|
}
|
||||||
|
if (originalDockerComposeFileLocation !== application.dockerComposeFileLocation) {
|
||||||
|
await reloadCompose();
|
||||||
|
}
|
||||||
if (!isBot) {
|
if (!isBot) {
|
||||||
await post(`/applications/${id}/check`, {
|
await post(`/applications/${id}/check`, {
|
||||||
fqdn: application.fqdn,
|
fqdn: application.fqdn,
|
||||||
@ -365,6 +369,9 @@
|
|||||||
async function reloadCompose() {
|
async function reloadCompose() {
|
||||||
if (loading.reloadCompose) return;
|
if (loading.reloadCompose) return;
|
||||||
loading.reloadCompose = true;
|
loading.reloadCompose = true;
|
||||||
|
const composeLocation = application.dockerComposeFileLocation.startsWith('/')
|
||||||
|
? application.dockerComposeFileLocation
|
||||||
|
: `/${application.dockerComposeFileLocation}`;
|
||||||
try {
|
try {
|
||||||
if (application.gitSource.type === 'github') {
|
if (application.gitSource.type === 'github') {
|
||||||
const headers = isPublicRepository
|
const headers = isPublicRepository
|
||||||
@ -373,9 +380,10 @@
|
|||||||
Authorization: `token ${$appSession.tokens.github}`
|
Authorization: `token ${$appSession.tokens.github}`
|
||||||
};
|
};
|
||||||
const data = await get(
|
const data = await get(
|
||||||
`${apiUrl}/repos/${repository}/contents/${dockerComposeFileLocation}?ref=${branch}`,
|
`${apiUrl}/repos/${repository}/contents/${composeLocation}?ref=${branch}`,
|
||||||
{
|
{
|
||||||
...headers,
|
...headers,
|
||||||
|
'If-None-Match': '',
|
||||||
Accept: 'application/vnd.github.v2.json'
|
Accept: 'application/vnd.github.v2.json'
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
@ -405,7 +413,7 @@
|
|||||||
});
|
});
|
||||||
const dockerComposeFileYml = files.find(
|
const dockerComposeFileYml = files.find(
|
||||||
(file: { name: string; type: string }) =>
|
(file: { name: string; type: string }) =>
|
||||||
file.name === dockerComposeFileLocation && file.type === 'blob'
|
file.name === composeLocation && file.type === 'blob'
|
||||||
);
|
);
|
||||||
const id = dockerComposeFileYml.id;
|
const id = dockerComposeFileYml.id;
|
||||||
|
|
||||||
@ -424,12 +432,17 @@
|
|||||||
await handleSubmit(false);
|
await handleSubmit(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
originalDockerComposeFileLocation = application.dockerComposeFileLocation;
|
||||||
addToast({
|
addToast({
|
||||||
message: 'Compose file reloaded.',
|
message: 'Compose file reloaded.',
|
||||||
type: 'success'
|
type: 'success'
|
||||||
});
|
});
|
||||||
} catch (error) {
|
} catch (error: any) {
|
||||||
|
if (error.message === 'Not Found') {
|
||||||
|
error.message = `Can't find ${application.dockerComposeFileLocation} file.`;
|
||||||
|
errorNotification(error);
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
errorNotification(error);
|
errorNotification(error);
|
||||||
} finally {
|
} finally {
|
||||||
loading.reloadCompose = false;
|
loading.reloadCompose = false;
|
||||||
@ -1029,6 +1042,25 @@
|
|||||||
{/if}
|
{/if}
|
||||||
</div>
|
</div>
|
||||||
<div class="grid grid-flow-row gap-2">
|
<div class="grid grid-flow-row gap-2">
|
||||||
|
<div class="grid grid-cols-2 items-center px-8 pb-4">
|
||||||
|
<label for="dockerComposeFileLocation"
|
||||||
|
>Docker Compose File Location
|
||||||
|
<Explainer
|
||||||
|
explanation="You can specify a custom docker compose file location. <br> Should be absolute path, like <span class='text-settings font-bold'>/data/docker-compose.yml</span> or <span class='text-settings font-bold'>/docker-compose.yml.</span>"
|
||||||
|
/>
|
||||||
|
</label>
|
||||||
|
<div>
|
||||||
|
<input
|
||||||
|
class="w-full"
|
||||||
|
disabled={isDisabled}
|
||||||
|
readonly={!$appSession.isAdmin}
|
||||||
|
name="dockerComposeFileLocation"
|
||||||
|
id="dockerComposeFileLocation"
|
||||||
|
bind:value={application.dockerComposeFileLocation}
|
||||||
|
placeholder="eg: /docker-compose.yml"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
{#each dockerComposeServices as service}
|
{#each dockerComposeServices as service}
|
||||||
<div
|
<div
|
||||||
class="grid items-center bg-coolgray-100 rounded border border-coolgray-300 p-2 px-4"
|
class="grid items-center bg-coolgray-100 rounded border border-coolgray-300 p-2 px-4"
|
||||||
|
Loading…
Reference in New Issue
Block a user