feat: Multiply dockerfile locations for docker buildpack

This commit is contained in:
Andras Bacsai 2022-04-19 22:34:28 +02:00
parent 625e71ab08
commit 2b28f8bd8f
10 changed files with 57 additions and 22 deletions

View File

@ -0,0 +1,2 @@
-- AlterTable
ALTER TABLE "Application" ADD COLUMN "dockerFileLocation" TEXT;

View File

@ -91,6 +91,7 @@ model Application {
pythonWSGI String? pythonWSGI String?
pythonModule String? pythonModule String?
pythonVariable String? pythonVariable String?
dockerFileLocation String?
createdAt DateTime @default(now()) createdAt DateTime @default(now())
updatedAt DateTime @updatedAt updatedAt DateTime @updatedAt
settings ApplicationSettings? settings ApplicationSettings?

View File

@ -91,7 +91,8 @@ export const setDefaultConfiguration = async (data) => {
startCommand, startCommand,
buildCommand, buildCommand,
publishDirectory, publishDirectory,
baseDirectory baseDirectory,
dockerFileLocation
} = data; } = data;
const template = scanningTemplates[buildPack]; const template = scanningTemplates[buildPack];
if (!port) { if (!port) {
@ -110,6 +111,12 @@ export const setDefaultConfiguration = async (data) => {
if (!baseDirectory.startsWith('/')) baseDirectory = `/${baseDirectory}`; if (!baseDirectory.startsWith('/')) baseDirectory = `/${baseDirectory}`;
if (!baseDirectory.endsWith('/')) baseDirectory = `${baseDirectory}/`; if (!baseDirectory.endsWith('/')) baseDirectory = `${baseDirectory}/`;
} }
if (dockerFileLocation) {
if (!dockerFileLocation.startsWith('/')) dockerFileLocation = `/${dockerFileLocation}`;
if (dockerFileLocation.endsWith('/')) dockerFileLocation = dockerFileLocation.slice(0, -1);
} else {
dockerFileLocation = '/Dockerfile';
}
return { return {
buildPack, buildPack,
@ -118,7 +125,8 @@ export const setDefaultConfiguration = async (data) => {
startCommand, startCommand,
buildCommand, buildCommand,
publishDirectory, publishDirectory,
baseDirectory baseDirectory,
dockerFileLocation
}; };
}; };

View File

@ -10,15 +10,16 @@ export default async function ({
buildId, buildId,
baseDirectory, baseDirectory,
secrets, secrets,
pullmergeRequestId pullmergeRequestId,
dockerFileLocation
}) { }) {
try { try {
let file = `${workdir}/Dockerfile`; const file = `${workdir}${dockerFileLocation}`;
let dockerFileOut = `${workdir}`;
if (baseDirectory) { if (baseDirectory) {
file = `${workdir}/${baseDirectory}/Dockerfile`; dockerFileOut = `${workdir}${baseDirectory}`;
workdir = `${workdir}/${baseDirectory}`; workdir = `${workdir}${baseDirectory}`;
} }
const Dockerfile: Array<string> = (await fs.readFile(`${file}`, 'utf8')) const Dockerfile: Array<string> = (await fs.readFile(`${file}`, 'utf8'))
.toString() .toString()
.trim() .trim()
@ -41,8 +42,8 @@ export default async function ({
} }
}); });
} }
await fs.writeFile(`${file}`, Dockerfile.join('\n')); await fs.writeFile(`${dockerFileOut}${dockerFileLocation}`, Dockerfile.join('\n'));
await buildImage({ applicationId, tag, workdir, docker, buildId, debug }); await buildImage({ applicationId, tag, workdir, docker, buildId, debug, dockerFileLocation });
} catch (error) { } catch (error) {
throw error; throw error;
} }

View File

@ -263,7 +263,8 @@ export async function configureApplication({
publishDirectory, publishDirectory,
pythonWSGI, pythonWSGI,
pythonModule, pythonModule,
pythonVariable pythonVariable,
dockerFileLocation
}: { }: {
id: string; id: string;
buildPack: string; buildPack: string;
@ -278,6 +279,7 @@ export async function configureApplication({
pythonWSGI: string; pythonWSGI: string;
pythonModule: string; pythonModule: string;
pythonVariable: string; pythonVariable: string;
dockerFileLocation: string;
}): Promise<Application> { }): Promise<Application> {
return await prisma.application.update({ return await prisma.application.update({
where: { id }, where: { id },
@ -293,7 +295,8 @@ export async function configureApplication({
publishDirectory, publishDirectory,
pythonWSGI, pythonWSGI,
pythonModule, pythonModule,
pythonVariable pythonVariable,
dockerFileLocation
} }
}); });
} }

View File

@ -85,7 +85,8 @@ export async function buildImage({
docker, docker,
buildId, buildId,
isCache = false, isCache = false,
debug = false debug = false,
dockerFileLocation = '/Dockerfile'
}) { }) {
if (isCache) { if (isCache) {
await saveBuildLog({ line: `Building cache image started.`, buildId, applicationId }); await saveBuildLog({ line: `Building cache image started.`, buildId, applicationId });
@ -103,7 +104,7 @@ export async function buildImage({
const stream = await docker.engine.buildImage( const stream = await docker.engine.buildImage(
{ src: ['.'], context: workdir }, { src: ['.'], context: workdir },
{ {
dockerfile: isCache ? 'Dockerfile-cache' : 'Dockerfile', dockerfile: isCache ? `${dockerFileLocation}-cache` : dockerFileLocation,
t: `${applicationId}:${tag}${isCache ? '-cache' : ''}` t: `${applicationId}:${tag}${isCache ? '-cache' : ''}`
} }
); );

View File

@ -56,7 +56,8 @@ export default async function (job: Job<BuilderJob, void, string>): Promise<void
buildCommand, buildCommand,
startCommand, startCommand,
baseDirectory, baseDirectory,
publishDirectory publishDirectory,
dockerFileLocation
} = job.data; } = job.data;
const { debug } = settings; const { debug } = settings;
@ -107,6 +108,7 @@ export default async function (job: Job<BuilderJob, void, string>): Promise<void
buildCommand = configuration.buildCommand; buildCommand = configuration.buildCommand;
publishDirectory = configuration.publishDirectory; publishDirectory = configuration.publishDirectory;
baseDirectory = configuration.baseDirectory; baseDirectory = configuration.baseDirectory;
dockerFileLocation = configuration.dockerFileLocation;
const commit = await importers[gitSource.type]({ const commit = await importers[gitSource.type]({
applicationId, applicationId,
@ -209,7 +211,8 @@ export default async function (job: Job<BuilderJob, void, string>): Promise<void
phpModules, phpModules,
pythonWSGI, pythonWSGI,
pythonModule, pythonModule,
pythonVariable pythonVariable,
dockerFileLocation
}); });
else { else {
await saveBuildLog({ line: `Build pack ${buildPack} not found`, buildId, applicationId }); await saveBuildLog({ line: `Build pack ${buildPack} not found`, buildId, applicationId });

View File

@ -21,6 +21,7 @@ export type BuilderJob = {
pythonWSGI: string; pythonWSGI: string;
pythonModule: string; pythonModule: string;
pythonVariable: string; pythonVariable: string;
dockerFileLocation: string;
createdAt: string; createdAt: string;
updatedAt: string; updatedAt: string;
destinationDockerId: string; destinationDockerId: string;

View File

@ -56,7 +56,8 @@ export const post: RequestHandler = async (event) => {
publishDirectory, publishDirectory,
pythonWSGI, pythonWSGI,
pythonModule, pythonModule,
pythonVariable pythonVariable,
dockerFileLocation
} = await event.request.json(); } = await event.request.json();
if (port) port = Number(port); if (port) port = Number(port);
@ -68,7 +69,8 @@ export const post: RequestHandler = async (event) => {
startCommand, startCommand,
buildCommand, buildCommand,
publishDirectory, publishDirectory,
baseDirectory baseDirectory,
dockerFileLocation
}); });
await db.configureApplication({ await db.configureApplication({
id, id,
@ -84,6 +86,7 @@ export const post: RequestHandler = async (event) => {
pythonWSGI, pythonWSGI,
pythonModule, pythonModule,
pythonVariable, pythonVariable,
dockerFileLocation,
...defaultConfiguration ...defaultConfiguration
}); });
return { status: 201 }; return { status: 201 };

View File

@ -68,11 +68,6 @@
value: 'Gunicorn', value: 'Gunicorn',
label: 'Gunicorn' label: 'Gunicorn'
} }
// },
// {
// value: 'uWSGI',
// label: 'uWSGI'
// }
]; ];
if (browser && window.location.hostname === 'demo.coolify.io' && !application.fqdn) { if (browser && window.location.hostname === 'demo.coolify.io' && !application.fqdn) {
@ -420,6 +415,23 @@
/> />
</div> </div>
{/if} {/if}
{#if application.buildPack === 'docker'}
<div class="grid grid-cols-2 items-center">
<label for="dockerFileLocation" class="text-base font-bold text-stone-100"
>Dockerfile Location</label
>
<input
readonly={!$session.isAdmin}
name="dockerFileLocation"
id="dockerFileLocation"
bind:value={application.dockerFileLocation}
placeholder="default: /Dockerfile"
/>
<Explainer
text="Does not rely on Base Directory. <br>Should be absolute path, like <span class='text-green-500 font-bold'>/data/Dockerfile</span> or <span class='text-green-500 font-bold'>/Dockerfile.</span>"
/>
</div>
{/if}
<div class="grid grid-cols-2 items-center"> <div class="grid grid-cols-2 items-center">
<div class="flex-col"> <div class="flex-col">
<label for="baseDirectory" class="pt-2 text-base font-bold text-stone-100" <label for="baseDirectory" class="pt-2 text-base font-bold text-stone-100"