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

View File

@ -641,9 +641,9 @@ export async function buildImage({
commit commit
}) { }) {
if (isCache) { if (isCache) {
await saveBuildLog({ line: `Building cache image started.`, buildId, applicationId }); await saveBuildLog({ line: `[CACHE] Building cache image.`, buildId, applicationId });
} else { } else {
await saveBuildLog({ line: `Building image started.`, buildId, applicationId }); await saveBuildLog({ line: `[PRODUCTION] Building production image.`, buildId, applicationId });
} }
if (!debug) { if (!debug) {
await saveBuildLog({ await saveBuildLog({
@ -667,12 +667,12 @@ export async function buildImage({
const { status } = await prisma.build.findUnique({ where: { id: buildId } }) const { status } = await prisma.build.findUnique({ where: { id: buildId } })
if (status === 'canceled') { if (status === 'canceled') {
throw new Error('Deployment canceled.') throw new Error('[DEPLOYMENT] Canceled!!!')
} }
if (isCache) { if (isCache) {
await saveBuildLog({ line: `Building cache image successful.`, buildId, applicationId }); await saveBuildLog({ line: `[CACHE] Successful! 🎉`, buildId, applicationId });
} else { } 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'); scheduler.workers.get('deployApplication').postMessage('cancel');
} }
await cleanupDB(buildId, applicationId); await cleanupDB(buildId, applicationId);
return reject(new Error('Deployment canceled.')); return reject(new Error('[DEPLOYMENT] Canceled!!!'));
} }
const { stdout: buildContainers } = await executeDockerCmd({ const { stdout: buildContainers } = await executeDockerCmd({
dockerId, dockerId,
@ -1568,7 +1568,7 @@ async function cleanupDB(buildId: string, applicationId: string) {
if (data?.status === 'queued' || data?.status === 'running') { if (data?.status === 'queued' || data?.status === 'running') {
await prisma.build.update({ where: { id: buildId }, data: { status: 'canceled' } }); 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) { export function convertTolOldVolumeNames(type) {

View File

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

View File

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

View File

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

View File

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

View File

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