Skip to content

Commit 5360c60

Browse files
authored
Merge pull request coollabsio#565 from coollabsio/next
v3.8.2
2 parents ac40abb + f60c640 commit 5360c60

File tree

33 files changed

+1155
-1362
lines changed

33 files changed

+1155
-1362
lines changed

apps/api/package.json

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,13 @@
2222
"@fastify/jwt": "6.3.2",
2323
"@fastify/static": "6.5.0",
2424
"@iarna/toml": "2.2.5",
25+
"@ladjs/graceful": "3.0.2",
2526
"@prisma/client": "3.15.2",
2627
"axios": "0.27.2",
2728
"bcryptjs": "2.4.3",
2829
"bree": "9.1.2",
2930
"cabin": "9.1.2",
30-
"compare-versions": "4.1.3",
31+
"compare-versions": "4.1.4",
3132
"cuid": "2.1.8",
3233
"dayjs": "1.11.5",
3334
"dockerode": "3.3.4",
@@ -43,17 +44,18 @@
4344
"jsonwebtoken": "8.5.1",
4445
"node-forge": "1.3.1",
4546
"node-os-utils": "1.3.7",
46-
"p-queue": "7.3.0",
47+
"p-all": "4.0.0",
48+
"p-throttle": "5.0.0",
4749
"public-ip": "6.0.1",
4850
"ssh-config": "4.1.6",
4951
"strip-ansi": "7.0.1",
5052
"unique-names-generator": "4.7.1"
5153
},
5254
"devDependencies": {
53-
"@types/node": "18.7.11",
55+
"@types/node": "18.7.13",
5456
"@types/node-os-utils": "1.3.0",
55-
"@typescript-eslint/eslint-plugin": "5.34.0",
56-
"@typescript-eslint/parser": "5.34.0",
57+
"@typescript-eslint/eslint-plugin": "5.35.1",
58+
"@typescript-eslint/parser": "5.35.1",
5759
"esbuild": "0.15.5",
5860
"eslint": "8.22.0",
5961
"eslint-config-prettier": "8.5.0",
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
-- RedefineTables
2+
PRAGMA foreign_keys=OFF;
3+
CREATE TABLE "new_Setting" (
4+
"id" TEXT NOT NULL PRIMARY KEY,
5+
"fqdn" TEXT,
6+
"isRegistrationEnabled" BOOLEAN NOT NULL DEFAULT false,
7+
"dualCerts" BOOLEAN NOT NULL DEFAULT false,
8+
"minPort" INTEGER NOT NULL DEFAULT 9000,
9+
"maxPort" INTEGER NOT NULL DEFAULT 9100,
10+
"proxyPassword" TEXT NOT NULL,
11+
"proxyUser" TEXT NOT NULL,
12+
"proxyHash" TEXT,
13+
"isAutoUpdateEnabled" BOOLEAN NOT NULL DEFAULT false,
14+
"isDNSCheckEnabled" BOOLEAN NOT NULL DEFAULT true,
15+
"DNSServers" TEXT,
16+
"isTraefikUsed" BOOLEAN NOT NULL DEFAULT true,
17+
"createdAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
18+
"updatedAt" DATETIME NOT NULL,
19+
"ipv4" TEXT,
20+
"ipv6" TEXT,
21+
"arch" TEXT,
22+
"concurrentBuilds" INTEGER NOT NULL DEFAULT 1
23+
);
24+
INSERT INTO "new_Setting" ("DNSServers", "arch", "createdAt", "dualCerts", "fqdn", "id", "ipv4", "ipv6", "isAutoUpdateEnabled", "isDNSCheckEnabled", "isRegistrationEnabled", "isTraefikUsed", "maxPort", "minPort", "proxyHash", "proxyPassword", "proxyUser", "updatedAt") SELECT "DNSServers", "arch", "createdAt", "dualCerts", "fqdn", "id", "ipv4", "ipv6", "isAutoUpdateEnabled", "isDNSCheckEnabled", "isRegistrationEnabled", "isTraefikUsed", "maxPort", "minPort", "proxyHash", "proxyPassword", "proxyUser", "updatedAt" FROM "Setting";
25+
DROP TABLE "Setting";
26+
ALTER TABLE "new_Setting" RENAME TO "Setting";
27+
CREATE UNIQUE INDEX "Setting_fqdn_key" ON "Setting"("fqdn");
28+
PRAGMA foreign_key_check;
29+
PRAGMA foreign_keys=ON;
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
-- RedefineTables
2+
PRAGMA foreign_keys=OFF;
3+
CREATE TABLE "new_Build" (
4+
"id" TEXT NOT NULL PRIMARY KEY,
5+
"type" TEXT NOT NULL,
6+
"applicationId" TEXT,
7+
"destinationDockerId" TEXT,
8+
"gitSourceId" TEXT,
9+
"githubAppId" TEXT,
10+
"gitlabAppId" TEXT,
11+
"commit" TEXT,
12+
"pullmergeRequestId" TEXT,
13+
"forceRebuild" BOOLEAN NOT NULL DEFAULT false,
14+
"sourceBranch" TEXT,
15+
"branch" TEXT,
16+
"status" TEXT DEFAULT 'queued',
17+
"createdAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
18+
"updatedAt" DATETIME NOT NULL
19+
);
20+
INSERT INTO "new_Build" ("applicationId", "branch", "commit", "createdAt", "destinationDockerId", "gitSourceId", "githubAppId", "gitlabAppId", "id", "status", "type", "updatedAt") SELECT "applicationId", "branch", "commit", "createdAt", "destinationDockerId", "gitSourceId", "githubAppId", "gitlabAppId", "id", "status", "type", "updatedAt" FROM "Build";
21+
DROP TABLE "Build";
22+
ALTER TABLE "new_Build" RENAME TO "Build";
23+
PRAGMA foreign_key_check;
24+
PRAGMA foreign_keys=ON;

apps/api/prisma/schema.prisma

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ model Setting {
2727
ipv4 String?
2828
ipv6 String?
2929
arch String?
30+
concurrentBuilds Int @default(1)
3031
}
3132

3233
model User {
@@ -197,6 +198,9 @@ model Build {
197198
githubAppId String?
198199
gitlabAppId String?
199200
commit String?
201+
pullmergeRequestId String?
202+
forceRebuild Boolean @default(false)
203+
sourceBranch String?
200204
branch String?
201205
status String? @default("queued")
202206
createdAt DateTime @default(now())

apps/api/src/index.ts

Lines changed: 34 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,10 @@ import env from '@fastify/env';
55
import cookie from '@fastify/cookie';
66
import path, { join } from 'path';
77
import autoLoad from '@fastify/autoload';
8-
import { asyncExecShell, isDev, listSettings, prisma, version } from './lib/common';
8+
import { asyncExecShell, asyncSleep, isDev, listSettings, prisma, version } from './lib/common';
99
import { scheduler } from './lib/scheduler';
10-
import axios from 'axios';
1110
import compareVersions from 'compare-versions';
12-
11+
import Graceful from '@ladjs/graceful'
1312
declare module 'fastify' {
1413
interface FastifyInstance {
1514
config: {
@@ -104,49 +103,39 @@ fastify.listen({ port, host }, async (err: any, address: any) => {
104103
}
105104
console.log(`Coolify's API is listening on ${host}:${port}`);
106105
await initServer();
107-
await scheduler.start('deployApplication');
108-
await scheduler.start('cleanupStorage');
109-
await scheduler.start('cleanupPrismaEngines');
110-
await scheduler.start('checkProxies');
111-
112-
// Check if no build is running
113106

114-
// Check for update
107+
const graceful = new Graceful({ brees: [scheduler] });
108+
graceful.listen();
109+
115110
setInterval(async () => {
116-
const { isAutoUpdateEnabled } = await prisma.setting.findFirst();
117-
if (isAutoUpdateEnabled) {
118-
const currentVersion = version;
119-
const { data: versions } = await axios
120-
.get(
121-
`https://get.coollabs.io/versions.json`
122-
, {
123-
params: {
124-
appId: process.env['COOLIFY_APP_ID'] || undefined,
125-
version: currentVersion
126-
}
127-
})
128-
const latestVersion = versions['coolify'].main.version;
129-
const isUpdateAvailable = compareVersions(latestVersion, currentVersion);
130-
if (isUpdateAvailable === 1) {
131-
if (scheduler.workers.has('deployApplication')) {
132-
scheduler.workers.get('deployApplication').postMessage("status:autoUpdater");
133-
}
134-
}
111+
if (!scheduler.workers.has('deployApplication')) {
112+
scheduler.run('deployApplication');
135113
}
114+
if (!scheduler.workers.has('infrastructure')) {
115+
scheduler.run('infrastructure');
116+
}
117+
}, 2000)
118+
119+
// autoUpdater
120+
setInterval(async () => {
121+
scheduler.workers.has('infrastructure') && scheduler.workers.get('infrastructure').postMessage("action:autoUpdater")
136122
}, isDev ? 5000 : 60000 * 15)
137123

138-
// Cleanup storage
124+
// cleanupStorage
139125
setInterval(async () => {
140-
if (scheduler.workers.has('deployApplication')) {
141-
scheduler.workers.get('deployApplication').postMessage("status:cleanupStorage");
142-
}
143-
}, isDev ? 5000 : 60000 * 10)
126+
scheduler.workers.has('infrastructure') && scheduler.workers.get('infrastructure').postMessage("action:cleanupStorage")
127+
}, isDev ? 6000 : 60000 * 10)
128+
129+
// checkProxies
130+
setInterval(async () => {
131+
scheduler.workers.has('infrastructure') && scheduler.workers.get('infrastructure').postMessage("action:checkProxies")
132+
}, 10000)
133+
134+
// cleanupPrismaEngines
135+
// setInterval(async () => {
136+
// scheduler.workers.has('infrastructure') && scheduler.workers.get('infrastructure').postMessage("action:cleanupPrismaEngines")
137+
// }, 60000)
144138

145-
scheduler.on('worker deleted', async (name) => {
146-
if (name === 'autoUpdater' || name === 'cleanupStorage') {
147-
if (!scheduler.workers.has('deployApplication')) await scheduler.start('deployApplication');
148-
}
149-
});
150139
await getArch();
151140
await getIPAddress();
152141
});
@@ -170,6 +159,12 @@ async function initServer() {
170159
try {
171160
await asyncExecShell(`docker network create --attachable coolify`);
172161
} catch (error) { }
162+
try {
163+
const isOlder = compareVersions('3.8.1', version);
164+
if (isOlder === -1) {
165+
await prisma.build.updateMany({ where: { status: { in: ['running', 'queued'] } }, data: { status: 'failed' } });
166+
}
167+
} catch (error) { }
173168
}
174169
async function getArch() {
175170
try {

apps/api/src/jobs/autoUpdater.ts

Lines changed: 0 additions & 43 deletions
This file was deleted.

apps/api/src/jobs/checkProxies.ts

Lines changed: 0 additions & 96 deletions
This file was deleted.

apps/api/src/jobs/cleanupPrismaEngines.ts

Lines changed: 0 additions & 19 deletions
This file was deleted.

0 commit comments

Comments
 (0)