v1.0.23 (#68)
# Features - Build environment variables for NodeJS builds - Initial monorepo support (more tests needed!) # Fixes - Fix wrong redirects - Logout fix for the session manager
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
import { setDefaultConfiguration } from '$lib/api/applications/configuration';
|
||||
import { saveServerLog } from '$lib/api/applications/logging';
|
||||
import { docker } from '$lib/api/docker';
|
||||
import Configuration from '$models/Configuration';
|
||||
import type { Request } from '@sveltejs/kit';
|
||||
|
||||
@@ -8,16 +7,16 @@ export async function post(request: Request) {
|
||||
try {
|
||||
const { DOMAIN } = process.env;
|
||||
const configuration = setDefaultConfiguration(request.body);
|
||||
const configurationFound = await Configuration.find({
|
||||
'repository.id': { $ne: configuration.repository.id },
|
||||
const sameDomainAndPath = await Configuration.find({
|
||||
'publish.path': configuration.publish.path,
|
||||
'publish.domain': configuration.publish.domain
|
||||
}).select('-_id -__v -createdAt -updatedAt');
|
||||
if (configurationFound.length > 0 || configuration.publish.domain === DOMAIN) {
|
||||
if (sameDomainAndPath.length > 1 || configuration.publish.domain === DOMAIN) {
|
||||
return {
|
||||
status: 200,
|
||||
body: {
|
||||
success: false,
|
||||
message: 'Domain already in use.'
|
||||
message: 'Domain/path are already in use.'
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -3,14 +3,11 @@ import Configuration from '$models/Configuration';
|
||||
import type { Request } from '@sveltejs/kit';
|
||||
|
||||
export async function post(request: Request) {
|
||||
const { name, organization, branch }: any = request.body || {};
|
||||
if (name && organization && branch) {
|
||||
const { nickname }: any = request.body || {};
|
||||
if (nickname) {
|
||||
const configurationFound = await Configuration.find({
|
||||
'repository.name': name,
|
||||
'repository.organization': organization,
|
||||
'repository.branch': branch
|
||||
'general.nickname': nickname
|
||||
}).select('-_id -__v -createdAt -updatedAt');
|
||||
|
||||
if (configurationFound) {
|
||||
return {
|
||||
status: 200,
|
||||
@@ -28,22 +25,8 @@ export async function post(request: Request) {
|
||||
const configuration = r.Spec.Labels.configuration
|
||||
? JSON.parse(r.Spec.Labels.configuration)
|
||||
: null;
|
||||
if (branch) {
|
||||
if (
|
||||
configuration.repository.name === name &&
|
||||
configuration.repository.organization === organization &&
|
||||
configuration.repository.branch === branch
|
||||
) {
|
||||
return r;
|
||||
}
|
||||
} else {
|
||||
if (
|
||||
configuration.repository.name === name &&
|
||||
configuration.repository.organization === organization
|
||||
) {
|
||||
return r;
|
||||
}
|
||||
}
|
||||
|
||||
if (configuration.general.nickname === nickname) return r;
|
||||
return null;
|
||||
});
|
||||
|
||||
|
||||
@@ -5,6 +5,8 @@ import cloneRepository from '$lib/api/applications/cloneRepository';
|
||||
import { cleanupTmp } from '$lib/api/common';
|
||||
import queueAndBuild from '$lib/api/applications/queueAndBuild';
|
||||
import Configuration from '$models/Configuration';
|
||||
import preChecks from '$lib/api/applications/preChecks';
|
||||
import preTasks from '$lib/api/applications/preTasks';
|
||||
|
||||
export async function post(request: Request) {
|
||||
const configuration = setDefaultConfiguration(request.body);
|
||||
@@ -18,10 +20,8 @@ export async function post(request: Request) {
|
||||
}
|
||||
try {
|
||||
await cloneRepository(configuration);
|
||||
const { foundService, imageChanged, configChanged, forceUpdate } = await precheckDeployment(
|
||||
configuration
|
||||
);
|
||||
if (foundService && !forceUpdate && !imageChanged && !configChanged) {
|
||||
const nextStep = await preChecks(configuration);
|
||||
if (nextStep === 0) {
|
||||
cleanupTmp(configuration.general.workdir);
|
||||
return {
|
||||
status: 200,
|
||||
@@ -31,50 +31,9 @@ export async function post(request: Request) {
|
||||
}
|
||||
};
|
||||
}
|
||||
const alreadyQueued = await Deployment.find({
|
||||
repoId: configuration.repository.id,
|
||||
branch: configuration.repository.branch,
|
||||
organization: configuration.repository.organization,
|
||||
name: configuration.repository.name,
|
||||
domain: configuration.publish.domain,
|
||||
progress: { $in: ['queued', 'inprogress'] }
|
||||
});
|
||||
if (alreadyQueued.length > 0) {
|
||||
return {
|
||||
status: 200,
|
||||
body: {
|
||||
success: false,
|
||||
message: 'Already in the queue.'
|
||||
}
|
||||
};
|
||||
}
|
||||
const { id, organization, name, branch } = configuration.repository;
|
||||
const { domain } = configuration.publish;
|
||||
const { deployId, nickname, pullRequest } = configuration.general;
|
||||
await preTasks(configuration)
|
||||
|
||||
await new Deployment({
|
||||
repoId: id,
|
||||
branch,
|
||||
deployId,
|
||||
domain,
|
||||
organization,
|
||||
name,
|
||||
nickname
|
||||
}).save();
|
||||
|
||||
await Configuration.findOneAndUpdate(
|
||||
{
|
||||
'repository.id': id,
|
||||
'repository.organization': organization,
|
||||
'repository.name': name,
|
||||
'repository.branch': branch,
|
||||
'general.pullRequest': { $in: [null, 0] }
|
||||
},
|
||||
{ ...configuration },
|
||||
{ upsert: true, new: true }
|
||||
);
|
||||
|
||||
queueAndBuild(configuration, imageChanged);
|
||||
queueAndBuild(configuration, nextStep);
|
||||
return {
|
||||
status: 201,
|
||||
body: {
|
||||
@@ -86,23 +45,7 @@ export async function post(request: Request) {
|
||||
};
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
await Deployment.findOneAndUpdate(
|
||||
{
|
||||
repoId: configuration.repository.id,
|
||||
branch: configuration.repository.branch,
|
||||
organization: configuration.repository.organization,
|
||||
name: configuration.repository.name,
|
||||
domain: configuration.publish.domain
|
||||
},
|
||||
{
|
||||
repoId: configuration.repository.id,
|
||||
branch: configuration.repository.branch,
|
||||
organization: configuration.repository.organization,
|
||||
name: configuration.repository.name,
|
||||
domain: configuration.publish.domain,
|
||||
progress: 'failed'
|
||||
}
|
||||
);
|
||||
await Deployment.findOneAndUpdate({ nickname: configuration.general.nickname }, { $set: { progress: 'failed' } });
|
||||
return {
|
||||
status: 500,
|
||||
body: {
|
||||
|
||||
@@ -4,63 +4,47 @@ import ApplicationLog from '$models/ApplicationLog';
|
||||
import { delay, execShellAsync } from '$lib/api/common';
|
||||
import Configuration from '$models/Configuration';
|
||||
|
||||
async function purgeImagesAsync(found) {
|
||||
await delay(10000);
|
||||
await purgeImagesContainers(found, true);
|
||||
}
|
||||
export async function post(request: Request) {
|
||||
const { organization, name, branch, domain } = request.body;
|
||||
const { nickname } = request.body;
|
||||
try {
|
||||
const configurationFound = await Configuration.findOne({
|
||||
'repository.organization': organization,
|
||||
'repository.name': name,
|
||||
'repository.branch': branch,
|
||||
'publish.domain': domain
|
||||
'general.nickname': nickname
|
||||
});
|
||||
if (configurationFound) {
|
||||
const id = configurationFound._id;
|
||||
if (configurationFound?.general?.pullRequest === 0) {
|
||||
// Main deployment deletion request; deleting main + PRs
|
||||
const allConfiguration = await Configuration.find({
|
||||
'repository.name': name,
|
||||
'repository.organization': organization,
|
||||
'repository.branch': branch
|
||||
'publish.domain': { $regex: `.*${configurationFound.publish.domain}`, $options: 'i' },
|
||||
'publish.path': configurationFound.publish.path
|
||||
});
|
||||
for (const config of allConfiguration) {
|
||||
await Configuration.findOneAndRemove({
|
||||
'repository.name': config.repository.name,
|
||||
'repository.organization': config.repository.organization,
|
||||
'repository.branch': config.repository.branch
|
||||
});
|
||||
await execShellAsync(`docker stack rm ${config.build.container.name}`);
|
||||
}
|
||||
const deploys = await Deployment.find({ organization, branch, name });
|
||||
await Configuration.deleteMany({
|
||||
'publish.domain': { $regex: `.*${configurationFound.publish.domain}`, $options: 'i' },
|
||||
'publish.path': configurationFound.publish.path
|
||||
});
|
||||
const deploys = await Deployment.find({ nickname });
|
||||
for (const deploy of deploys) {
|
||||
await ApplicationLog.deleteMany({ deployId: deploy.deployId });
|
||||
await Deployment.deleteMany({ deployId: deploy.deployId });
|
||||
}
|
||||
|
||||
purgeImagesAsync(configurationFound);
|
||||
} else {
|
||||
// Delete only PRs
|
||||
await Configuration.findByIdAndRemove(id);
|
||||
await execShellAsync(`docker stack rm ${configurationFound.build.container.name}`);
|
||||
const deploys = await Deployment.find({ organization, branch, name, domain });
|
||||
const deploys = await Deployment.find({ nickname });
|
||||
for (const deploy of deploys) {
|
||||
await ApplicationLog.deleteMany({ deployId: deploy.deployId });
|
||||
await Deployment.deleteMany({ deployId: deploy.deployId });
|
||||
}
|
||||
purgeImagesAsync(configurationFound);
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
status: 200,
|
||||
body: {
|
||||
organization,
|
||||
name,
|
||||
branch
|
||||
}
|
||||
body: {}
|
||||
};
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
@@ -1,7 +1,6 @@
|
||||
import type { Request } from '@sveltejs/kit';
|
||||
export async function del(request: Request) {
|
||||
request.locals.session.destroy = true;
|
||||
|
||||
request.locals.session.destroy()
|
||||
return {
|
||||
body: {
|
||||
ok: true
|
||||
|
||||
@@ -10,8 +10,6 @@ export async function post(request: Request) {
|
||||
let { baseURL, remoteDB, database, wordpressExtraConfiguration } = request.body;
|
||||
const traefikURL = baseURL;
|
||||
baseURL = `https://${baseURL}`;
|
||||
console.log({ baseURL, remoteDB, database, wordpressExtraConfiguration });
|
||||
|
||||
const workdir = '/tmp/wordpress';
|
||||
const deployId = `wp-${generator.generate({ length: 5, numbers: true, strict: true })}`;
|
||||
const defaultDatabaseName = generator.generate({ length: 12, numbers: true, strict: true });
|
||||
|
||||
@@ -39,6 +39,7 @@ export async function post(request: Request) {
|
||||
};
|
||||
}
|
||||
|
||||
// TODO: Monorepo support here. Find all configurations by id and update all deployments! Tough!
|
||||
try {
|
||||
const applications = await Configuration.find({
|
||||
'repository.id': request.body.repository.id
|
||||
|
||||
@@ -3,18 +3,20 @@
|
||||
* @type {import('@sveltejs/kit').Load}
|
||||
*/
|
||||
export async function load(session) {
|
||||
if (!browser && !process.env.VITE_GITHUB_APP_CLIENTID) {
|
||||
return {
|
||||
status: 302,
|
||||
redirect: '/dashboard/services'
|
||||
};
|
||||
if (!browser) {
|
||||
if (!import.meta.env.VITE_GITHUB_APP_CLIENTID) {
|
||||
return {
|
||||
status: 302,
|
||||
redirect: '/dashboard/services'
|
||||
};
|
||||
}
|
||||
}
|
||||
return {};
|
||||
}
|
||||
</script>
|
||||
|
||||
<script>
|
||||
import { application, initialApplication, initConf, dashboard, prApplication } from '$store';
|
||||
import { application, initialApplication, initConf, dashboard, prApplication, originalDomain } from '$store';
|
||||
import { onDestroy } from 'svelte';
|
||||
import Loading from '$components/Loading.svelte';
|
||||
import Navbar from '$components/Application/Navbar.svelte';
|
||||
@@ -23,17 +25,12 @@
|
||||
import { browser } from '$app/env';
|
||||
import { request } from '$lib/request';
|
||||
|
||||
$application.repository.organization = $page.params.organization;
|
||||
$application.repository.name = $page.params.name;
|
||||
$application.repository.branch = $page.params.branch;
|
||||
|
||||
$application.general.nickname = $page.params.nickname;
|
||||
async function setConfiguration() {
|
||||
try {
|
||||
const { configuration } = await request(`/api/v1/application/config`, $session, {
|
||||
body: {
|
||||
name: $application.repository.name,
|
||||
organization: $application.repository.organization,
|
||||
branch: $application.repository.branch
|
||||
nickname: $application.general.nickname
|
||||
}
|
||||
});
|
||||
$prApplication = configuration.filter((c) => c.general.pullRequest !== 0);
|
||||
@@ -49,12 +46,8 @@
|
||||
await setConfiguration();
|
||||
} else {
|
||||
const found = $dashboard.applications.deployed.find((app) => {
|
||||
const { organization, name, branch } = app.configuration.repository;
|
||||
if (
|
||||
organization === $application.repository.organization &&
|
||||
name === $application.repository.name &&
|
||||
branch === $application.repository.branch
|
||||
) {
|
||||
const { domain } = app.configuration.publish;
|
||||
if (domain === $application.publish.domain) {
|
||||
return app;
|
||||
}
|
||||
});
|
||||
@@ -65,6 +58,8 @@
|
||||
await setConfiguration();
|
||||
}
|
||||
}
|
||||
$originalDomain = $application.publish.domain
|
||||
|
||||
} else {
|
||||
$application = JSON.parse(JSON.stringify(initialApplication));
|
||||
}
|
||||
|
||||
@@ -4,11 +4,13 @@
|
||||
* @type {import('@sveltejs/kit').Load}
|
||||
*/
|
||||
export async function load(session) {
|
||||
if (!browser && !process.env.VITE_GITHUB_APP_CLIENTID) {
|
||||
return {
|
||||
status: 302,
|
||||
redirect: '/dashboard/services'
|
||||
};
|
||||
if (!browser) {
|
||||
if (!import.meta.env.VITE_GITHUB_APP_CLIENTID) {
|
||||
return {
|
||||
status: 302,
|
||||
redirect: '/dashboard/services'
|
||||
};
|
||||
}
|
||||
}
|
||||
return {
|
||||
props: {
|
||||
@@ -23,6 +25,7 @@
|
||||
import { dashboard, dateOptions, settings } from '$store';
|
||||
import { fade } from 'svelte/transition';
|
||||
import { browser } from '$app/env';
|
||||
import { dashify } from '$lib/common';
|
||||
</script>
|
||||
|
||||
<div
|
||||
@@ -59,9 +62,7 @@
|
||||
<div
|
||||
class="relative rounded-xl p-6 bg-warmGray-800 border-2 border-dashed border-transparent hover:border-green-500 text-white shadow-md cursor-pointer ease-in-out hover:scale-105 duration-100 group"
|
||||
on:click={() => {
|
||||
goto(
|
||||
`/application/${application.configuration.repository.organization}/${application.configuration.repository.name}/${application.configuration.repository.branch}/configuration`
|
||||
);
|
||||
goto(`/application/${application.configuration.general.nickname}/configuration`);
|
||||
}}
|
||||
>
|
||||
<div class="flex items-center">
|
||||
|
||||
Reference in New Issue
Block a user