feat: Be able to redeploy PRs

This commit is contained in:
Andras Bacsai
2022-03-23 11:49:40 +01:00
parent a8c5551292
commit 4e8fe79e2b
3 changed files with 38 additions and 2 deletions

View File

@@ -11,6 +11,7 @@ export const post: RequestHandler = async (event) => {
if (status === 401) return { status, body }; if (status === 401) return { status, body };
const { id } = event.params; const { id } = event.params;
const { pullmergeRequestId = null, branch } = await event.request.json();
try { try {
const buildId = cuid(); const buildId = cuid();
const applicationFound = await db.getApplication({ id, teamId }); const applicationFound = await db.getApplication({ id, teamId });
@@ -42,7 +43,17 @@ export const post: RequestHandler = async (event) => {
type: 'manual' type: 'manual'
} }
}); });
if (pullmergeRequestId) {
await buildQueue.add(buildId, {
build_id: buildId,
type: 'manual',
...applicationFound,
sourceBranch: branch,
pullmergeRequestId
});
} else {
await buildQueue.add(buildId, { build_id: buildId, type: 'manual', ...applicationFound }); await buildQueue.add(buildId, { build_id: buildId, type: 'manual', ...applicationFound });
}
return { return {
status: 200, status: 200,
body: { body: {

View File

@@ -26,15 +26,28 @@
export let applicationSecrets; export let applicationSecrets;
import { getDomain } from '$lib/components/common'; import { getDomain } from '$lib/components/common';
import Secret from '../secrets/_Secret.svelte'; import Secret from '../secrets/_Secret.svelte';
import { get } from '$lib/api'; import { get, post } from '$lib/api';
import { page } from '$app/stores'; import { page } from '$app/stores';
import Explainer from '$lib/components/Explainer.svelte'; import Explainer from '$lib/components/Explainer.svelte';
import { errorNotification } from '$lib/form';
import { toast } from '@zerodevx/svelte-toast';
const { id } = $page.params; const { id } = $page.params;
async function refreshSecrets() { async function refreshSecrets() {
const data = await get(`/applications/${id}/secrets.json`); const data = await get(`/applications/${id}/secrets.json`);
PRMRSecrets = [...data.secrets]; PRMRSecrets = [...data.secrets];
} }
async function redeploy(container) {
try {
await post(`/applications/${id}/deploy.json`, {
pullmergeRequestId: container.pullmergeRequestId,
branch: container.branch
});
toast.push('Application redeployed queued.');
} catch ({ error }) {
return errorNotification(error);
}
}
</script> </script>
<div class="flex space-x-1 p-6 font-bold"> <div class="flex space-x-1 p-6 font-bold">
@@ -90,6 +103,11 @@
<div class="truncate text-center text-xl font-bold">{getDomain(container.fqdn)}</div> <div class="truncate text-center text-xl font-bold">{getDomain(container.fqdn)}</div>
</div> </div>
</a> </a>
<div class="flex items-center justify-center">
<button class="bg-coollabs hover:bg-coollabs-100" on:click={() => redeploy(container)}
>Redeploy</button
>
</div>
{/each} {/each}
{:else} {:else}
<div class="flex-col"> <div class="flex-col">

View File

@@ -27,6 +27,7 @@
import { page } from '$app/stores'; import { page } from '$app/stores';
import Storage from './_Storage.svelte'; import Storage from './_Storage.svelte';
import { get } from '$lib/api'; import { get } from '$lib/api';
import Explainer from '$lib/components/Explainer.svelte';
const { id } = $page.params; const { id } = $page.params;
async function refreshStorage() { async function refreshStorage() {
@@ -44,6 +45,12 @@
</div> </div>
<div class="mx-auto max-w-6xl rounded-xl px-6 pt-4"> <div class="mx-auto max-w-6xl rounded-xl px-6 pt-4">
<div class="flex justify-center py-4 text-center">
<Explainer
customClass="w-full"
text={'You can specify any folder that you want to be persistent across deployments. <br>This is useful for storing data such as a database (SQLite) or a cache.'}
/>
</div>
<table class="mx-auto border-separate text-left"> <table class="mx-auto border-separate text-left">
<thead> <thead>
<tr class="h-12"> <tr class="h-12">