fix: build logs

This commit is contained in:
Andras Bacsai 2022-09-16 09:06:45 +02:00
parent 41e221f0cb
commit cb05fd4a3c
4 changed files with 11 additions and 32 deletions

View File

@ -13,7 +13,7 @@ import { checkDomainsIsValidInDNS, checkDoubleBranch, checkExposedPort, createDi
import { checkContainer, formatLabelsOnDocker, isContainerExited, removeContainer } from '../../../../lib/docker'; import { checkContainer, formatLabelsOnDocker, isContainerExited, removeContainer } from '../../../../lib/docker';
import type { FastifyRequest } from 'fastify'; import type { FastifyRequest } from 'fastify';
import type { GetImages, CancelDeployment, CheckDNS, CheckRepository, DeleteApplication, DeleteSecret, DeleteStorage, GetApplicationLogs, GetBuildIdLogs, GetBuildLogs, SaveApplication, SaveApplicationSettings, SaveApplicationSource, SaveDeployKey, SaveDestination, SaveSecret, SaveStorage, DeployApplication, CheckDomain, StopPreviewApplication, RestartPreviewApplication } from './types'; import type { GetImages, CancelDeployment, CheckDNS, CheckRepository, DeleteApplication, DeleteSecret, DeleteStorage, GetApplicationLogs, GetBuildIdLogs, SaveApplication, SaveApplicationSettings, SaveApplicationSource, SaveDeployKey, SaveDestination, SaveSecret, SaveStorage, DeployApplication, CheckDomain, StopPreviewApplication, RestartPreviewApplication, GetBuilds } from './types';
import { OnlyId } from '../../../../types'; import { OnlyId } from '../../../../types';
import path from 'node:path'; import path from 'node:path';
@ -1147,7 +1147,7 @@ export async function getApplicationLogs(request: FastifyRequest<GetApplicationL
return errorHandler({ status, message }) return errorHandler({ status, message })
} }
} }
export async function getBuildLogs(request: FastifyRequest<GetBuildLogs>) { export async function getBuilds(request: FastifyRequest<GetBuilds>) {
try { try {
const { id } = request.params const { id } = request.params
let { buildId, skip = 0 } = request.query let { buildId, skip = 0 } = request.query
@ -1164,8 +1164,7 @@ export async function getBuildLogs(request: FastifyRequest<GetBuildLogs>) {
builds = await prisma.build.findMany({ builds = await prisma.build.findMany({
where: { applicationId: id }, where: { applicationId: id },
orderBy: { createdAt: 'desc' }, orderBy: { createdAt: 'desc' },
take: 5, take: 5 + skip
skip
}); });
} }
builds = builds.map((build) => { builds = builds.map((build) => {

View File

@ -1,8 +1,8 @@
import { FastifyPluginAsync } from 'fastify'; import { FastifyPluginAsync } from 'fastify';
import { OnlyId } from '../../../../types'; import { OnlyId } from '../../../../types';
import { cancelDeployment, checkDNS, checkDomain, checkRepository, deleteApplication, deleteSecret, deleteStorage, deployApplication, getApplication, getApplicationLogs, getApplicationStatus, getBuildIdLogs, getBuildLogs, getBuildPack, getGitHubToken, getGitLabSSHKey, getImages, getPreviews, getPreviewStatus, getSecrets, getStorages, getUsage, listApplications, loadPreviews, newApplication, restartApplication, restartPreview, saveApplication, saveApplicationSettings, saveApplicationSource, saveBuildPack, saveConnectedDatabase, saveDeployKey, saveDestination, saveGitLabSSHKey, saveRepository, saveSecret, saveStorage, stopApplication, stopPreviewApplication } from './handlers'; import { cancelDeployment, checkDNS, checkDomain, checkRepository, deleteApplication, deleteSecret, deleteStorage, deployApplication, getApplication, getApplicationLogs, getApplicationStatus, getBuildIdLogs, getBuildPack, getBuilds, getGitHubToken, getGitLabSSHKey, getImages, getPreviews, getPreviewStatus, getSecrets, getStorages, getUsage, listApplications, loadPreviews, newApplication, restartApplication, restartPreview, saveApplication, saveApplicationSettings, saveApplicationSource, saveBuildPack, saveConnectedDatabase, saveDeployKey, saveDestination, saveGitLabSSHKey, saveRepository, saveSecret, saveStorage, stopApplication, stopPreviewApplication } from './handlers';
import type { CancelDeployment, CheckDNS, CheckDomain, CheckRepository, DeleteApplication, DeleteSecret, DeleteStorage, DeployApplication, GetApplicationLogs, GetBuildIdLogs, GetBuildLogs, GetImages, RestartPreviewApplication, SaveApplication, SaveApplicationSettings, SaveApplicationSource, SaveDeployKey, SaveDestination, SaveSecret, SaveStorage, StopPreviewApplication } from './types'; import type { CancelDeployment, CheckDNS, CheckDomain, CheckRepository, DeleteApplication, DeleteSecret, DeleteStorage, DeployApplication, GetApplicationLogs, GetBuildIdLogs, GetBuilds, GetImages, RestartPreviewApplication, SaveApplication, SaveApplicationSettings, SaveApplicationSource, SaveDeployKey, SaveDestination, SaveSecret, SaveStorage, StopPreviewApplication } from './types';
const root: FastifyPluginAsync = async (fastify): Promise<void> => { const root: FastifyPluginAsync = async (fastify): Promise<void> => {
fastify.addHook('onRequest', async (request) => { fastify.addHook('onRequest', async (request) => {
@ -42,7 +42,7 @@ const root: FastifyPluginAsync = async (fastify): Promise<void> => {
fastify.post<RestartPreviewApplication>('/:id/previews/:pullmergeRequestId/restart', async (request, reply) => await restartPreview(request, reply)); fastify.post<RestartPreviewApplication>('/:id/previews/:pullmergeRequestId/restart', async (request, reply) => await restartPreview(request, reply));
fastify.get<GetApplicationLogs>('/:id/logs', async (request) => await getApplicationLogs(request)); fastify.get<GetApplicationLogs>('/:id/logs', async (request) => await getApplicationLogs(request));
fastify.get<GetBuildLogs>('/:id/logs/build', async (request) => await getBuildLogs(request)); fastify.get<GetBuilds>('/:id/logs/build', async (request) => await getBuilds(request));
fastify.get<GetBuildIdLogs>('/:id/logs/build/:buildId', async (request) => await getBuildIdLogs(request)); fastify.get<GetBuildIdLogs>('/:id/logs/build/:buildId', async (request) => await getBuildIdLogs(request));
fastify.get('/:id/usage', async (request) => await getUsage(request)) fastify.get('/:id/usage', async (request) => await getUsage(request))

View File

@ -89,7 +89,7 @@ export interface GetApplicationLogs extends OnlyId {
since: number, since: number,
} }
} }
export interface GetBuildLogs extends OnlyId { export interface GetBuilds extends OnlyId {
Querystring: { Querystring: {
buildId: string buildId: string
skip: number, skip: number,

View File

@ -54,34 +54,14 @@
const response = await get(`/applications/${$page.params.id}/logs/build?skip=${skip}`); const response = await get(`/applications/${$page.params.id}/logs/build?skip=${skip}`);
builds = response.builds; builds = response.builds;
} }
// async function updateBuildStatus({ detail }: { detail: any }) {
// const { status } = detail;
// if (status !== 'running') {
// try {
// const data = await get(`/applications/${id}/logs/build?buildId=${buildId}`);
// builds = builds.filter((build: any) => {
// if (build.id === data.builds[0].id) {
// build.status = data.builds[0].status;
// }
// return build;
// });
// } catch (error) {
// return errorNotification(error);
// }
// } else {
// builds = builds.filter((build: any) => {
// if (build.id === buildId) build.status = status;
// return build;
// });
// }
// }
async function loadMoreBuilds() { async function loadMoreBuilds() {
if (buildCount >= skip) { if (buildCount >= skip) {
skip = skip + 5; skip = skip + 5;
noMoreBuilds = buildCount >= skip; noMoreBuilds = buildCount <= skip;
try { try {
const data = await get(`/applications/${id}/logs/build?skip=${skip}`); const data = await get(`/applications/${id}/logs/build?skip=${skip}`);
builds = builds.concat(data.builds); builds = data.builds
return; return;
} catch (error) { } catch (error) {
return errorNotification(error); return errorNotification(error);
@ -235,7 +215,7 @@
</div> </div>
{#if !noMoreBuilds} {#if !noMoreBuilds}
{#if buildCount > 5} {#if buildCount > 5}
<div class="flex space-x-2"> <div class="flex space-x-2 pb-10">
<button <button
disabled={noMoreBuilds} disabled={noMoreBuilds}
class=" btn btn-sm w-full text-xs" class=" btn btn-sm w-full text-xs"