Merge branch 'next' into some-tweaks
This commit is contained in:
commit
e689be552b
@ -357,7 +357,9 @@ import * as buildpacks from '../lib/buildPacks';
|
|||||||
where: { id: buildId, status: { in: ['queued', 'running'] } },
|
where: { id: buildId, status: { in: ['queued', 'running'] } },
|
||||||
data: { status: 'failed' }
|
data: { status: 'failed' }
|
||||||
});
|
});
|
||||||
await saveBuildLog({ line: error, buildId, applicationId: application.id });
|
if (error !== 1) {
|
||||||
|
await saveBuildLog({ line: error, buildId, applicationId: application.id });
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -21,7 +21,7 @@ import { scheduler } from './scheduler';
|
|||||||
import { supportedServiceTypesAndVersions } from './services/supportedVersions';
|
import { supportedServiceTypesAndVersions } from './services/supportedVersions';
|
||||||
import { includeServices } from './services/common';
|
import { includeServices } from './services/common';
|
||||||
|
|
||||||
export const version = '3.10.2';
|
export const version = '3.10.3';
|
||||||
export const isDev = process.env.NODE_ENV === 'development';
|
export const isDev = process.env.NODE_ENV === 'development';
|
||||||
|
|
||||||
const algorithm = 'aes-256-ctr';
|
const algorithm = 'aes-256-ctr';
|
||||||
@ -96,7 +96,8 @@ export const asyncExecShellStream = async ({
|
|||||||
const array = stdout.split('\n');
|
const array = stdout.split('\n');
|
||||||
for (const line of array) {
|
for (const line of array) {
|
||||||
if (line !== '\n' && line !== '') {
|
if (line !== '\n' && line !== '') {
|
||||||
await saveBuildLog({
|
logs.push(line.replace('\n', ''))
|
||||||
|
debug && await saveBuildLog({
|
||||||
line: `${line.replace('\n', '')}`,
|
line: `${line.replace('\n', '')}`,
|
||||||
buildId,
|
buildId,
|
||||||
applicationId
|
applicationId
|
||||||
@ -109,7 +110,8 @@ export const asyncExecShellStream = async ({
|
|||||||
const array = stderr.split('\n');
|
const array = stderr.split('\n');
|
||||||
for (const line of array) {
|
for (const line of array) {
|
||||||
if (line !== '\n' && line !== '') {
|
if (line !== '\n' && line !== '') {
|
||||||
await saveBuildLog({
|
errorLogs.push(line.replace('\n', ''))
|
||||||
|
debug && await saveBuildLog({
|
||||||
line: `${line.replace('\n', '')}`,
|
line: `${line.replace('\n', '')}`,
|
||||||
buildId,
|
buildId,
|
||||||
applicationId
|
applicationId
|
||||||
|
@ -40,7 +40,7 @@ export default async function ({
|
|||||||
|
|
||||||
if (forPublic) {
|
if (forPublic) {
|
||||||
await asyncExecShell(
|
await asyncExecShell(
|
||||||
`git clone -q -b ${branch} git@${url}:${repository}.git --config core.sshCommand="ssh -p ${customPort} -q -o StrictHostKeyChecking=no" ${workdir}/ && cd ${workdir}/ && git submodule update --init --recursive && git lfs pull && cd .. `
|
`git clone -q -b ${branch} https://${url}/${repository}.git ${workdir}/ && cd ${workdir}/ && git submodule update --init --recursive && git lfs pull && cd .. `
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
await asyncExecShell(
|
await asyncExecShell(
|
||||||
|
@ -1006,78 +1006,135 @@ async function startUmamiService(request: FastifyRequest<ServiceStartStop>) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const initDbSQL = `
|
const initDbSQL = `
|
||||||
drop table if exists event;
|
-- CreateTable
|
||||||
drop table if exists pageview;
|
CREATE TABLE "account" (
|
||||||
drop table if exists session;
|
"user_id" SERIAL NOT NULL,
|
||||||
drop table if exists website;
|
"username" VARCHAR(255) NOT NULL,
|
||||||
drop table if exists account;
|
"password" VARCHAR(60) NOT NULL,
|
||||||
|
"is_admin" BOOLEAN NOT NULL DEFAULT false,
|
||||||
|
"created_at" TIMESTAMPTZ(6) DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
"updated_at" TIMESTAMPTZ(6) DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
|
||||||
create table account (
|
PRIMARY KEY ("user_id")
|
||||||
user_id serial primary key,
|
);
|
||||||
username varchar(255) unique not null,
|
|
||||||
password varchar(60) not null,
|
|
||||||
is_admin bool not null default false,
|
|
||||||
created_at timestamp with time zone default current_timestamp,
|
|
||||||
updated_at timestamp with time zone default current_timestamp
|
|
||||||
);
|
|
||||||
|
|
||||||
create table website (
|
-- CreateTable
|
||||||
website_id serial primary key,
|
CREATE TABLE "event" (
|
||||||
website_uuid uuid unique not null,
|
"event_id" SERIAL NOT NULL,
|
||||||
user_id int not null references account(user_id) on delete cascade,
|
"website_id" INTEGER NOT NULL,
|
||||||
name varchar(100) not null,
|
"session_id" INTEGER NOT NULL,
|
||||||
domain varchar(500),
|
"created_at" TIMESTAMPTZ(6) DEFAULT CURRENT_TIMESTAMP,
|
||||||
share_id varchar(64) unique,
|
"url" VARCHAR(500) NOT NULL,
|
||||||
created_at timestamp with time zone default current_timestamp
|
"event_type" VARCHAR(50) NOT NULL,
|
||||||
);
|
"event_value" VARCHAR(50) NOT NULL,
|
||||||
|
|
||||||
create table session (
|
PRIMARY KEY ("event_id")
|
||||||
session_id serial primary key,
|
);
|
||||||
session_uuid uuid unique not null,
|
|
||||||
website_id int not null references website(website_id) on delete cascade,
|
|
||||||
created_at timestamp with time zone default current_timestamp,
|
|
||||||
hostname varchar(100),
|
|
||||||
browser varchar(20),
|
|
||||||
os varchar(20),
|
|
||||||
device varchar(20),
|
|
||||||
screen varchar(11),
|
|
||||||
language varchar(35),
|
|
||||||
country char(2)
|
|
||||||
);
|
|
||||||
|
|
||||||
create table pageview (
|
-- CreateTable
|
||||||
view_id serial primary key,
|
CREATE TABLE "pageview" (
|
||||||
website_id int not null references website(website_id) on delete cascade,
|
"view_id" SERIAL NOT NULL,
|
||||||
session_id int not null references session(session_id) on delete cascade,
|
"website_id" INTEGER NOT NULL,
|
||||||
created_at timestamp with time zone default current_timestamp,
|
"session_id" INTEGER NOT NULL,
|
||||||
url varchar(500) not null,
|
"created_at" TIMESTAMPTZ(6) DEFAULT CURRENT_TIMESTAMP,
|
||||||
referrer varchar(500)
|
"url" VARCHAR(500) NOT NULL,
|
||||||
);
|
"referrer" VARCHAR(500),
|
||||||
|
|
||||||
create table event (
|
PRIMARY KEY ("view_id")
|
||||||
event_id serial primary key,
|
);
|
||||||
website_id int not null references website(website_id) on delete cascade,
|
|
||||||
session_id int not null references session(session_id) on delete cascade,
|
|
||||||
created_at timestamp with time zone default current_timestamp,
|
|
||||||
url varchar(500) not null,
|
|
||||||
event_type varchar(50) not null,
|
|
||||||
event_value varchar(50) not null
|
|
||||||
);
|
|
||||||
|
|
||||||
create index website_user_id_idx on website(user_id);
|
-- CreateTable
|
||||||
|
CREATE TABLE "session" (
|
||||||
|
"session_id" SERIAL NOT NULL,
|
||||||
|
"session_uuid" UUID NOT NULL,
|
||||||
|
"website_id" INTEGER NOT NULL,
|
||||||
|
"created_at" TIMESTAMPTZ(6) DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
"hostname" VARCHAR(100),
|
||||||
|
"browser" VARCHAR(20),
|
||||||
|
"os" VARCHAR(20),
|
||||||
|
"device" VARCHAR(20),
|
||||||
|
"screen" VARCHAR(11),
|
||||||
|
"language" VARCHAR(35),
|
||||||
|
"country" CHAR(2),
|
||||||
|
|
||||||
create index session_created_at_idx on session(created_at);
|
PRIMARY KEY ("session_id")
|
||||||
create index session_website_id_idx on session(website_id);
|
);
|
||||||
|
|
||||||
create index pageview_created_at_idx on pageview(created_at);
|
-- CreateTable
|
||||||
create index pageview_website_id_idx on pageview(website_id);
|
CREATE TABLE "website" (
|
||||||
create index pageview_session_id_idx on pageview(session_id);
|
"website_id" SERIAL NOT NULL,
|
||||||
create index pageview_website_id_created_at_idx on pageview(website_id, created_at);
|
"website_uuid" UUID NOT NULL,
|
||||||
create index pageview_website_id_session_id_created_at_idx on pageview(website_id, session_id, created_at);
|
"user_id" INTEGER NOT NULL,
|
||||||
|
"name" VARCHAR(100) NOT NULL,
|
||||||
|
"domain" VARCHAR(500),
|
||||||
|
"share_id" VARCHAR(64),
|
||||||
|
"created_at" TIMESTAMPTZ(6) DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
|
||||||
create index event_created_at_idx on event(created_at);
|
PRIMARY KEY ("website_id")
|
||||||
create index event_website_id_idx on event(website_id);
|
);
|
||||||
create index event_session_id_idx on event(session_id);
|
|
||||||
|
-- CreateIndex
|
||||||
|
CREATE UNIQUE INDEX "account.username_unique" ON "account"("username");
|
||||||
|
|
||||||
|
-- CreateIndex
|
||||||
|
CREATE INDEX "event_created_at_idx" ON "event"("created_at");
|
||||||
|
|
||||||
|
-- CreateIndex
|
||||||
|
CREATE INDEX "event_session_id_idx" ON "event"("session_id");
|
||||||
|
|
||||||
|
-- CreateIndex
|
||||||
|
CREATE INDEX "event_website_id_idx" ON "event"("website_id");
|
||||||
|
|
||||||
|
-- CreateIndex
|
||||||
|
CREATE INDEX "pageview_created_at_idx" ON "pageview"("created_at");
|
||||||
|
|
||||||
|
-- CreateIndex
|
||||||
|
CREATE INDEX "pageview_session_id_idx" ON "pageview"("session_id");
|
||||||
|
|
||||||
|
-- CreateIndex
|
||||||
|
CREATE INDEX "pageview_website_id_created_at_idx" ON "pageview"("website_id", "created_at");
|
||||||
|
|
||||||
|
-- CreateIndex
|
||||||
|
CREATE INDEX "pageview_website_id_idx" ON "pageview"("website_id");
|
||||||
|
|
||||||
|
-- CreateIndex
|
||||||
|
CREATE INDEX "pageview_website_id_session_id_created_at_idx" ON "pageview"("website_id", "session_id", "created_at");
|
||||||
|
|
||||||
|
-- CreateIndex
|
||||||
|
CREATE UNIQUE INDEX "session.session_uuid_unique" ON "session"("session_uuid");
|
||||||
|
|
||||||
|
-- CreateIndex
|
||||||
|
CREATE INDEX "session_created_at_idx" ON "session"("created_at");
|
||||||
|
|
||||||
|
-- CreateIndex
|
||||||
|
CREATE INDEX "session_website_id_idx" ON "session"("website_id");
|
||||||
|
|
||||||
|
-- CreateIndex
|
||||||
|
CREATE UNIQUE INDEX "website.website_uuid_unique" ON "website"("website_uuid");
|
||||||
|
|
||||||
|
-- CreateIndex
|
||||||
|
CREATE UNIQUE INDEX "website.share_id_unique" ON "website"("share_id");
|
||||||
|
|
||||||
|
-- CreateIndex
|
||||||
|
CREATE INDEX "website_user_id_idx" ON "website"("user_id");
|
||||||
|
|
||||||
|
-- AddForeignKey
|
||||||
|
ALTER TABLE "event" ADD FOREIGN KEY ("session_id") REFERENCES "session"("session_id") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||||
|
|
||||||
|
-- AddForeignKey
|
||||||
|
ALTER TABLE "event" ADD FOREIGN KEY ("website_id") REFERENCES "website"("website_id") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||||
|
|
||||||
|
-- AddForeignKey
|
||||||
|
ALTER TABLE "pageview" ADD FOREIGN KEY ("session_id") REFERENCES "session"("session_id") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||||
|
|
||||||
|
-- AddForeignKey
|
||||||
|
ALTER TABLE "pageview" ADD FOREIGN KEY ("website_id") REFERENCES "website"("website_id") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||||
|
|
||||||
|
-- AddForeignKey
|
||||||
|
ALTER TABLE "session" ADD FOREIGN KEY ("website_id") REFERENCES "website"("website_id") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||||
|
|
||||||
|
-- AddForeignKey
|
||||||
|
ALTER TABLE "website" ADD FOREIGN KEY ("user_id") REFERENCES "account"("user_id") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||||
|
|
||||||
insert into account (username, password, is_admin) values ('admin', '${bcrypt.hashSync(
|
insert into account (username, password, is_admin) values ('admin', '${bcrypt.hashSync(
|
||||||
umamiAdminPassword,
|
umamiAdminPassword,
|
||||||
|
@ -3,15 +3,15 @@ import { compareVersions } from "compare-versions";
|
|||||||
import cuid from "cuid";
|
import cuid from "cuid";
|
||||||
import bcrypt from "bcryptjs";
|
import bcrypt from "bcryptjs";
|
||||||
import {
|
import {
|
||||||
asyncExecShell,
|
asyncExecShell,
|
||||||
asyncSleep,
|
asyncSleep,
|
||||||
cleanupDockerStorage,
|
cleanupDockerStorage,
|
||||||
errorHandler,
|
errorHandler,
|
||||||
isDev,
|
isDev,
|
||||||
listSettings,
|
listSettings,
|
||||||
prisma,
|
prisma,
|
||||||
uniqueName,
|
uniqueName,
|
||||||
version,
|
version,
|
||||||
} from "../../../lib/common";
|
} from "../../../lib/common";
|
||||||
import { supportedServiceTypesAndVersions } from "../../../lib/services/supportedVersions";
|
import { supportedServiceTypesAndVersions } from "../../../lib/services/supportedVersions";
|
||||||
import { scheduler } from "../../../lib/scheduler";
|
import { scheduler } from "../../../lib/scheduler";
|
||||||
@ -20,321 +20,321 @@ import type { Login, Update } from ".";
|
|||||||
import type { GetCurrentUser } from "./types";
|
import type { GetCurrentUser } from "./types";
|
||||||
|
|
||||||
export async function hashPassword(password: string): Promise<string> {
|
export async function hashPassword(password: string): Promise<string> {
|
||||||
const saltRounds = 15;
|
const saltRounds = 15;
|
||||||
return bcrypt.hash(password, saltRounds);
|
return bcrypt.hash(password, saltRounds);
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function cleanupManually(request: FastifyRequest) {
|
export async function cleanupManually(request: FastifyRequest) {
|
||||||
try {
|
try {
|
||||||
const { serverId } = request.body;
|
const { serverId } = request.body;
|
||||||
const destination = await prisma.destinationDocker.findUnique({
|
const destination = await prisma.destinationDocker.findUnique({
|
||||||
where: { id: serverId },
|
where: { id: serverId },
|
||||||
});
|
});
|
||||||
await cleanupDockerStorage(destination.id, true, true);
|
await cleanupDockerStorage(destination.id, true, true);
|
||||||
return {};
|
return {};
|
||||||
} catch ({ status, message }) {
|
} catch ({ status, message }) {
|
||||||
return errorHandler({ status, message });
|
return errorHandler({ status, message });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
export async function checkUpdate(request: FastifyRequest) {
|
export async function checkUpdate(request: FastifyRequest) {
|
||||||
try {
|
try {
|
||||||
const isStaging =
|
const isStaging =
|
||||||
request.hostname === "staging.coolify.io" ||
|
request.hostname === "staging.coolify.io" ||
|
||||||
request.hostname === "arm.coolify.io";
|
request.hostname === "arm.coolify.io";
|
||||||
const currentVersion = version;
|
const currentVersion = version;
|
||||||
const { data: versions } = await axios.get(
|
const { data: versions } = await axios.get(
|
||||||
`https://get.coollabs.io/versions.json?appId=${process.env["COOLIFY_APP_ID"]}&version=${currentVersion}`
|
`https://get.coollabs.io/versions.json?appId=${process.env["COOLIFY_APP_ID"]}&version=${currentVersion}`
|
||||||
);
|
);
|
||||||
const latestVersion = versions["coolify"].main.version;
|
const latestVersion = versions["coolify"].main.version;
|
||||||
const isUpdateAvailable = compareVersions(latestVersion, currentVersion);
|
const isUpdateAvailable = compareVersions(latestVersion, currentVersion);
|
||||||
if (isStaging) {
|
if (isStaging) {
|
||||||
return {
|
return {
|
||||||
isUpdateAvailable: true,
|
isUpdateAvailable: true,
|
||||||
latestVersion: "next",
|
latestVersion: "next",
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
return {
|
return {
|
||||||
isUpdateAvailable: isStaging ? true : isUpdateAvailable === 1,
|
isUpdateAvailable: isStaging ? true : isUpdateAvailable === 1,
|
||||||
latestVersion,
|
latestVersion,
|
||||||
};
|
};
|
||||||
} catch ({ status, message }) {
|
} catch ({ status, message }) {
|
||||||
return errorHandler({ status, message });
|
return errorHandler({ status, message });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function update(request: FastifyRequest<Update>) {
|
export async function update(request: FastifyRequest<Update>) {
|
||||||
const { latestVersion } = request.body;
|
const { latestVersion } = request.body;
|
||||||
try {
|
try {
|
||||||
if (!isDev) {
|
if (!isDev) {
|
||||||
const { isAutoUpdateEnabled } = await prisma.setting.findFirst();
|
const { isAutoUpdateEnabled } = await prisma.setting.findFirst();
|
||||||
await asyncExecShell(`docker pull coollabsio/coolify:${latestVersion}`);
|
await asyncExecShell(`docker pull coollabsio/coolify:${latestVersion}`);
|
||||||
await asyncExecShell(`env | grep COOLIFY > .env`);
|
await asyncExecShell(`env | grep COOLIFY > .env`);
|
||||||
await asyncExecShell(
|
await asyncExecShell(
|
||||||
`sed -i '/COOLIFY_AUTO_UPDATE=/cCOOLIFY_AUTO_UPDATE=${isAutoUpdateEnabled}' .env`
|
`sed -i '/COOLIFY_AUTO_UPDATE=/cCOOLIFY_AUTO_UPDATE=${isAutoUpdateEnabled}' .env`
|
||||||
);
|
);
|
||||||
await asyncExecShell(
|
await asyncExecShell(
|
||||||
`docker run --rm -tid --env-file .env -v /var/run/docker.sock:/var/run/docker.sock -v coolify-db coollabsio/coolify:${latestVersion} /bin/sh -c "env | grep COOLIFY > .env && echo 'TAG=${latestVersion}' >> .env && docker stop -t 0 coolify && docker rm coolify && docker compose up -d --force-recreate"`
|
`docker run --rm -tid --env-file .env -v /var/run/docker.sock:/var/run/docker.sock -v coolify-db coollabsio/coolify:${latestVersion} /bin/sh -c "env | grep COOLIFY > .env && echo 'TAG=${latestVersion}' >> .env && docker stop -t 0 coolify && docker rm coolify && docker compose up -d --force-recreate"`
|
||||||
);
|
);
|
||||||
return {};
|
return {};
|
||||||
} else {
|
} else {
|
||||||
await asyncSleep(2000);
|
await asyncSleep(2000);
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
} catch ({ status, message }) {
|
} catch ({ status, message }) {
|
||||||
return errorHandler({ status, message });
|
return errorHandler({ status, message });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
export async function resetQueue(request: FastifyRequest<any>) {
|
export async function resetQueue(request: FastifyRequest<any>) {
|
||||||
try {
|
try {
|
||||||
const teamId = request.user.teamId;
|
const teamId = request.user.teamId;
|
||||||
if (teamId === "0") {
|
if (teamId === "0") {
|
||||||
await prisma.build.updateMany({
|
await prisma.build.updateMany({
|
||||||
where: { status: { in: ["queued", "running"] } },
|
where: { status: { in: ["queued", "running"] } },
|
||||||
data: { status: "canceled" },
|
data: { status: "canceled" },
|
||||||
});
|
});
|
||||||
scheduler.workers.get("deployApplication").postMessage("cancel");
|
scheduler.workers.get("deployApplication").postMessage("cancel");
|
||||||
}
|
}
|
||||||
} catch ({ status, message }) {
|
} catch ({ status, message }) {
|
||||||
return errorHandler({ status, message });
|
return errorHandler({ status, message });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
export async function restartCoolify(request: FastifyRequest<any>) {
|
export async function restartCoolify(request: FastifyRequest<any>) {
|
||||||
try {
|
try {
|
||||||
const teamId = request.user.teamId;
|
const teamId = request.user.teamId;
|
||||||
if (teamId === "0") {
|
if (teamId === "0") {
|
||||||
if (!isDev) {
|
if (!isDev) {
|
||||||
asyncExecShell(`docker restart coolify`);
|
asyncExecShell(`docker restart coolify`);
|
||||||
return {};
|
return {};
|
||||||
} else {
|
} else {
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
throw {
|
throw {
|
||||||
status: 500,
|
status: 500,
|
||||||
message: "You are not authorized to restart Coolify.",
|
message: "You are not authorized to restart Coolify.",
|
||||||
};
|
};
|
||||||
} catch ({ status, message }) {
|
} catch ({ status, message }) {
|
||||||
return errorHandler({ status, message });
|
return errorHandler({ status, message });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function showDashboard(request: FastifyRequest) {
|
export async function showDashboard(request: FastifyRequest) {
|
||||||
try {
|
try {
|
||||||
const userId = request.user.userId;
|
const userId = request.user.userId;
|
||||||
const teamId = request.user.teamId;
|
const teamId = request.user.teamId;
|
||||||
const applications = await prisma.application.findMany({
|
const applications = await prisma.application.findMany({
|
||||||
where: { teams: { some: { id: teamId === "0" ? undefined : teamId } } },
|
where: { teams: { some: { id: teamId === "0" ? undefined : teamId } } },
|
||||||
include: { settings: true, destinationDocker: true, teams: true },
|
include: { settings: true, destinationDocker: true, teams: true },
|
||||||
});
|
});
|
||||||
const databases = await prisma.database.findMany({
|
const databases = await prisma.database.findMany({
|
||||||
where: { teams: { some: { id: teamId === "0" ? undefined : teamId } } },
|
where: { teams: { some: { id: teamId === "0" ? undefined : teamId } } },
|
||||||
include: { settings: true, destinationDocker: true, teams: true },
|
include: { settings: true, destinationDocker: true, teams: true },
|
||||||
});
|
});
|
||||||
const services = await prisma.service.findMany({
|
const services = await prisma.service.findMany({
|
||||||
where: { teams: { some: { id: teamId === "0" ? undefined : teamId } } },
|
where: { teams: { some: { id: teamId === "0" ? undefined : teamId } } },
|
||||||
include: { destinationDocker: true, teams: true },
|
include: { destinationDocker: true, teams: true },
|
||||||
});
|
});
|
||||||
const gitSources = await prisma.gitSource.findMany({
|
const gitSources = await prisma.gitSource.findMany({
|
||||||
where: { teams: { some: { id: teamId === "0" ? undefined : teamId } } },
|
where: { teams: { some: { id: teamId === "0" ? undefined : teamId } } },
|
||||||
include: { teams: true },
|
include: { teams: true },
|
||||||
});
|
});
|
||||||
const destinations = await prisma.destinationDocker.findMany({
|
const destinations = await prisma.destinationDocker.findMany({
|
||||||
where: { teams: { some: { id: teamId === "0" ? undefined : teamId } } },
|
where: { teams: { some: { id: teamId === "0" ? undefined : teamId } } },
|
||||||
include: { teams: true },
|
include: { teams: true },
|
||||||
});
|
});
|
||||||
const settings = await listSettings();
|
const settings = await listSettings();
|
||||||
return {
|
return {
|
||||||
applications,
|
applications,
|
||||||
databases,
|
databases,
|
||||||
services,
|
services,
|
||||||
gitSources,
|
gitSources,
|
||||||
destinations,
|
destinations,
|
||||||
settings,
|
settings,
|
||||||
};
|
};
|
||||||
} catch ({ status, message }) {
|
} catch ({ status, message }) {
|
||||||
return errorHandler({ status, message });
|
return errorHandler({ status, message });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function login(
|
export async function login(
|
||||||
request: FastifyRequest<Login>,
|
request: FastifyRequest<Login>,
|
||||||
reply: FastifyReply
|
reply: FastifyReply
|
||||||
) {
|
) {
|
||||||
if (request.user) {
|
if (request.user) {
|
||||||
return reply.redirect("/dashboard");
|
return reply.redirect("/dashboard");
|
||||||
} else {
|
} else {
|
||||||
const { email, password, isLogin } = request.body || {};
|
const { email, password, isLogin } = request.body || {};
|
||||||
if (!email || !password) {
|
if (!email || !password) {
|
||||||
throw { status: 500, message: "Email and password are required." };
|
throw { status: 500, message: "Email and password are required." };
|
||||||
}
|
}
|
||||||
const users = await prisma.user.count();
|
const users = await prisma.user.count();
|
||||||
const userFound = await prisma.user.findUnique({
|
const userFound = await prisma.user.findUnique({
|
||||||
where: { email },
|
where: { email },
|
||||||
include: { teams: true, permission: true },
|
include: { teams: true, permission: true },
|
||||||
rejectOnNotFound: false,
|
rejectOnNotFound: false,
|
||||||
});
|
});
|
||||||
if (!userFound && isLogin) {
|
if (!userFound && isLogin) {
|
||||||
throw { status: 500, message: "User not found." };
|
throw { status: 500, message: "User not found." };
|
||||||
}
|
}
|
||||||
const { isRegistrationEnabled, id } = await prisma.setting.findFirst();
|
const { isRegistrationEnabled, id } = await prisma.setting.findFirst();
|
||||||
let uid = cuid();
|
let uid = cuid();
|
||||||
let permission = "read";
|
let permission = "read";
|
||||||
let isAdmin = false;
|
let isAdmin = false;
|
||||||
|
|
||||||
if (users === 0) {
|
if (users === 0) {
|
||||||
await prisma.setting.update({
|
await prisma.setting.update({
|
||||||
where: { id },
|
where: { id },
|
||||||
data: { isRegistrationEnabled: false },
|
data: { isRegistrationEnabled: false },
|
||||||
});
|
});
|
||||||
uid = "0";
|
uid = "0";
|
||||||
}
|
}
|
||||||
if (userFound) {
|
if (userFound) {
|
||||||
if (userFound.type === "email") {
|
if (userFound.type === "email") {
|
||||||
if (userFound.password === "RESETME") {
|
if (userFound.password === "RESETME") {
|
||||||
const hashedPassword = await hashPassword(password);
|
const hashedPassword = await hashPassword(password);
|
||||||
if (userFound.updatedAt < new Date(Date.now() - 1000 * 60 * 10)) {
|
if (userFound.updatedAt < new Date(Date.now() - 1000 * 60 * 10)) {
|
||||||
if (userFound.id === "0") {
|
if (userFound.id === "0") {
|
||||||
await prisma.user.update({
|
await prisma.user.update({
|
||||||
where: { email: userFound.email },
|
where: { email: userFound.email },
|
||||||
data: { password: "RESETME" },
|
data: { password: "RESETME" },
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
await prisma.user.update({
|
await prisma.user.update({
|
||||||
where: { email: userFound.email },
|
where: { email: userFound.email },
|
||||||
data: { password: "RESETTIMEOUT" },
|
data: { password: "RESETTIMEOUT" },
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
throw {
|
throw {
|
||||||
status: 500,
|
status: 500,
|
||||||
message:
|
message:
|
||||||
"Password reset link has expired. Please request a new one.",
|
"Password reset link has expired. Please request a new one.",
|
||||||
};
|
};
|
||||||
} else {
|
} else {
|
||||||
await prisma.user.update({
|
await prisma.user.update({
|
||||||
where: { email: userFound.email },
|
where: { email: userFound.email },
|
||||||
data: { password: hashedPassword },
|
data: { password: hashedPassword },
|
||||||
});
|
});
|
||||||
return {
|
return {
|
||||||
userId: userFound.id,
|
userId: userFound.id,
|
||||||
teamId: userFound.id,
|
teamId: userFound.id,
|
||||||
permission: userFound.permission,
|
permission: userFound.permission,
|
||||||
isAdmin: true,
|
isAdmin: true,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const passwordMatch = await bcrypt.compare(
|
const passwordMatch = await bcrypt.compare(
|
||||||
password,
|
password,
|
||||||
userFound.password
|
userFound.password
|
||||||
);
|
);
|
||||||
if (!passwordMatch) {
|
if (!passwordMatch) {
|
||||||
throw {
|
throw {
|
||||||
status: 500,
|
status: 500,
|
||||||
message: "Wrong password or email address.",
|
message: "Wrong password or email address.",
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
uid = userFound.id;
|
uid = userFound.id;
|
||||||
isAdmin = true;
|
isAdmin = true;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
permission = "owner";
|
permission = "owner";
|
||||||
isAdmin = true;
|
isAdmin = true;
|
||||||
if (!isRegistrationEnabled) {
|
if (!isRegistrationEnabled) {
|
||||||
throw {
|
throw {
|
||||||
status: 404,
|
status: 404,
|
||||||
message: "Registration disabled by administrator.",
|
message: "Registration disabled by administrator.",
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
const hashedPassword = await hashPassword(password);
|
const hashedPassword = await hashPassword(password);
|
||||||
if (users === 0) {
|
if (users === 0) {
|
||||||
await prisma.user.create({
|
await prisma.user.create({
|
||||||
data: {
|
data: {
|
||||||
id: uid,
|
id: uid,
|
||||||
email,
|
email,
|
||||||
password: hashedPassword,
|
password: hashedPassword,
|
||||||
type: "email",
|
type: "email",
|
||||||
teams: {
|
teams: {
|
||||||
create: {
|
create: {
|
||||||
id: uid,
|
id: uid,
|
||||||
name: uniqueName(),
|
name: uniqueName(),
|
||||||
destinationDocker: { connect: { network: "coolify" } },
|
destinationDocker: { connect: { network: "coolify" } },
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
permission: { create: { teamId: uid, permission: "owner" } },
|
permission: { create: { teamId: uid, permission: "owner" } },
|
||||||
},
|
},
|
||||||
include: { teams: true },
|
include: { teams: true },
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
await prisma.user.create({
|
await prisma.user.create({
|
||||||
data: {
|
data: {
|
||||||
id: uid,
|
id: uid,
|
||||||
email,
|
email,
|
||||||
password: hashedPassword,
|
password: hashedPassword,
|
||||||
type: "email",
|
type: "email",
|
||||||
teams: {
|
teams: {
|
||||||
create: {
|
create: {
|
||||||
id: uid,
|
id: uid,
|
||||||
name: uniqueName(),
|
name: uniqueName(),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
permission: { create: { teamId: uid, permission: "owner" } },
|
permission: { create: { teamId: uid, permission: "owner" } },
|
||||||
},
|
},
|
||||||
include: { teams: true },
|
include: { teams: true },
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return {
|
return {
|
||||||
userId: uid,
|
userId: uid,
|
||||||
teamId: uid,
|
teamId: uid,
|
||||||
permission,
|
permission,
|
||||||
isAdmin,
|
isAdmin,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getCurrentUser(
|
export async function getCurrentUser(
|
||||||
request: FastifyRequest<GetCurrentUser>,
|
request: FastifyRequest<GetCurrentUser>,
|
||||||
fastify
|
fastify
|
||||||
) {
|
) {
|
||||||
let token = null;
|
let token = null;
|
||||||
const { teamId } = request.query;
|
const { teamId } = request.query;
|
||||||
try {
|
try {
|
||||||
const user = await prisma.user.findUnique({
|
const user = await prisma.user.findUnique({
|
||||||
where: { id: request.user.userId },
|
where: { id: request.user.userId },
|
||||||
});
|
});
|
||||||
if (!user) {
|
if (!user) {
|
||||||
throw "User not found";
|
throw "User not found";
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
throw { status: 401, message: error };
|
throw { status: 401, message: error };
|
||||||
}
|
}
|
||||||
if (teamId) {
|
if (teamId) {
|
||||||
try {
|
try {
|
||||||
const user = await prisma.user.findFirst({
|
const user = await prisma.user.findFirst({
|
||||||
where: { id: request.user.userId, teams: { some: { id: teamId } } },
|
where: { id: request.user.userId, teams: { some: { id: teamId } } },
|
||||||
include: { teams: true, permission: true },
|
include: { teams: true, permission: true },
|
||||||
});
|
});
|
||||||
if (user) {
|
if (user) {
|
||||||
const permission = user.permission.find(
|
const permission = user.permission.find(
|
||||||
(p) => p.teamId === teamId
|
(p) => p.teamId === teamId
|
||||||
).permission;
|
).permission;
|
||||||
const payload = {
|
const payload = {
|
||||||
...request.user,
|
...request.user,
|
||||||
teamId,
|
teamId,
|
||||||
permission: permission || null,
|
permission: permission || null,
|
||||||
isAdmin: permission === "owner" || permission === "admin",
|
isAdmin: permission === "owner" || permission === "admin",
|
||||||
};
|
};
|
||||||
token = fastify.jwt.sign(payload);
|
token = fastify.jwt.sign(payload);
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
// No new token -> not switching teams
|
// No new token -> not switching teams
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return {
|
return {
|
||||||
settings: await prisma.setting.findFirst(),
|
settings: await prisma.setting.findFirst(),
|
||||||
supportedServiceTypesAndVersions,
|
supportedServiceTypesAndVersions,
|
||||||
token,
|
token,
|
||||||
...request.user,
|
...request.user,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -28,7 +28,7 @@ import {addToast} from '$lib/store';
|
|||||||
import BuildLog from './_BuildLog.svelte';
|
import BuildLog from './_BuildLog.svelte';
|
||||||
import { get, post } from '$lib/api';
|
import { get, post } from '$lib/api';
|
||||||
import { t } from '$lib/translations';
|
import { t } from '$lib/translations';
|
||||||
import { changeQueryParams, dateOptions, errorNotification } from '$lib/common';
|
import { changeQueryParams, dateOptions, errorNotification, asyncSleep } from '$lib/common';
|
||||||
import Tooltip from '$lib/components/Tooltip.svelte';
|
import Tooltip from '$lib/components/Tooltip.svelte';
|
||||||
|
|
||||||
let buildId: any;
|
let buildId: any;
|
||||||
@ -85,7 +85,7 @@ import {addToast} from '$lib/store';
|
|||||||
return changeQueryParams(buildId);
|
return changeQueryParams(buildId);
|
||||||
}
|
}
|
||||||
async function resetQueue() {
|
async function resetQueue() {
|
||||||
const sure = confirm('It will reset all build queues for all applications. If something is queued, it will be canceled automatically. Are you sure? ');
|
const sure = confirm('It will reset all build queues for all applications. If something is queued, it will be canceled automatically. Are you sure? ');
|
||||||
if (sure) {
|
if (sure) {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@ -94,6 +94,8 @@ import {addToast} from '$lib/store';
|
|||||||
message: 'Queue reset done.',
|
message: 'Queue reset done.',
|
||||||
type: 'success'
|
type: 'success'
|
||||||
});
|
});
|
||||||
|
await asyncSleep(500)
|
||||||
|
return window.location.reload()
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
return errorNotification(error);
|
return errorNotification(error);
|
||||||
}
|
}
|
||||||
@ -162,12 +164,8 @@ import {addToast} from '$lib/store';
|
|||||||
on:click={() => loadBuild(build.id)}
|
on:click={() => loadBuild(build.id)}
|
||||||
class:rounded-tr={index === 0}
|
class:rounded-tr={index === 0}
|
||||||
class:rounded-br={index === builds.length - 1}
|
class:rounded-br={index === builds.length - 1}
|
||||||
class="flex cursor-pointer items-center justify-center border-l-2 py-4 no-underline transition-all duration-100 hover:bg-coolgray-400 hover:shadow-xl"
|
class="flex cursor-pointer items-center justify-center py-4 no-underline transition-all duration-100 hover:bg-coolgray-400 hover:shadow-xl"
|
||||||
class:bg-coolgray-400={buildId === build.id}
|
class:bg-coolgray-400={buildId === build.id}
|
||||||
class:border-red-500={build.status === 'failed'}
|
|
||||||
class:border-orange-500={build.status === 'canceled'}
|
|
||||||
class:border-green-500={build.status === 'success'}
|
|
||||||
class:border-yellow-500={build.status === 'running'}
|
|
||||||
>
|
>
|
||||||
<div class="flex-col px-2 text-center min-w-[10rem]">
|
<div class="flex-col px-2 text-center min-w-[10rem]">
|
||||||
<div class="text-sm font-bold">
|
<div class="text-sm font-bold">
|
||||||
@ -176,6 +174,11 @@ import {addToast} from '$lib/store';
|
|||||||
<div class="text-xs">
|
<div class="text-xs">
|
||||||
{build.type}
|
{build.type}
|
||||||
</div>
|
</div>
|
||||||
|
<div class="badge badge-sm text-xs text-white uppercase rounded bg-coolgray-300 border-none font-bold"
|
||||||
|
class:text-red-500={build.status === 'failed'}
|
||||||
|
class:text-orange-500={build.status === 'canceled'}
|
||||||
|
class:text-green-500={build.status === 'success'}
|
||||||
|
class:text-yellow-500={build.status === 'running'}>{build.status}</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="w-48 text-center text-xs">
|
<div class="w-48 text-center text-xs">
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "coolify",
|
"name": "coolify",
|
||||||
"description": "An open-source & self-hostable Heroku / Netlify alternative.",
|
"description": "An open-source & self-hostable Heroku / Netlify alternative.",
|
||||||
"version": "3.10.2",
|
"version": "3.10.3",
|
||||||
"license": "Apache-2.0",
|
"license": "Apache-2.0",
|
||||||
"repository": "github:coollabsio/coolify",
|
"repository": "github:coollabsio/coolify",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user