WIP: Base image selector

This commit is contained in:
Andras Bacsai 2022-04-25 23:44:06 +02:00
parent 62ccab22d6
commit 5998212b82
8 changed files with 51 additions and 6 deletions

View File

@ -105,6 +105,7 @@ model Application {
gitSource GitSource? @relation(fields: [gitSourceId], references: [id])
secrets Secret[]
persistentStorage ApplicationPersistentStorage[]
baseImage String?
}
model ApplicationSettings {

View File

@ -12,6 +12,17 @@ import type {
Application,
ApplicationPersistentStorage
} from '@prisma/client';
const nodeBased = [
'react',
'vuejs',
'static',
'svelte',
'gatsby',
'php',
'astro',
'eleventy',
'node'
];
export async function listApplications(teamId: string): Promise<Application[]> {
if (teamId === '0') {
@ -195,6 +206,24 @@ export async function getApplication({ id, teamId }: { id: string; teamId: strin
return s;
});
}
// Set default build images
if (!body.baseImage) {
if (nodeBased.includes(body.buildPack)) {
body.baseImage = 'node:lts';
}
if (body.buildPack === 'python') {
body.baseImage = 'python:3-alpine';
}
if (body.buildPack === 'rust') {
body.baseImage = 'rust:latest';
}
if (body.buildPack === 'deno') {
body.baseImage = 'denoland/deno:latest';
}
if (body.buildPack === 'php') {
body.baseImage = 'webdevops/php-apache:8.0-alpine';
}
}
return { ...body };
}
@ -266,7 +295,8 @@ export async function configureApplication({
pythonVariable,
dockerFileLocation,
denoMainFile,
denoOptions
denoOptions,
baseImage
}: {
id: string;
buildPack: string;
@ -284,6 +314,7 @@ export async function configureApplication({
dockerFileLocation: string;
denoMainFile: string;
denoOptions: string;
baseImage: string;
}): Promise<Application> {
return await prisma.application.update({
where: { id },
@ -302,7 +333,8 @@ export async function configureApplication({
pythonVariable,
dockerFileLocation,
denoMainFile,
denoOptions
denoOptions,
baseImage
}
});
}

View File

@ -41,10 +41,11 @@ export async function buildCacheImageWithNode(data, imageForBuild) {
Dockerfile.push('RUN curl -f https://get.pnpm.io/v6.16.js | node - add --global pnpm');
Dockerfile.push('RUN pnpm add -g pnpm');
}
Dockerfile.push(`COPY .${baseDirectory || ''} ./`);
if (installCommand) {
Dockerfile.push(`COPY .${baseDirectory || ''}/package.json ./`);
Dockerfile.push(`RUN ${installCommand}`);
}
Dockerfile.push(`COPY .${baseDirectory || ''} ./`);
Dockerfile.push(`RUN ${buildCommand}`);
await fs.writeFile(`${workdir}/Dockerfile-cache`, Dockerfile.join('\n'));
await buildImage({ applicationId, tag, workdir, docker, buildId, isCache: true, debug });

View File

@ -124,7 +124,7 @@
"no_branches_found": "No branches found",
"configure_build_pack": "Configure Build Pack",
"scanning_repository_suggest_build_pack": "Scanning repository to suggest a build pack for you...",
"found_lock_file": "Found lock file for <span class=\"font-bold text-orange-500 pl-1\">{{packageManager}}</span>. Using it for predefined commands commands.",
"found_lock_file": "Found lock file for <span class=\"font-bold text-orange-500 px-1\"> {{packageManager}}</span>.Using it for predefined commands commands.",
"configure_destination": "Configure Destination",
"no_configurable_destination": "No configurable Destination found",
"select_a_repository_project": "Select a Repository / Project",
@ -184,6 +184,7 @@
"git_source": "Git Source",
"git_repository": "Git Repository",
"build_pack": "Build Pack",
"base_image": "Base Image",
"destination": "Destination",
"application": "Application",
"url_fqdn": "URL (FQDN)",

View File

@ -225,7 +225,7 @@
<div class="max-w-7xl mx-auto flex flex-wrap justify-center">
{#each buildPacks as buildPack}
<div class="p-2">
<BuildPack {buildPack} {scanning} bind:foundConfig />
<BuildPack {packageManager} {buildPack} {scanning} bind:foundConfig />
</div>
{/each}
</div>

View File

@ -62,7 +62,8 @@ export const post: RequestHandler = async (event) => {
pythonVariable,
dockerFileLocation,
denoMainFile,
denoOptions
denoOptions,
baseImage
} = await event.request.json();
if (port) port = Number(port);
if (denoOptions) denoOptions = denoOptions.trim();
@ -96,6 +97,7 @@ export const post: RequestHandler = async (event) => {
dockerFileLocation,
denoMainFile,
denoOptions,
baseImage,
...defaultConfiguration
});
return { status: 201 };

View File

@ -310,6 +310,14 @@
/>
</div>
</div>
<div class="grid grid-cols-2 items-center pb-8">
<label for="baseImage" class="text-base font-bold text-stone-100"
>{$t('application.base_image')}</label
>
<div class="no-underline">
<input value={application.baseImage} id="baseImage" disabled class="bg-transparent " />
</div>
</div>
</div>
<div class="flex space-x-1 py-5 font-bold">
<div class="title">{$t('application.application')}</div>