feat: save application data before deploying

This commit is contained in:
Andras Bacsai 2022-11-30 15:40:27 +01:00
parent 9913e7b70b
commit 76373a8597
9 changed files with 41 additions and 31 deletions

View File

@ -301,8 +301,7 @@ import * as buildpacks from '../lib/buildPacks';
}
try {
await executeDockerCmd({ debug, buildId, applicationId, dockerId: destinationDocker.id, command: `docker compose --project-directory ${workdir} up -d` })
await saveBuildLog({ line: 'Deployment successful!', buildId, applicationId });
await saveBuildLog({ line: 'Proxy will be updated shortly.', buildId, applicationId });
await saveBuildLog({ line: '[DEPLOYMENT] Successful! 🎉', buildId, applicationId });
await prisma.build.update({ where: { id: buildId }, data: { status: 'success' } });
await prisma.application.update({
where: { id: applicationId },
@ -363,7 +362,7 @@ import * as buildpacks from '../lib/buildPacks';
//
}
try {
await saveBuildLog({ line: 'Deployment started.', buildId, applicationId });
await saveBuildLog({ line: '[DEPLOYMENT] Deployment initiated.', buildId, applicationId });
const composeVolumes = volumes.map((volume) => {
return {
[`${volume.split(':')[0]}`]: {
@ -395,7 +394,7 @@ import * as buildpacks from '../lib/buildPacks';
};
await fs.writeFile(`${workdir}/docker-compose.yml`, yaml.dump(composeFile));
await executeDockerCmd({ dockerId: destinationDocker.id, command: `docker compose --project-directory ${workdir} up -d` })
await saveBuildLog({ line: 'Deployment successful!', buildId, applicationId });
await saveBuildLog({ line: '[DEPLOYMENT] Successful! 🎉', buildId, applicationId });
} catch (error) {
await saveBuildLog({ line: error, buildId, applicationId });
const foundBuild = await prisma.build.findUnique({ where: { id: buildId } })
@ -409,7 +408,6 @@ import * as buildpacks from '../lib/buildPacks';
}
throw new Error(error);
}
await saveBuildLog({ line: 'Proxy will be updated shortly.', buildId, applicationId });
await prisma.build.update({ where: { id: buildId }, data: { status: 'success' } });
if (!pullmergeRequestId) await prisma.application.update({
where: { id: applicationId },

View File

@ -641,9 +641,9 @@ export async function buildImage({
commit
}) {
if (isCache) {
await saveBuildLog({ line: `Building cache image started.`, buildId, applicationId });
await saveBuildLog({ line: `[CACHE] Building cache image.`, buildId, applicationId });
} else {
await saveBuildLog({ line: `Building image started.`, buildId, applicationId });
await saveBuildLog({ line: `[PRODUCTION] Building production image.`, buildId, applicationId });
}
if (!debug) {
await saveBuildLog({
@ -667,12 +667,12 @@ export async function buildImage({
const { status } = await prisma.build.findUnique({ where: { id: buildId } })
if (status === 'canceled') {
throw new Error('Deployment canceled.')
throw new Error('[DEPLOYMENT] Canceled!!!')
}
if (isCache) {
await saveBuildLog({ line: `Building cache image successful.`, buildId, applicationId });
await saveBuildLog({ line: `[CACHE] Successful! 🎉`, buildId, applicationId });
} else {
await saveBuildLog({ line: `Building image successful.`, buildId, applicationId });
await saveBuildLog({ line: `[PRODUCTION] Successful! 🎉`, buildId, applicationId });
}
}

View File

@ -1535,7 +1535,7 @@ export async function stopBuild(buildId, applicationId) {
scheduler.workers.get('deployApplication').postMessage('cancel');
}
await cleanupDB(buildId, applicationId);
return reject(new Error('Deployment canceled.'));
return reject(new Error('[DEPLOYMENT] Canceled!!!'));
}
const { stdout: buildContainers } = await executeDockerCmd({
dockerId,
@ -1568,7 +1568,7 @@ async function cleanupDB(buildId: string, applicationId: string) {
if (data?.status === 'queued' || data?.status === 'running') {
await prisma.build.update({ where: { id: buildId }, data: { status: 'canceled' } });
}
await saveBuildLog({ line: 'Deployment canceled.', buildId, applicationId });
await saveBuildLog({ line: '[DEPLOYMENT] Canceled!!!', buildId, applicationId });
}
export function convertTolOldVolumeNames(type) {

View File

@ -30,16 +30,16 @@ export default async function ({
}): Promise<string> {
const { default: got } = await import('got')
const url = htmlUrl.replace('https://', '').replace('http://', '');
await saveBuildLog({ line: 'GitHub importer started.', buildId, applicationId });
await saveBuildLog({ line: '[IMPORTER] Warming up GitHub importer.', buildId, applicationId });
if (forPublic) {
await saveBuildLog({
line: `Cloning ${repository}:${branch} branch.`,
line: `[IMPORTER] Cloning ${repository}:${branch} branch.`,
buildId,
applicationId
});
if (gitCommitHash) {
await saveBuildLog({
line: `Checking out ${gitCommitHash} commit.`,
line: `[IMPORTER] Checking out ${gitCommitHash} commit.`,
buildId,
applicationId
});
@ -71,13 +71,13 @@ export default async function ({
})
.json();
await saveBuildLog({
line: `Cloning ${repository}:${branch} branch.`,
line: `[IMPORTER] Cloning ${repository}:${branch} branch.`,
buildId,
applicationId
});
if (gitCommitHash) {
await saveBuildLog({
line: `Checking out ${gitCommitHash} commit.`,
line: `[IMPORTER] Checking out ${gitCommitHash} commit.`,
buildId,
applicationId
});

View File

@ -27,7 +27,7 @@ export default async function ({
forPublic: boolean;
}): Promise<string> {
const url = htmlUrl.replace('https://', '').replace('http://', '').replace(/\/$/, '');
await saveBuildLog({ line: 'GitLab importer started.', buildId, applicationId });
await saveBuildLog({ line: '[IMPORTER] Warming up GitLab importer.', buildId, applicationId });
if (!forPublic) {
await asyncExecShell(`echo '${privateSshKey}' > ${repodir}/id.rsa`);
@ -35,13 +35,13 @@ export default async function ({
}
await saveBuildLog({
line: `Cloning ${repository}:${branch} branch.`,
line: `[IMPORTER] Cloning ${repository}:${branch} branch.`,
buildId,
applicationId
});
if (gitCommitHash) {
await saveBuildLog({
line: `Checking out ${gitCommitHash} commit.`,
line: `[IMPORTER] Checking out ${gitCommitHash} commit.`,
buildId,
applicationId
});

View File

@ -70,8 +70,8 @@
selectedBuildId
} from '$lib/store';
import { errorNotification, handlerNotFoundLoad } from '$lib/common';
import Tooltip from '$lib/components/Tooltip.svelte';
import Menu from './_Menu.svelte';
import { saveForm } from './utils';
let statusInterval: any;
let forceDelete = false;
@ -114,6 +114,7 @@
}, 2000);
}
try {
await saveForm(id, application);
const { buildId } = await post(`/applications/${id}/deploy`, {
...application,
forceRebuild

View File

@ -50,6 +50,7 @@
import Explainer from '$lib/components/Explainer.svelte';
import { goto } from '$app/navigation';
import Beta from '$lib/components/Beta.svelte';
import { saveForm } from './utils';
const { id } = $page.params;
@ -267,11 +268,7 @@
}
}
}
await post(`/applications/${id}`, {
...application,
baseDatabaseBranch,
dockerComposeConfiguration: JSON.stringify(dockerComposeConfiguration)
});
await saveForm(id, application,baseDatabaseBranch, dockerComposeConfiguration);
setLocation(application, settings);
$isDeploymentEnabled = checkIfDeploymentEnabledApplications($appSession.isAdmin, application);
@ -519,6 +516,8 @@
<label for="repository">Git commit</label>
<div class="flex gap-2">
<input
id="commit"
name="commit"
class="w-full"
disabled={isDisabled}
placeholder="default: latest commit"

View File

@ -55,7 +55,7 @@
branch: preview.sourceBranch
});
addToast({
message: 'Deployment queued',
message: 'Deployment queued.',
type: 'success'
});
if ($page.url.pathname.startsWith(`/applications/${id}/logs/build`)) {
@ -183,9 +183,7 @@
<div class="flex justify-center py-4 text-center text-xl font-bold">Loading...</div>
</div>
{:else if application.previewApplication.length > 0}
<div
class="grid grid-col gap-4 auto-cols-max grid-cols-1 md:grid-cols-2 lg:grid-cols-2 px-6"
>
<div class="grid grid-col gap-4 auto-cols-max grid-cols-1 md:grid-cols-2 lg:grid-cols-2 px-6">
{#each application.previewApplication as preview}
<div class="no-underline mb-5 w-full">
<div class="w-full rounded p-5 bg-coolgray-200 indicator">
@ -216,7 +214,12 @@
<div class="flex justify-end items-end space-x-2 h-10">
{#if preview.customDomain}
<a id="openpreview" href={preview.customDomain} target="_blank noreferrer" class="icons">
<a
id="openpreview"
href={preview.customDomain}
target="_blank noreferrer"
class="icons"
>
<svg
xmlns="http://www.w3.org/2000/svg"
class="h-6 w-6"

View File

@ -0,0 +1,9 @@
import { post } from "$lib/api";
export async function saveForm(id: string, application: any, baseDatabaseBranch?: any, dockerComposeConfiguration?: any) {
return await post(`/applications/${id}`, {
...application,
baseDatabaseBranch,
dockerComposeConfiguration: JSON.stringify(dockerComposeConfiguration)
});
}