Skip to content

An open-source, self-hostable PaaS alternative to Vercel, Heroku & Netlify that lets you easily deploy static sites, databases, full-stack applications and 360+ one-click services on your own servers.

feat: Multiply dockerfile locations for docker buildpack

Andras Bacsai2b28f8bd8f83
diff --git a/prisma/migrations/20220419203408_multiply_dockerfile_locations/migration.sql b/prisma/migrations/20220419203408_multiply_dockerfile_locations/migration.sql
new file mode 100644
index 0000000000..ce32f0844f
--- /dev/null
+++ b/prisma/migrations/20220419203408_multiply_dockerfile_locations/migration.sql
@@ -0,0 +1,2 @@
+-- AlterTable
+ALTER TABLE "Application" ADD COLUMN "dockerFileLocation" TEXT;
diff --git a/prisma/schema.prisma b/prisma/schema.prisma
index 712958add1..668f4588a1 100644
--- a/prisma/schema.prisma
+++ b/prisma/schema.prisma
@@ -91,6 +91,7 @@ model Application {
pythonWSGI String?
pythonModule String?
pythonVariable String?
+ dockerFileLocation String?
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
settings ApplicationSettings?
diff --git a/src/lib/buildPacks/common.ts b/src/lib/buildPacks/common.ts
index 65f4d69035..e6f62bd23e 100644
--- a/src/lib/buildPacks/common.ts
+++ b/src/lib/buildPacks/common.ts
@@ -91,7 +91,8 @@ export const setDefaultConfiguration = async (data) => {
startCommand,
buildCommand,
publishDirectory,
- baseDirectory
+ baseDirectory,
+ dockerFileLocation
} = data;
const template = scanningTemplates[buildPack];
if (!port) {
@@ -110,6 +111,12 @@ export const setDefaultConfiguration = async (data) => {
if (!baseDirectory.startsWith('/')) 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 {
buildPack,
@@ -118,7 +125,8 @@ export const setDefaultConfiguration = async (data) => {
startCommand,
buildCommand,
publishDirectory,
- baseDirectory
+ baseDirectory,
+ dockerFileLocation
};
};
diff --git a/src/lib/buildPacks/docker.ts b/src/lib/buildPacks/docker.ts
index 2db5d567c8..1ddf81a607 100644
--- a/src/lib/buildPacks/docker.ts
+++ b/src/lib/buildPacks/docker.ts
@@ -10,15 +10,16 @@ export default async function ({
buildId,
baseDirectory,
secrets,
- pullmergeRequestId
+ pullmergeRequestId,
+ dockerFileLocation
}) {
try {
- let file = `${workdir}/Dockerfile`;
+ const file = `${workdir}${dockerFileLocation}`;
+ let dockerFileOut = `${workdir}`;
if (baseDirectory) {
- file = `${workdir}/${baseDirectory}/Dockerfile`;
- workdir = `${workdir}/${baseDirectory}`;
+ dockerFileOut = `${workdir}${baseDirectory}`;
+ workdir = `${workdir}${baseDirectory}`;
}
-
const Dockerfile: Array<string> = (await fs.readFile(`${file}`, 'utf8'))
.toString()
.trim()
@@ -41,8 +42,8 @@ export default async function ({
}
});
}
- await fs.writeFile(`${file}`, Dockerfile.join('\n'));
- await buildImage({ applicationId, tag, workdir, docker, buildId, debug });
+ await fs.writeFile(`${dockerFileOut}${dockerFileLocation}`, Dockerfile.join('\n'));
+ await buildImage({ applicationId, tag, workdir, docker, buildId, debug, dockerFileLocation });
} catch (error) {
throw error;
}
diff --git a/src/lib/database/applications.ts b/src/lib/database/applications.ts
index 3ce6286d71..020b9ba759 100644
--- a/src/lib/database/applications.ts
+++ b/src/lib/database/applications.ts
@@ -263,7 +263,8 @@ export async function configureApplication({
publishDirectory,
pythonWSGI,
pythonModule,
- pythonVariable
+ pythonVariable,
+ dockerFileLocation
}: {
id: string;
buildPack: string;
@@ -278,6 +279,7 @@ export async function configureApplication({
pythonWSGI: string;
pythonModule: string;
pythonVariable: string;
+ dockerFileLocation: string;
}): Promise<Application> {
return await prisma.application.update({
where: { id },
@@ -293,7 +295,8 @@ export async function configureApplication({
publishDirectory,
pythonWSGI,
pythonModule,
- pythonVariable
+ pythonVariable,
+ dockerFileLocation
}
});
}
diff --git a/src/lib/docker.ts b/src/lib/docker.ts
index 04f68ac48a..c2642623fa 100644
--- a/src/lib/docker.ts
+++ b/src/lib/docker.ts
@@ -85,7 +85,8 @@ export async function buildImage({
docker,
buildId,
isCache = false,
- debug = false
+ debug = false,
+ dockerFileLocation = '/Dockerfile'
}) {
if (isCache) {
await saveBuildLog({ line: `Building cache image started.`, buildId, applicationId });
@@ -103,7 +104,7 @@ export async function buildImage({
const stream = await docker.engine.buildImage(
{ src: ['.'], context: workdir },
{
- dockerfile: isCache ? 'Dockerfile-cache' : 'Dockerfile',
+ dockerfile: isCache ? `${dockerFileLocation}-cache` : dockerFileLocation,
t: `${applicationId}:${tag}${isCache ? '-cache' : ''}`
}
);
diff --git a/src/lib/queues/builder.ts b/src/lib/queues/builder.ts
index e761043768..076c5a5118 100644
--- a/src/lib/queues/builder.ts
+++ b/src/lib/queues/builder.ts
@@ -56,7 +56,8 @@ export default async function (job: Job<BuilderJob, void, string>): Promise<void
buildCommand,
startCommand,
baseDirectory,
- publishDirectory
+ publishDirectory,
+ dockerFileLocation
} = job.data;
const { debug } = settings;
@@ -107,6 +108,7 @@ export default async function (job: Job<BuilderJob, void, string>): Promise<void
buildCommand = configuration.buildCommand;
publishDirectory = configuration.publishDirectory;
baseDirectory = configuration.baseDirectory;
+ dockerFileLocation = configuration.dockerFileLocation;
const commit = await importers[gitSource.type]({
applicationId,
@@ -209,7 +211,8 @@ export default async function (job: Job<BuilderJob, void, string>): Promise<void
phpModules,
pythonWSGI,
pythonModule,
- pythonVariable
+ pythonVariable,
+ dockerFileLocation
});
else {
await saveBuildLog({ line: `Build pack ${buildPack} not found`, buildId, applicationId });
diff --git a/src/lib/types/builderJob.ts b/src/lib/types/builderJob.ts
index 1a1652f8a7..30a38bfd9f 100644
--- a/src/lib/types/builderJob.ts
+++ b/src/lib/types/builderJob.ts
@@ -21,6 +21,7 @@ export type BuilderJob = {
pythonWSGI: string;
pythonModule: string;
pythonVariable: string;
+ dockerFileLocation: string;
createdAt: string;
updatedAt: string;
destinationDockerId: string;
diff --git a/src/routes/applications/[id]/index.json.ts b/src/routes/applications/[id]/index.json.ts
index 8a67242d21..1b3bc75978 100644
--- a/src/routes/applications/[id]/index.json.ts
+++ b/src/routes/applications/[id]/index.json.ts
@@ -56,7 +56,8 @@ export const post: RequestHandler = async (event) => {
publishDirectory,
pythonWSGI,
pythonModule,
- pythonVariable
+ pythonVariable,
+ dockerFileLocation
} = await event.request.json();
if (port) port = Number(port);
@@ -68,7 +69,8 @@ export const post: RequestHandler = async (event) => {
startCommand,
buildCommand,
publishDirectory,
- baseDirectory
+ baseDirectory,
+ dockerFileLocation
});
await db.configureApplication({
id,
@@ -84,6 +86,7 @@ export const post: RequestHandler = async (event) => {
pythonWSGI,
pythonModule,
pythonVariable,
+ dockerFileLocation,
...defaultConfiguration
});
return { status: 201 };
diff --git a/src/routes/applications/[id]/index.svelte b/src/routes/applications/[id]/index.svelte
index 4b7d6b497d..b1939913ea 100644
--- a/src/routes/applications/[id]/index.svelte
+++ b/src/routes/applications/[id]/index.svelte
@@ -68,11 +68,6 @@
value: 'Gunicorn',
label: 'Gunicorn'
}
- // },
- // {
- // value: 'uWSGI',
- // label: 'uWSGI'
- // }
];
if (browser && window.location.hostname === 'demo.coolify.io' && !application.fqdn) {
@@ -420,6 +415,23 @@
/>
</div>
{/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="flex-col">
<label for="baseDirectory" class="pt-2 text-base font-bold text-stone-100"