Skip to content

An open-source, self-hostable PaaS alternative to Vercel, Heroku & Netlify that lets you easily deploy static sites, databases, full-stack applications and 360+ one-click services on your own servers.

Merge branch 'arm' into improve-typing

Andras Bacsai45bf6f77d1bf
diff --cc src/lib/common.ts
index e3aeac7cc1,57cdabba22..a9157d1dc4
--- a/src/lib/common.ts
+++ b/src/lib/common.ts
@@@ -46,30 -45,37 +46,32 @@@ const customConfig: Config =
export const version = currentVersion;
export const asyncExecShell = util.promisify(child.exec);
-export const asyncSleep = (delay) => new Promise((resolve) => setTimeout(resolve, delay));
-
+export const asyncSleep = (delay: number): Promise<unknown> =>
+ new Promise((resolve) => setTimeout(resolve, delay));
export const sentry = Sentry;
-export const uniqueName = () => uniqueNamesGenerator(customConfig);
-
-export const saveBuildLog = async ({ line, buildId, applicationId }) => {
+export const uniqueName = (): string => uniqueNamesGenerator(customConfig);
+
+export const saveBuildLog = async ({
+ line,
+ buildId,
+ applicationId
+}: {
+ line: string;
+ buildId: string;
+ applicationId: string;
+}): Promise<Job> => {
- if (line.includes('ghs_')) {
- const regex = /ghs_.*@/g;
- line = line.replace(regex, '<SENSITIVE_DATA_DELETED>@');
+ if (line) {
+ if (line.includes('ghs_')) {
+ const regex = /ghs_.*@/g;
+ line = line.replace(regex, '<SENSITIVE_DATA_DELETED>@');
+ }
+ const addTimestamp = `${generateTimestamp()} ${line}`;
+ return await buildLogQueue.add(buildId, { buildId, line: addTimestamp, applicationId });
}
- const addTimestamp = `${generateTimestamp()} ${line}`;
- return await buildLogQueue.add(buildId, { buildId, line: addTimestamp, applicationId });
};
-export const isTeamIdTokenAvailable = (request) => {
- const cookie = request.headers.cookie
- ?.split(';')
- .map((s) => s.trim())
- .find((s) => s.startsWith('teamId='))
- ?.split('=')[1];
- if (!cookie) {
- return getTeam(request);
- } else {
- return cookie;
- }
-};
-
-export const getTeam = (event) => {
+export const getTeam = (event: RequestEvent): string | null => {
const cookies = Cookie.parse(event.request.headers.get('cookie'));
if (cookies?.teamId) {
return cookies.teamId;
diff --cc src/lib/database/applications.ts
index 0f432b5d34,ce53fe7096..3ce6286d71
--- a/src/lib/database/applications.ts
+++ b/src/lib/database/applications.ts
@@@ -70,26 -73,16 +70,30 @@@ export async function removeApplication
await prisma.build.deleteMany({ where: { applicationId: id } });
await prisma.secret.deleteMany({ where: { applicationId: id } });
await prisma.applicationPersistentStorage.deleteMany({ where: { applicationId: id } });
- await prisma.application.deleteMany({ where: { id, teams: { some: { id: teamId } } } });
+ if (teamId === '0') {
+ await prisma.application.deleteMany({ where: { id } });
+ } else {
+ await prisma.application.deleteMany({ where: { id, teams: { some: { id: teamId } } } });
+ }
}
-export async function getApplicationWebhook({ projectId, branch }) {
+export async function getApplicationWebhook({
+ projectId,
+ branch
+}: {
+ projectId: number;
+ branch: string;
+}): Promise<
+ Application & {
+ destinationDocker: DestinationDocker;
+ settings: ApplicationSettings;
+ gitSource: GitSource;
+ secrets: Secret[];
+ persistentStorage: ApplicationPersistentStorage[];
+ }
+> {
try {
- let application = await prisma.application.findFirst({
+ const application = await prisma.application.findFirst({
where: { projectId, branch, settings: { autodeploy: true } },
include: {
destinationDocker: true,
diff --cc src/lib/database/common.ts
index 541fb86851,9d588fcc45..cdc1d5b92b
--- a/src/lib/database/common.ts
+++ b/src/lib/database/common.ts
@@@ -217,8 -156,10 +217,9 @@@ export function generateDatabaseConfigu
};
} else if (type === 'postgresql') {
return {
- // url: `psql://${dbUser}:${dbUserPassword}@${id}:${isPublic ? port : 5432}/${defaultDatabase}`,
privatePort: 5432,
environmentVariables: {
+ POSTGRESQL_POSTGRES_PASSWORD: rootUserPassword,
POSTGRESQL_PASSWORD: dbUserPassword,
POSTGRESQL_USERNAME: dbUser,
POSTGRESQL_DATABASE: defaultDatabase
diff --cc src/lib/database/gitSources.ts
index f77df7ae7a,b8279c268e..01d36a7da6
--- a/src/lib/database/gitSources.ts
+++ b/src/lib/database/gitSources.ts
@@@ -16,34 -13,15 +16,29 @@@ export async function listSources
});
}
-export async function newSource({ teamId, name }) {
+export async function newSource({
+ name,
+ teamId,
+ type,
+ htmlUrl,
+ apiUrl,
+ organization
+}: {
+ name: string;
+ teamId: string;
+ type: string;
+ htmlUrl: string;
+ apiUrl: string;
+ organization: string;
+}): Promise<GitSource> {
return await prisma.gitSource.create({
data: {
- teams: { connect: { id: teamId } },
name,
- type,
- htmlUrl,
- apiUrl,
- organization
+ teams: { connect: { id: teamId } }
}
});
}
-export async function removeSource({ id }) {
+export async function removeSource({ id }: { id: string }): Promise<void> {
- // TODO: Disconnect application with this sourceId! Maybe not needed?
const source = await prisma.gitSource.delete({
where: { id },
include: { githubApp: true, gitlabApp: true }
@@@ -119,15 -92,9 +121,15 @@@ export async function configureGitsourc
data: { gitSource: { connect: { id: gitSourceId } } }
});
}
-export async function updateGitsource({ id, name, htmlUrl, apiUrl }) {
+export async function updateGitsource({
+ id,
+ name
+}: {
+ id: string;
+ name: string;
+}): Promise<GitSource> {
return await prisma.gitSource.update({
where: { id },
- data: { name }
+ data: { name, htmlUrl, apiUrl }
});
}
diff --cc src/lib/database/users.ts
index 9fd46b932b,22e32fbc7e..cdabf35888
--- a/src/lib/database/users.ts
+++ b/src/lib/database/users.ts
@@@ -1,12 -1,12 +1,13 @@@
import cuid from 'cuid';
- import bcrypt from 'bcrypt';
+ import bcrypt from 'bcryptjs';
+
import { prisma } from './common';
import { asyncExecShell, uniqueName } from '$lib/common';
-
import * as db from '$lib/database';
import { startCoolifyProxy } from '$lib/haproxy';
-export async function hashPassword(password: string) {
+import type { User } from '@prisma/client';
+
+export async function hashPassword(password: string): Promise<string> {
const saltRounds = 15;
return bcrypt.hash(password, saltRounds);
}
diff --cc src/lib/importers/gitlab.ts
index b7eb6d47bc,0cf57d98a7..966b22c969
--- a/src/lib/importers/gitlab.ts
+++ b/src/lib/importers/gitlab.ts
@@@ -9,17 -9,8 +9,17 @@@ export default async function (
branch,
buildId,
privateSshKey
-}): Promise<any> {
+}: {
+ applicationId: string;
+ workdir: string;
+ repository: string;
+ htmlUrl: string;
+ branch: string;
+ buildId: string;
+ repodir: string;
+ privateSshKey: string;
+}): Promise<string> {
- const url = htmlUrl.replace('https://', '').replace('http://', '');
+ const url = htmlUrl.replace('https://', '').replace('http://', '').replace(/\/$/, '');
await saveBuildLog({ line: 'GitLab importer started.', buildId, applicationId });
await asyncExecShell(`echo '${privateSshKey}' > ${repodir}/id.rsa`);
await asyncExecShell(`chmod 600 ${repodir}/id.rsa`);