Merge branch 'main' into main
This commit is contained in:
@@ -4,6 +4,12 @@ import { promises as fs } from 'fs';
|
||||
const createDockerfile = async (data, image, htaccessFound): Promise<void> => {
|
||||
const { workdir, baseDirectory } = data;
|
||||
const Dockerfile: Array<string> = [];
|
||||
let composerFound = false;
|
||||
try {
|
||||
await fs.readFile(`${workdir}${baseDirectory || ''}/composer.json`);
|
||||
composerFound = true;
|
||||
} catch (error) {}
|
||||
|
||||
Dockerfile.push(`FROM ${image}`);
|
||||
Dockerfile.push(`LABEL coolify.image=true`);
|
||||
Dockerfile.push('WORKDIR /app');
|
||||
@@ -11,6 +17,10 @@ const createDockerfile = async (data, image, htaccessFound): Promise<void> => {
|
||||
if (htaccessFound) {
|
||||
Dockerfile.push(`COPY .${baseDirectory || ''}/.htaccess ./`);
|
||||
}
|
||||
if (composerFound) {
|
||||
Dockerfile.push(`RUN composer install`);
|
||||
}
|
||||
|
||||
Dockerfile.push(`COPY /entrypoint.sh /opt/docker/provision/entrypoint.d/30-entrypoint.sh`);
|
||||
Dockerfile.push(`EXPOSE 80`);
|
||||
await fs.writeFile(`${workdir}/Dockerfile`, Dockerfile.join('\n'));
|
||||
@@ -21,12 +31,14 @@ export default async function (data) {
|
||||
try {
|
||||
let htaccessFound = false;
|
||||
try {
|
||||
const d = await fs.readFile(`${workdir}${baseDirectory || ''}/.htaccess`);
|
||||
await fs.readFile(`${workdir}${baseDirectory || ''}/.htaccess`);
|
||||
htaccessFound = true;
|
||||
} catch (e) {
|
||||
//
|
||||
}
|
||||
const image = htaccessFound ? 'webdevops/php-apache' : 'webdevops/php-nginx';
|
||||
const image = htaccessFound
|
||||
? 'webdevops/php-apache:8.0-alpine'
|
||||
: 'webdevops/php-nginx:8.0-alpine';
|
||||
await createDockerfile(data, image, htaccessFound);
|
||||
await buildImage(data);
|
||||
} catch (error) {
|
||||
|
||||
@@ -52,12 +52,14 @@ export const sentry = Sentry;
|
||||
export const uniqueName = () => uniqueNamesGenerator(customConfig);
|
||||
|
||||
export const saveBuildLog = async ({ line, buildId, applicationId }) => {
|
||||
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) => {
|
||||
@@ -100,6 +102,7 @@ export const getUserDetails = async (event, isAdminRequired = true) => {
|
||||
message: 'OK'
|
||||
}
|
||||
};
|
||||
|
||||
if (isAdminRequired && permission !== 'admin' && permission !== 'owner') {
|
||||
payload.status = 401;
|
||||
payload.body.message =
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
export let isCenter = true;
|
||||
export let disabled = false;
|
||||
export let dataTooltip = null;
|
||||
export let loading = false;
|
||||
</script>
|
||||
|
||||
<div class="flex items-center py-4 pr-8">
|
||||
@@ -26,9 +27,10 @@
|
||||
on:click
|
||||
aria-pressed="false"
|
||||
class="relative mx-20 inline-flex h-6 w-11 flex-shrink-0 cursor-pointer rounded-full border-2 border-transparent transition-colors duration-200 ease-in-out"
|
||||
class:opacity-50={disabled}
|
||||
class:bg-green-600={setting}
|
||||
class:bg-stone-700={!setting}
|
||||
class:opacity-50={disabled || loading}
|
||||
class:bg-green-600={!loading && setting}
|
||||
class:bg-stone-700={!loading && !setting}
|
||||
class:bg-yellow-500={loading}
|
||||
>
|
||||
<span class="sr-only">Use setting</span>
|
||||
<span
|
||||
@@ -40,6 +42,7 @@
|
||||
class=" absolute inset-0 flex h-full w-full items-center justify-center transition-opacity duration-200 ease-in"
|
||||
class:opacity-0={setting}
|
||||
class:opacity-100={!setting}
|
||||
class:animate-spin={loading}
|
||||
aria-hidden="true"
|
||||
>
|
||||
<svg class="h-3 w-3 bg-white text-red-600" fill="none" viewBox="0 0 12 12">
|
||||
@@ -57,6 +60,7 @@
|
||||
aria-hidden="true"
|
||||
class:opacity-100={setting}
|
||||
class:opacity-0={!setting}
|
||||
class:animate-spin={loading}
|
||||
>
|
||||
<svg class="h-3 w-3 bg-white text-green-600" fill="currentColor" viewBox="0 0 12 12">
|
||||
<path
|
||||
|
||||
@@ -43,3 +43,142 @@ export function changeQueryParams(buildId) {
|
||||
queryParams.set('buildId', buildId);
|
||||
return history.pushState(null, null, '?' + queryParams.toString());
|
||||
}
|
||||
|
||||
export const supportedDatabaseTypesAndVersions = [
|
||||
{
|
||||
name: 'mongodb',
|
||||
fancyName: 'MongoDB',
|
||||
baseImage: 'bitnami/mongodb',
|
||||
versions: ['5.0', '4.4', '4.2']
|
||||
},
|
||||
{ name: 'mysql', fancyName: 'MySQL', baseImage: 'bitnami/mysql', versions: ['8.0', '5.7'] },
|
||||
{
|
||||
name: 'postgresql',
|
||||
fancyName: 'PostgreSQL',
|
||||
baseImage: 'bitnami/postgresql',
|
||||
versions: ['14.2.0', '13.6.0', '12.10.0 ', '11.15.0', '10.20.0']
|
||||
},
|
||||
{
|
||||
name: 'redis',
|
||||
fancyName: 'Redis',
|
||||
baseImage: 'bitnami/redis',
|
||||
versions: ['6.2', '6.0', '5.0']
|
||||
},
|
||||
{ name: 'couchdb', fancyName: 'CouchDB', baseImage: 'bitnami/couchdb', versions: ['3.2.1'] }
|
||||
];
|
||||
export const supportedServiceTypesAndVersions = [
|
||||
{
|
||||
name: 'plausibleanalytics',
|
||||
fancyName: 'Plausible Analytics',
|
||||
baseImage: 'plausible/analytics',
|
||||
images: ['bitnami/postgresql:13.2.0', 'yandex/clickhouse-server:21.3.2.5'],
|
||||
versions: ['latest', 'stable'],
|
||||
recommendedVersion: 'stable',
|
||||
ports: {
|
||||
main: 8000
|
||||
}
|
||||
},
|
||||
{
|
||||
name: 'nocodb',
|
||||
fancyName: 'NocoDB',
|
||||
baseImage: 'nocodb/nocodb',
|
||||
versions: ['latest'],
|
||||
recommendedVersion: 'latest',
|
||||
ports: {
|
||||
main: 8080
|
||||
}
|
||||
},
|
||||
{
|
||||
name: 'minio',
|
||||
fancyName: 'MinIO',
|
||||
baseImage: 'minio/minio',
|
||||
versions: ['latest'],
|
||||
recommendedVersion: 'latest',
|
||||
ports: {
|
||||
main: 9001
|
||||
}
|
||||
},
|
||||
{
|
||||
name: 'vscodeserver',
|
||||
fancyName: 'VSCode Server',
|
||||
baseImage: 'codercom/code-server',
|
||||
versions: ['latest'],
|
||||
recommendedVersion: 'latest',
|
||||
ports: {
|
||||
main: 8080
|
||||
}
|
||||
},
|
||||
{
|
||||
name: 'wordpress',
|
||||
fancyName: 'Wordpress',
|
||||
baseImage: 'wordpress',
|
||||
images: ['bitnami/mysql:5.7'],
|
||||
versions: ['latest', 'php8.1', 'php8.0', 'php7.4', 'php7.3'],
|
||||
recommendedVersion: 'latest',
|
||||
ports: {
|
||||
main: 80
|
||||
}
|
||||
},
|
||||
{
|
||||
name: 'vaultwarden',
|
||||
fancyName: 'Vaultwarden',
|
||||
baseImage: 'vaultwarden/server',
|
||||
versions: ['latest'],
|
||||
recommendedVersion: 'latest',
|
||||
ports: {
|
||||
main: 80
|
||||
}
|
||||
},
|
||||
{
|
||||
name: 'languagetool',
|
||||
fancyName: 'LanguageTool',
|
||||
baseImage: 'silviof/docker-languagetool',
|
||||
versions: ['latest'],
|
||||
recommendedVersion: 'latest',
|
||||
ports: {
|
||||
main: 8010
|
||||
}
|
||||
},
|
||||
{
|
||||
name: 'n8n',
|
||||
fancyName: 'n8n',
|
||||
baseImage: 'n8nio/n8n',
|
||||
versions: ['latest'],
|
||||
recommendedVersion: 'latest',
|
||||
ports: {
|
||||
main: 5678
|
||||
}
|
||||
},
|
||||
{
|
||||
name: 'uptimekuma',
|
||||
fancyName: 'Uptime Kuma',
|
||||
baseImage: 'louislam/uptime-kuma',
|
||||
versions: ['latest'],
|
||||
recommendedVersion: 'latest',
|
||||
ports: {
|
||||
main: 3001
|
||||
}
|
||||
},
|
||||
{
|
||||
name: 'ghost',
|
||||
fancyName: 'Ghost',
|
||||
baseImage: 'bitnami/ghost',
|
||||
images: ['bitnami/mariadb'],
|
||||
versions: ['latest'],
|
||||
recommendedVersion: 'latest',
|
||||
ports: {
|
||||
main: 2368
|
||||
}
|
||||
},
|
||||
{
|
||||
name: 'meilisearch',
|
||||
fancyName: 'Meilisearch',
|
||||
baseImage: 'getmeili/meilisearch',
|
||||
images: [],
|
||||
versions: ['latest'],
|
||||
recommendedVersion: 'latest',
|
||||
ports: {
|
||||
main: 7700
|
||||
}
|
||||
}
|
||||
];
|
||||
|
||||
@@ -5,7 +5,13 @@ import { getDomain, removeDestinationDocker } from '$lib/common';
|
||||
import { prisma } from './common';
|
||||
|
||||
export async function listApplications(teamId) {
|
||||
return await prisma.application.findMany({ where: { teams: { some: { id: teamId } } } });
|
||||
if (teamId === '0') {
|
||||
return await prisma.application.findMany({ include: { teams: true } });
|
||||
}
|
||||
return await prisma.application.findMany({
|
||||
where: { teams: { some: { id: teamId } } },
|
||||
include: { teams: true }
|
||||
});
|
||||
}
|
||||
|
||||
export async function newApplication({ name, teamId }) {
|
||||
@@ -67,7 +73,11 @@ export async function removeApplication({ id, teamId }) {
|
||||
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 }) {
|
||||
@@ -130,16 +140,30 @@ export async function getApplicationById({ id }) {
|
||||
return { ...body };
|
||||
}
|
||||
export async function getApplication({ id, teamId }) {
|
||||
let body = await prisma.application.findFirst({
|
||||
where: { id, teams: { some: { id: teamId } } },
|
||||
include: {
|
||||
destinationDocker: true,
|
||||
settings: true,
|
||||
gitSource: { include: { githubApp: true, gitlabApp: true } },
|
||||
secrets: true,
|
||||
persistentStorage: true
|
||||
}
|
||||
});
|
||||
let body = {};
|
||||
if (teamId === '0') {
|
||||
body = await prisma.application.findFirst({
|
||||
where: { id },
|
||||
include: {
|
||||
destinationDocker: true,
|
||||
settings: true,
|
||||
gitSource: { include: { githubApp: true, gitlabApp: true } },
|
||||
secrets: true,
|
||||
persistentStorage: true
|
||||
}
|
||||
});
|
||||
} else {
|
||||
body = await prisma.application.findFirst({
|
||||
where: { id, teams: { some: { id: teamId } } },
|
||||
include: {
|
||||
destinationDocker: true,
|
||||
settings: true,
|
||||
gitSource: { include: { githubApp: true, gitlabApp: true } },
|
||||
secrets: true,
|
||||
persistentStorage: true
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if (body?.gitSource?.githubApp?.clientSecret) {
|
||||
body.gitSource.githubApp.clientSecret = decrypt(body.gitSource.githubApp.clientSecret);
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
import { dev } from '$app/env';
|
||||
import { sentry } from '$lib/common';
|
||||
import {
|
||||
supportedDatabaseTypesAndVersions,
|
||||
supportedServiceTypesAndVersions
|
||||
} from '$lib/components/common';
|
||||
import * as Prisma from '@prisma/client';
|
||||
import { default as ProdPrisma } from '@prisma/client';
|
||||
import type { PrismaClientOptions } from '@prisma/client/runtime';
|
||||
@@ -82,134 +86,6 @@ export async function generateSshKeyPair(): Promise<{ publicKey: string; private
|
||||
});
|
||||
}
|
||||
|
||||
export const supportedDatabaseTypesAndVersions = [
|
||||
{
|
||||
name: 'mongodb',
|
||||
fancyName: 'MongoDB',
|
||||
baseImage: 'bitnami/mongodb',
|
||||
versions: ['5.0.5', '4.4.11', '4.2.18', '4.0.27']
|
||||
},
|
||||
{ name: 'mysql', fancyName: 'MySQL', baseImage: 'bitnami/mysql', versions: ['8.0.27', '5.7.36'] },
|
||||
{
|
||||
name: 'postgresql',
|
||||
fancyName: 'PostgreSQL',
|
||||
baseImage: 'bitnami/postgresql',
|
||||
versions: ['14.1.0', '13.5.0', '12.9.0', '11.14.0', '10.19.0', '9.6.24']
|
||||
},
|
||||
{
|
||||
name: 'redis',
|
||||
fancyName: 'Redis',
|
||||
baseImage: 'bitnami/redis',
|
||||
versions: ['6.2.6', '6.0.16', '5.0.14']
|
||||
},
|
||||
{ name: 'couchdb', fancyName: 'CouchDB', baseImage: 'bitnami/couchdb', versions: ['3.2.1'] }
|
||||
];
|
||||
export const supportedServiceTypesAndVersions = [
|
||||
{
|
||||
name: 'plausibleanalytics',
|
||||
fancyName: 'Plausible Analytics',
|
||||
baseImage: 'plausible/analytics',
|
||||
images: ['bitnami/postgresql:13.2.0', 'yandex/clickhouse-server:21.3.2.5'],
|
||||
versions: ['latest'],
|
||||
ports: {
|
||||
main: 8000
|
||||
}
|
||||
},
|
||||
{
|
||||
name: 'nocodb',
|
||||
fancyName: 'NocoDB',
|
||||
baseImage: 'nocodb/nocodb',
|
||||
versions: ['latest'],
|
||||
ports: {
|
||||
main: 8080
|
||||
}
|
||||
},
|
||||
{
|
||||
name: 'minio',
|
||||
fancyName: 'MinIO',
|
||||
baseImage: 'minio/minio',
|
||||
versions: ['latest'],
|
||||
ports: {
|
||||
main: 9001
|
||||
}
|
||||
},
|
||||
{
|
||||
name: 'vscodeserver',
|
||||
fancyName: 'VSCode Server',
|
||||
baseImage: 'codercom/code-server',
|
||||
versions: ['latest'],
|
||||
ports: {
|
||||
main: 8080
|
||||
}
|
||||
},
|
||||
{
|
||||
name: 'wordpress',
|
||||
fancyName: 'Wordpress',
|
||||
baseImage: 'wordpress',
|
||||
images: ['bitnami/mysql:5.7'],
|
||||
versions: ['latest', 'php8.1', 'php8.0', 'php7.4', 'php7.3'],
|
||||
ports: {
|
||||
main: 80
|
||||
}
|
||||
},
|
||||
{
|
||||
name: 'vaultwarden',
|
||||
fancyName: 'Vaultwarden',
|
||||
baseImage: 'vaultwarden/server',
|
||||
versions: ['latest'],
|
||||
ports: {
|
||||
main: 80
|
||||
}
|
||||
},
|
||||
{
|
||||
name: 'languagetool',
|
||||
fancyName: 'LanguageTool',
|
||||
baseImage: 'silviof/docker-languagetool',
|
||||
versions: ['latest'],
|
||||
ports: {
|
||||
main: 8010
|
||||
}
|
||||
},
|
||||
{
|
||||
name: 'n8n',
|
||||
fancyName: 'n8n',
|
||||
baseImage: 'n8nio/n8n',
|
||||
versions: ['latest'],
|
||||
ports: {
|
||||
main: 5678
|
||||
}
|
||||
},
|
||||
{
|
||||
name: 'uptimekuma',
|
||||
fancyName: 'Uptime Kuma',
|
||||
baseImage: 'louislam/uptime-kuma',
|
||||
versions: ['latest'],
|
||||
ports: {
|
||||
main: 3001
|
||||
}
|
||||
},
|
||||
{
|
||||
name: 'ghost',
|
||||
fancyName: 'Ghost',
|
||||
baseImage: 'bitnami/ghost',
|
||||
images: ['bitnami/mariadb'],
|
||||
versions: ['latest'],
|
||||
ports: {
|
||||
main: 2368
|
||||
}
|
||||
},
|
||||
{
|
||||
name: 'meilisearch',
|
||||
fancyName: 'Meilisearch',
|
||||
baseImage: 'getmeili/meilisearch',
|
||||
images: [],
|
||||
versions: ['latest'],
|
||||
ports: {
|
||||
main: 7700
|
||||
}
|
||||
}
|
||||
];
|
||||
|
||||
export function getVersions(type) {
|
||||
const found = supportedDatabaseTypesAndVersions.find((t) => t.name === type);
|
||||
if (found) {
|
||||
|
||||
@@ -7,7 +7,14 @@ import getPort, { portNumbers } from 'get-port';
|
||||
import { asyncExecShell, getEngine, removeContainer } from '$lib/common';
|
||||
|
||||
export async function listDatabases(teamId) {
|
||||
return await prisma.database.findMany({ where: { teams: { some: { id: teamId } } } });
|
||||
if (teamId === '0') {
|
||||
return await prisma.database.findMany({ include: { teams: true } });
|
||||
} else {
|
||||
return await prisma.database.findMany({
|
||||
where: { teams: { some: { id: teamId } } },
|
||||
include: { teams: true }
|
||||
});
|
||||
}
|
||||
}
|
||||
export async function newDatabase({ name, teamId }) {
|
||||
const dbUser = cuid();
|
||||
@@ -31,10 +38,18 @@ export async function newDatabase({ name, teamId }) {
|
||||
}
|
||||
|
||||
export async function getDatabase({ id, teamId }) {
|
||||
const body = await prisma.database.findFirst({
|
||||
where: { id, teams: { some: { id: teamId } } },
|
||||
include: { destinationDocker: true, settings: true }
|
||||
});
|
||||
let body = {};
|
||||
if (teamId === '0') {
|
||||
body = await prisma.database.findFirst({
|
||||
where: { id },
|
||||
include: { destinationDocker: true, settings: true }
|
||||
});
|
||||
} else {
|
||||
body = await prisma.database.findFirst({
|
||||
where: { id, teams: { some: { id: teamId } } },
|
||||
include: { destinationDocker: true, settings: true }
|
||||
});
|
||||
}
|
||||
|
||||
if (body.dbUserPassword) body.dbUserPassword = decrypt(body.dbUserPassword);
|
||||
if (body.rootUserPassword) body.rootUserPassword = decrypt(body.rootUserPassword);
|
||||
@@ -122,3 +137,37 @@ export async function stopDatabase(database) {
|
||||
}
|
||||
return everStarted;
|
||||
}
|
||||
|
||||
export async function updatePasswordInDb(database, user, newPassword) {
|
||||
const {
|
||||
id,
|
||||
type,
|
||||
rootUser,
|
||||
rootUserPassword,
|
||||
dbUser,
|
||||
dbUserPassword,
|
||||
defaultDatabase,
|
||||
destinationDockerId,
|
||||
destinationDocker: { engine }
|
||||
} = database;
|
||||
if (destinationDockerId) {
|
||||
const host = getEngine(engine);
|
||||
if (type === 'mysql') {
|
||||
await asyncExecShell(
|
||||
`DOCKER_HOST=${host} docker exec ${id} mysql -u ${rootUser} -p${rootUserPassword} -e \"ALTER USER '${user}'@'%' IDENTIFIED WITH caching_sha2_password BY '${newPassword}';\"`
|
||||
);
|
||||
} else if (type === 'postgresql') {
|
||||
await asyncExecShell(
|
||||
`DOCKER_HOST=${host} docker exec ${id} psql postgresql://${dbUser}:${dbUserPassword}@${id}:5432/${defaultDatabase} -c "ALTER role ${user} WITH PASSWORD '${newPassword}'"`
|
||||
);
|
||||
} else if (type === 'mongodb') {
|
||||
await asyncExecShell(
|
||||
`DOCKER_HOST=${host} docker exec ${id} mongo 'mongodb://${rootUser}:${rootUserPassword}@${id}:27017/admin?readPreference=primary&ssl=false' --eval "db.changeUserPassword('${user}','${newPassword}')"`
|
||||
);
|
||||
} else if (type === 'redis') {
|
||||
await asyncExecShell(
|
||||
`DOCKER_HOST=${host} docker exec ${id} redis-cli -u redis://${dbUserPassword}@${id}:6379 --raw CONFIG SET requirepass ${newPassword}`
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,7 +6,13 @@ import { getDatabaseImage } from '.';
|
||||
import { prisma } from './common';
|
||||
|
||||
export async function listDestinations(teamId) {
|
||||
return await prisma.destinationDocker.findMany({ where: { teams: { some: { id: teamId } } } });
|
||||
if (teamId === '0') {
|
||||
return await prisma.destinationDocker.findMany({ include: { teams: true } });
|
||||
}
|
||||
return await prisma.destinationDocker.findMany({
|
||||
where: { teams: { some: { id: teamId } } },
|
||||
include: { teams: true }
|
||||
});
|
||||
}
|
||||
|
||||
export async function configureDestinationForService({ id, destinationId }) {
|
||||
@@ -38,9 +44,7 @@ export async function configureDestinationForDatabase({ id, destinationId }) {
|
||||
const host = getEngine(engine);
|
||||
if (type && version) {
|
||||
const baseImage = getDatabaseImage(type);
|
||||
asyncExecShell(
|
||||
`DOCKER_HOST=${host} docker pull ${baseImage}:${version} && echo "FROM ${baseImage}:${version}" | docker build --label coolify.image="true" -t "${baseImage}:${version}" -`
|
||||
);
|
||||
asyncExecShell(`DOCKER_HOST=${host} docker pull ${baseImage}:${version}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -124,12 +128,17 @@ export async function removeDestination({ id }) {
|
||||
}
|
||||
|
||||
export async function getDestination({ id, teamId }) {
|
||||
let destination = await prisma.destinationDocker.findFirst({
|
||||
where: { id, teams: { some: { id: teamId } } }
|
||||
});
|
||||
if (destination.remoteEngine) {
|
||||
destination.sshPrivateKey = decrypt(destination.sshPrivateKey);
|
||||
let destination = {};
|
||||
if (teamId === '0') {
|
||||
destination = await prisma.destinationDocker.findFirst({
|
||||
where: { id }
|
||||
});
|
||||
} else {
|
||||
destination = await prisma.destinationDocker.findFirst({
|
||||
where: { id, teams: { some: { id: teamId } } }
|
||||
});
|
||||
}
|
||||
|
||||
return destination;
|
||||
}
|
||||
export async function getDestinationByApplicationId({ id, teamId }) {
|
||||
|
||||
@@ -2,26 +2,26 @@ import { decrypt, encrypt } from '$lib/crypto';
|
||||
import { prisma } from './common';
|
||||
|
||||
export async function listSources(teamId) {
|
||||
if (teamId === '0') {
|
||||
return await prisma.gitSource.findMany({
|
||||
include: { githubApp: true, gitlabApp: true, teams: true }
|
||||
});
|
||||
}
|
||||
return await prisma.gitSource.findMany({
|
||||
where: { teams: { some: { id: teamId } } },
|
||||
include: { githubApp: true, gitlabApp: true }
|
||||
include: { githubApp: true, gitlabApp: true, teams: true }
|
||||
});
|
||||
}
|
||||
|
||||
export async function newSource({ name, teamId, type, htmlUrl, apiUrl, organization }) {
|
||||
export async function newSource({ teamId, name }) {
|
||||
return await prisma.gitSource.create({
|
||||
data: {
|
||||
teams: { connect: { id: teamId } },
|
||||
name,
|
||||
type,
|
||||
htmlUrl,
|
||||
apiUrl,
|
||||
organization
|
||||
teams: { connect: { id: teamId } }
|
||||
}
|
||||
});
|
||||
}
|
||||
export async function removeSource({ id }) {
|
||||
// TODO: Disconnect application with this sourceId! Maybe not needed?
|
||||
const source = await prisma.gitSource.delete({
|
||||
where: { id },
|
||||
include: { githubApp: true, gitlabApp: true }
|
||||
@@ -31,10 +31,18 @@ export async function removeSource({ id }) {
|
||||
}
|
||||
|
||||
export async function getSource({ id, teamId }) {
|
||||
let body = await prisma.gitSource.findFirst({
|
||||
where: { id, teams: { some: { id: teamId } } },
|
||||
include: { githubApp: true, gitlabApp: true }
|
||||
});
|
||||
let body = {};
|
||||
if (teamId === '0') {
|
||||
body = await prisma.gitSource.findFirst({
|
||||
where: { id },
|
||||
include: { githubApp: true, gitlabApp: true }
|
||||
});
|
||||
} else {
|
||||
body = await prisma.gitSource.findFirst({
|
||||
where: { id, teams: { some: { id: teamId } } },
|
||||
include: { githubApp: true, gitlabApp: true }
|
||||
});
|
||||
}
|
||||
if (body?.githubApp?.clientSecret)
|
||||
body.githubApp.clientSecret = decrypt(body.githubApp.clientSecret);
|
||||
if (body?.githubApp?.webhookSecret)
|
||||
@@ -43,8 +51,29 @@ export async function getSource({ id, teamId }) {
|
||||
if (body?.gitlabApp?.appSecret) body.gitlabApp.appSecret = decrypt(body.gitlabApp.appSecret);
|
||||
return body;
|
||||
}
|
||||
export async function addSource({ id, appId, teamId, oauthId, groupName, appSecret }) {
|
||||
export async function addGitHubSource({ id, teamId, type, name, htmlUrl, apiUrl }) {
|
||||
await prisma.gitSource.update({ where: { id }, data: { type, name, htmlUrl, apiUrl } });
|
||||
return await prisma.githubApp.create({
|
||||
data: {
|
||||
teams: { connect: { id: teamId } },
|
||||
gitSource: { connect: { id } }
|
||||
}
|
||||
});
|
||||
}
|
||||
export async function addGitLabSource({
|
||||
id,
|
||||
teamId,
|
||||
type,
|
||||
name,
|
||||
htmlUrl,
|
||||
apiUrl,
|
||||
oauthId,
|
||||
appId,
|
||||
appSecret,
|
||||
groupName
|
||||
}) {
|
||||
const encrptedAppSecret = encrypt(appSecret);
|
||||
await prisma.gitSource.update({ where: { id }, data: { type, apiUrl, htmlUrl, name } });
|
||||
return await prisma.gitlabApp.create({
|
||||
data: {
|
||||
teams: { connect: { id: teamId } },
|
||||
@@ -63,9 +92,9 @@ export async function configureGitsource({ id, gitSourceId }) {
|
||||
data: { gitSource: { connect: { id: gitSourceId } } }
|
||||
});
|
||||
}
|
||||
export async function updateGitsource({ id, name }) {
|
||||
export async function updateGitsource({ id, name, htmlUrl, apiUrl }) {
|
||||
return await prisma.gitSource.update({
|
||||
where: { id },
|
||||
data: { name }
|
||||
data: { name, htmlUrl, apiUrl }
|
||||
});
|
||||
}
|
||||
|
||||
@@ -5,7 +5,14 @@ import { generatePassword } from '.';
|
||||
import { prisma } from './common';
|
||||
|
||||
export async function listServices(teamId) {
|
||||
return await prisma.service.findMany({ where: { teams: { some: { id: teamId } } } });
|
||||
if (teamId === '0') {
|
||||
return await prisma.service.findMany({ include: { teams: true } });
|
||||
} else {
|
||||
return await prisma.service.findMany({
|
||||
where: { teams: { some: { id: teamId } } },
|
||||
include: { teams: true }
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
export async function newService({ name, teamId }) {
|
||||
@@ -13,19 +20,28 @@ export async function newService({ name, teamId }) {
|
||||
}
|
||||
|
||||
export async function getService({ id, teamId }) {
|
||||
const body = await prisma.service.findFirst({
|
||||
where: { id, teams: { some: { id: teamId } } },
|
||||
include: {
|
||||
destinationDocker: true,
|
||||
plausibleAnalytics: true,
|
||||
minio: true,
|
||||
vscodeserver: true,
|
||||
wordpress: true,
|
||||
ghost: true,
|
||||
serviceSecret: true,
|
||||
meiliSearch: true
|
||||
}
|
||||
});
|
||||
let body = {};
|
||||
const include = {
|
||||
destinationDocker: true,
|
||||
plausibleAnalytics: true,
|
||||
minio: true,
|
||||
vscodeserver: true,
|
||||
wordpress: true,
|
||||
ghost: true,
|
||||
serviceSecret: true,
|
||||
meiliSearch: true
|
||||
};
|
||||
if (teamId === '0') {
|
||||
body = await prisma.service.findFirst({
|
||||
where: { id },
|
||||
include
|
||||
});
|
||||
} else {
|
||||
body = await prisma.service.findFirst({
|
||||
where: { id, teams: { some: { id: teamId } } },
|
||||
include
|
||||
});
|
||||
}
|
||||
|
||||
if (body.plausibleAnalytics?.postgresqlPassword)
|
||||
body.plausibleAnalytics.postgresqlPassword = decrypt(
|
||||
@@ -59,8 +75,12 @@ export async function getService({ id, teamId }) {
|
||||
return s;
|
||||
});
|
||||
}
|
||||
if (body.wordpress?.ftpPassword) {
|
||||
body.wordpress.ftpPassword = decrypt(body.wordpress.ftpPassword);
|
||||
}
|
||||
const settings = await prisma.setting.findFirst();
|
||||
|
||||
return { ...body };
|
||||
return { ...body, settings };
|
||||
}
|
||||
|
||||
export async function configureServiceType({ id, type }) {
|
||||
@@ -200,18 +220,6 @@ export async function updatePlausibleAnalyticsService({ id, fqdn, email, usernam
|
||||
export async function updateService({ id, fqdn, name }) {
|
||||
return await prisma.service.update({ where: { id }, data: { fqdn, name } });
|
||||
}
|
||||
export async function updateLanguageToolService({ id, fqdn, name }) {
|
||||
return await prisma.service.update({ where: { id }, data: { fqdn, name } });
|
||||
}
|
||||
export async function updateMeiliSearchService({ id, fqdn, name }) {
|
||||
return await prisma.service.update({ where: { id }, data: { fqdn, name } });
|
||||
}
|
||||
export async function updateVaultWardenService({ id, fqdn, name }) {
|
||||
return await prisma.service.update({ where: { id }, data: { fqdn, name } });
|
||||
}
|
||||
export async function updateVsCodeServer({ id, fqdn, name }) {
|
||||
return await prisma.service.update({ where: { id }, data: { fqdn, name } });
|
||||
}
|
||||
export async function updateWordpress({ id, fqdn, name, mysqlDatabase, extraConfig }) {
|
||||
return await prisma.service.update({
|
||||
where: { id },
|
||||
|
||||
@@ -32,26 +32,42 @@ export async function login({ email, password, isLogin }) {
|
||||
if (users === 0) {
|
||||
await prisma.setting.update({ where: { id }, data: { isRegistrationEnabled: false } });
|
||||
// Create default network & start Coolify Proxy
|
||||
asyncExecShell(`docker network create --attachable coolify`)
|
||||
.then(() => {
|
||||
console.log('Network created');
|
||||
})
|
||||
.catch(() => {
|
||||
console.log('Network already exists.');
|
||||
});
|
||||
|
||||
startCoolifyProxy('/var/run/docker.sock')
|
||||
.then(() => {
|
||||
console.log('Coolify Proxy started.');
|
||||
})
|
||||
.catch((err) => {
|
||||
console.log(err);
|
||||
});
|
||||
await asyncExecShell(`docker network create --attachable coolify`);
|
||||
await startCoolifyProxy('/var/run/docker.sock');
|
||||
uid = '0';
|
||||
}
|
||||
|
||||
if (userFound) {
|
||||
if (userFound.type === 'email') {
|
||||
if (userFound.password === 'RESETME') {
|
||||
const hashedPassword = await hashPassword(password);
|
||||
if (userFound.updatedAt < new Date(Date.now() - 1000 * 60 * 10)) {
|
||||
await prisma.user.update({
|
||||
where: { email: userFound.email },
|
||||
data: { password: 'RESETTIMEOUT' }
|
||||
});
|
||||
throw {
|
||||
error: 'Password reset link has expired. Please request a new one.'
|
||||
};
|
||||
} else {
|
||||
await prisma.user.update({
|
||||
where: { email: userFound.email },
|
||||
data: { password: hashedPassword }
|
||||
});
|
||||
return {
|
||||
status: 200,
|
||||
headers: {
|
||||
'Set-Cookie': `teamId=${uid}; HttpOnly; Path=/; Max-Age=15778800;`
|
||||
},
|
||||
body: {
|
||||
userId: userFound.id,
|
||||
teamId: userFound.id,
|
||||
permission: userFound.permission,
|
||||
isAdmin: true
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
const passwordMatch = await bcrypt.compare(password, userFound.password);
|
||||
if (!passwordMatch) {
|
||||
throw {
|
||||
|
||||
@@ -6,6 +6,7 @@ import crypto from 'crypto';
|
||||
import * as db from '$lib/database';
|
||||
import { checkContainer, checkHAProxy } from '.';
|
||||
import { asyncExecShell, getDomain, getEngine } from '$lib/common';
|
||||
import { supportedServiceTypesAndVersions } from '$lib/components/common';
|
||||
|
||||
const url = dev ? 'http://localhost:5555' : 'http://coolify-haproxy:5555';
|
||||
|
||||
@@ -223,7 +224,7 @@ export async function configureHAProxy() {
|
||||
const { fqdn, id, type, destinationDocker, destinationDockerId, updatedAt } = service;
|
||||
if (destinationDockerId) {
|
||||
const { engine } = destinationDocker;
|
||||
const found = db.supportedServiceTypesAndVersions.find((a) => a.name === type);
|
||||
const found = supportedServiceTypesAndVersions.find((a) => a.name === type);
|
||||
if (found) {
|
||||
const port = found.ports.main;
|
||||
const publicPort = service[type]?.publicPort;
|
||||
|
||||
@@ -108,7 +108,7 @@ export async function stopTcpHttpProxy(destinationDocker, publicPort) {
|
||||
return error;
|
||||
}
|
||||
}
|
||||
export async function startTcpProxy(destinationDocker, id, publicPort, privatePort) {
|
||||
export async function startTcpProxy(destinationDocker, id, publicPort, privatePort, volume = null) {
|
||||
const { network, engine } = destinationDocker;
|
||||
const host = getEngine(engine);
|
||||
|
||||
@@ -123,7 +123,9 @@ export async function startTcpProxy(destinationDocker, id, publicPort, privatePo
|
||||
);
|
||||
const ip = JSON.parse(Config)[0].Gateway;
|
||||
return await asyncExecShell(
|
||||
`DOCKER_HOST=${host} docker run --restart always -e PORT=${publicPort} -e APP=${id} -e PRIVATE_PORT=${privatePort} --add-host 'host.docker.internal:host-gateway' --add-host 'host.docker.internal:${ip}' --network ${network} -p ${publicPort}:${publicPort} --name ${containerName} -d coollabsio/${defaultProxyImageTcp}`
|
||||
`DOCKER_HOST=${host} docker run --restart always -e PORT=${publicPort} -e APP=${id} -e PRIVATE_PORT=${privatePort} --add-host 'host.docker.internal:host-gateway' --add-host 'host.docker.internal:${ip}' --network ${network} -p ${publicPort}:${publicPort} --name ${containerName} ${
|
||||
volume ? `-v ${volume}` : ''
|
||||
} -d coollabsio/${defaultProxyImageTcp}`
|
||||
);
|
||||
}
|
||||
} catch (error) {
|
||||
|
||||
@@ -10,7 +10,7 @@ export default async function ({
|
||||
buildId,
|
||||
privateSshKey
|
||||
}): Promise<any> {
|
||||
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`);
|
||||
|
||||
@@ -3,7 +3,9 @@ import { checkContainer, reloadHaproxy } from '$lib/haproxy';
|
||||
import * as db from '$lib/database';
|
||||
import { dev } from '$app/env';
|
||||
import cuid from 'cuid';
|
||||
import fs from 'fs/promises';
|
||||
import getPort, { portNumbers } from 'get-port';
|
||||
import { supportedServiceTypesAndVersions } from '$lib/components/common';
|
||||
|
||||
export async function letsEncrypt(domain, id = null, isCoolify = false) {
|
||||
try {
|
||||
@@ -160,7 +162,7 @@ export async function generateSSLCerts() {
|
||||
type,
|
||||
destinationDocker: { engine }
|
||||
} = service;
|
||||
const found = db.supportedServiceTypesAndVersions.find((a) => a.name === type);
|
||||
const found = supportedServiceTypesAndVersions.find((a) => a.name === type);
|
||||
if (found) {
|
||||
const domain = getDomain(fqdn);
|
||||
const isHttps = fqdn.startsWith('https://');
|
||||
@@ -181,12 +183,41 @@ export async function generateSSLCerts() {
|
||||
if (isHttps) ssls.push({ domain, id: 'coolify', isCoolify: true });
|
||||
}
|
||||
if (ssls.length > 0) {
|
||||
const sslDir = dev ? '/tmp/ssl' : '/app/ssl';
|
||||
if (dev) {
|
||||
try {
|
||||
await asyncExecShell(`mkdir -p ${sslDir}`);
|
||||
} catch (error) {
|
||||
//
|
||||
}
|
||||
}
|
||||
const files = await fs.readdir(sslDir);
|
||||
let certificates = [];
|
||||
if (files.length > 0) {
|
||||
for (const file of files) {
|
||||
file.endsWith('.pem') && certificates.push(file.replace(/\.pem$/, ''));
|
||||
}
|
||||
}
|
||||
for (const ssl of ssls) {
|
||||
if (!dev) {
|
||||
console.log('Checking SSL for', ssl.domain);
|
||||
await letsEncrypt(ssl.domain, ssl.id, ssl.isCoolify);
|
||||
if (
|
||||
certificates.includes(ssl.domain) ||
|
||||
certificates.includes(ssl.domain.replace('www.', ''))
|
||||
) {
|
||||
console.log(`Certificate for ${ssl.domain} already exists`);
|
||||
} else {
|
||||
console.log('Generating SSL for', ssl.domain);
|
||||
await letsEncrypt(ssl.domain, ssl.id, ssl.isCoolify);
|
||||
}
|
||||
} else {
|
||||
console.log('Checking SSL for', ssl.domain);
|
||||
if (
|
||||
certificates.includes(ssl.domain) ||
|
||||
certificates.includes(ssl.domain.replace('www.', ''))
|
||||
) {
|
||||
console.log(`Certificate for ${ssl.domain} already exists`);
|
||||
} else {
|
||||
console.log('Generating SSL for', ssl.domain);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,12 +20,9 @@ import {
|
||||
setDefaultConfiguration
|
||||
} from '$lib/buildPacks/common';
|
||||
import yaml from 'js-yaml';
|
||||
import type { ComposeFile } from '$lib/types/composeFile';
|
||||
|
||||
export default async function (job) {
|
||||
/*
|
||||
Edge cases:
|
||||
1 - Change build pack and redeploy, what should happen?
|
||||
*/
|
||||
let {
|
||||
id: applicationId,
|
||||
repository,
|
||||
@@ -274,7 +271,7 @@ export default async function (job) {
|
||||
}
|
||||
};
|
||||
});
|
||||
const compose = {
|
||||
const composeFile: ComposeFile = {
|
||||
version: '3.8',
|
||||
services: {
|
||||
[imageId]: {
|
||||
@@ -283,7 +280,7 @@ export default async function (job) {
|
||||
volumes,
|
||||
env_file: envFound ? [`${workdir}/.env`] : [],
|
||||
networks: [docker.network],
|
||||
labels: labels,
|
||||
labels,
|
||||
depends_on: [],
|
||||
restart: 'always'
|
||||
}
|
||||
@@ -295,7 +292,7 @@ export default async function (job) {
|
||||
},
|
||||
volumes: Object.assign({}, ...composeVolumes)
|
||||
};
|
||||
await fs.writeFile(`${workdir}/docker-compose.yml`, yaml.dump(compose));
|
||||
await fs.writeFile(`${workdir}/docker-compose.yml`, yaml.dump(composeFile));
|
||||
await asyncExecShell(
|
||||
`DOCKER_HOST=${host} docker compose --project-directory ${workdir} up -d`
|
||||
);
|
||||
|
||||
53
src/lib/types/composeFile.ts
Normal file
53
src/lib/types/composeFile.ts
Normal file
@@ -0,0 +1,53 @@
|
||||
export type ComposeFile = {
|
||||
version: ComposerFileVersion;
|
||||
services: Record<string, ComposeFileService>;
|
||||
networks: Record<string, ComposeFileNetwork>;
|
||||
volumes?: Record<string, ComposeFileVolume>;
|
||||
};
|
||||
|
||||
export type ComposeFileService = {
|
||||
container_name: string;
|
||||
image?: string;
|
||||
networks: string[];
|
||||
environment?: Record<string, unknown>;
|
||||
volumes?: string[];
|
||||
ulimits?: unknown;
|
||||
labels?: string[];
|
||||
env_file?: string[];
|
||||
extra_hosts?: string[];
|
||||
restart: ComposeFileRestartOption;
|
||||
depends_on?: string[];
|
||||
command?: string;
|
||||
build?: {
|
||||
context: string;
|
||||
dockerfile: string;
|
||||
args?: Record<string, unknown>;
|
||||
};
|
||||
};
|
||||
|
||||
export type ComposerFileVersion =
|
||||
| '3.8'
|
||||
| '3.7'
|
||||
| '3.6'
|
||||
| '3.5'
|
||||
| '3.4'
|
||||
| '3.3'
|
||||
| '3.2'
|
||||
| '3.1'
|
||||
| '3.0'
|
||||
| '2.4'
|
||||
| '2.3'
|
||||
| '2.2'
|
||||
| '2.1'
|
||||
| '2.0';
|
||||
|
||||
export type ComposeFileRestartOption = 'no' | 'always' | 'on-failure' | 'unless-stopped';
|
||||
|
||||
export type ComposeFileNetwork = {
|
||||
external: boolean;
|
||||
};
|
||||
|
||||
export type ComposeFileVolume = {
|
||||
external?: boolean;
|
||||
name?: string;
|
||||
};
|
||||
Reference in New Issue
Block a user