From 1bd08cb2dbc6db33b61dd83ada4966405ab1c43d Mon Sep 17 00:00:00 2001 From: Andras Bacsai Date: Wed, 17 Aug 2022 10:18:38 +0200 Subject: [PATCH 01/19] fix: bots --- apps/ui/src/lib/store.ts | 10 ++++++++-- apps/ui/src/routes/applications/[id]/index.svelte | 3 ++- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/apps/ui/src/lib/store.ts b/apps/ui/src/lib/store.ts index 0656ada54..89e38b6b8 100644 --- a/apps/ui/src/lib/store.ts +++ b/apps/ui/src/lib/store.ts @@ -71,7 +71,8 @@ export const features = readable({ export const location: Writable = writable(null) export const setLocation = (resource: any, settings?: any) => { - if (resource.settings.isBot) { + if (resource.settings.isBot && resource.exposePort) { + disabledButton.set(false); return location.set(`http://${settings.ipv4}:${resource.exposePort}`) } if (GITPOD_WORKSPACE_URL && resource.exposePort) { @@ -84,7 +85,12 @@ export const setLocation = (resource: any, settings?: any) => { const newURL = `https://${CODESANDBOX_HOST.replace(/\$PORT/, resource.exposePort)}` return location.set(newURL) } - return location.set(resource.fqdn) + if (resource.fqdn) { + return location.set(resource.fqdn) + } else { + location.set(null); + disabledButton.set(true); + } } export const toasts: any = writable([]) diff --git a/apps/ui/src/routes/applications/[id]/index.svelte b/apps/ui/src/routes/applications/[id]/index.svelte index fbdeb43f8..baa74eb94 100644 --- a/apps/ui/src/routes/applications/[id]/index.svelte +++ b/apps/ui/src/routes/applications/[id]/index.svelte @@ -134,6 +134,7 @@ } if (name === 'isBot') { isBot = !isBot; + application.settings.isBot = isBot; setLocation(application, settings); } try { @@ -486,7 +487,7 @@ bind:setting={isBot} on:click={() => changeSettings('isBot')} title="Is your application a bot?" - description="You can deploy applications without domains.
They will listen on IP:PORT instead.

Useful for example bots." + description="You can deploy applications without domains.
They will listen on IP:EXPOSEDPORT instead.

Useful to host Twitch bots." /> {#if !isBot} From 727133e28b8626ac7fa86fcf23d90d9eed790c3a Mon Sep 17 00:00:00 2001 From: Andras Bacsai Date: Wed, 17 Aug 2022 10:43:57 +0200 Subject: [PATCH 02/19] feat: custom dns servers --- .../migration.sql | 2 + apps/api/prisma/schema.prisma | 1 + apps/api/src/lib/common.ts | 14 +- .../routes/api/v1/applications/handlers.ts | 2 +- apps/api/src/routes/api/v1/handlers.ts | 7 +- .../src/routes/api/v1/settings/handlers.ts | 9 +- apps/api/src/routes/api/v1/settings/types.ts | 3 +- apps/ui/src/lib/store.ts | 3 +- .../routes/applications/[id]/__layout.svelte | 64 +-- .../src/routes/applications/[id]/index.svelte | 20 +- apps/ui/src/routes/applications/index.svelte | 2 +- apps/ui/src/routes/index.svelte | 424 ++++++++++-------- apps/ui/src/routes/settings/global.svelte | 17 +- 13 files changed, 320 insertions(+), 248 deletions(-) create mode 100644 apps/api/prisma/migrations/20220817082342_custom_dns_servers/migration.sql diff --git a/apps/api/prisma/migrations/20220817082342_custom_dns_servers/migration.sql b/apps/api/prisma/migrations/20220817082342_custom_dns_servers/migration.sql new file mode 100644 index 000000000..03588b549 --- /dev/null +++ b/apps/api/prisma/migrations/20220817082342_custom_dns_servers/migration.sql @@ -0,0 +1,2 @@ +-- AlterTable +ALTER TABLE "Setting" ADD COLUMN "DNSServers" TEXT; diff --git a/apps/api/prisma/schema.prisma b/apps/api/prisma/schema.prisma index f67424a53..695478cef 100644 --- a/apps/api/prisma/schema.prisma +++ b/apps/api/prisma/schema.prisma @@ -20,6 +20,7 @@ model Setting { proxyHash String? isAutoUpdateEnabled Boolean @default(false) isDNSCheckEnabled Boolean @default(true) + DNSServers String? isTraefikUsed Boolean @default(true) createdAt DateTime @default(now()) updatedAt DateTime @updatedAt diff --git a/apps/api/src/lib/common.ts b/apps/api/src/lib/common.ts index 75ad6ff86..96921d82a 100644 --- a/apps/api/src/lib/common.ts +++ b/apps/api/src/lib/common.ts @@ -307,6 +307,10 @@ export async function checkDoubleBranch(branch: string, projectId: number): Prom } export async function isDNSValid(hostname: any, domain: string): Promise { const { isIP } = await import('is-ip'); + const { DNSServers } = await listSettings(); + if (DNSServers) { + dns.setServers([DNSServers]); + } let resolves = []; try { if (isIP(hostname)) { @@ -320,7 +324,6 @@ export async function isDNSValid(hostname: any, domain: string): Promise { try { let ipDomainFound = false; - dns.setServers(['1.1.1.1', '8.8.8.8']); const dnsResolve = await dns.resolve4(domain); if (dnsResolve.length > 0) { for (const ip of dnsResolve) { @@ -412,7 +415,12 @@ export async function checkDomainsIsValidInDNS({ hostname, fqdn, dualCerts }): P const { isIP } = await import('is-ip'); const domain = getDomain(fqdn); const domainDualCert = domain.includes('www.') ? domain.replace('www.', '') : `www.${domain}`; - dns.setServers(['1.1.1.1', '8.8.8.8']); + + const { DNSServers } = await listSettings(); + if (DNSServers) { + dns.setServers([DNSServers]); + } + let resolves = []; try { if (isIP(hostname)) { @@ -1553,7 +1561,7 @@ export async function configureServiceType({ }); } else if (type === 'appwrite') { const opensslKeyV1 = encrypt(generatePassword()); - const executorSecret = encrypt(generatePassword()); + const executorSecret = encrypt(generatePassword()); const redisPassword = encrypt(generatePassword()); const mariadbHost = `${id}-mariadb` const mariadbUser = cuid(); diff --git a/apps/api/src/routes/api/v1/applications/handlers.ts b/apps/api/src/routes/api/v1/applications/handlers.ts index cea2ca294..ce03c6e7c 100644 --- a/apps/api/src/routes/api/v1/applications/handlers.ts +++ b/apps/api/src/routes/api/v1/applications/handlers.ts @@ -18,7 +18,7 @@ export async function listApplications(request: FastifyRequest) { const { teamId } = request.user const applications = await prisma.application.findMany({ where: { teams: { some: { id: teamId === '0' ? undefined : teamId } } }, - include: { teams: true, destinationDocker: true } + include: { teams: true, destinationDocker: true, settings: true } }); const settings = await prisma.setting.findFirst() return { diff --git a/apps/api/src/routes/api/v1/handlers.ts b/apps/api/src/routes/api/v1/handlers.ts index 6d3112e97..ae558320e 100644 --- a/apps/api/src/routes/api/v1/handlers.ts +++ b/apps/api/src/routes/api/v1/handlers.ts @@ -4,7 +4,7 @@ import axios from 'axios'; import compare from 'compare-versions'; import cuid from 'cuid'; import bcrypt from 'bcryptjs'; -import { asyncExecShell, asyncSleep, cleanupDockerStorage, errorHandler, isDev, prisma, uniqueName, version } from '../../../lib/common'; +import { asyncExecShell, asyncSleep, cleanupDockerStorage, errorHandler, isDev, listSettings, prisma, uniqueName, version } from '../../../lib/common'; import type { FastifyReply, FastifyRequest } from 'fastify'; import type { Login, Update } from '.'; @@ -97,7 +97,8 @@ export async function showDashboard(request: FastifyRequest) { const userId = request.user.userId; const teamId = request.user.teamId; 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 } }); const databases = await prisma.database.findMany({ where: { teams: { some: { id: teamId === '0' ? undefined : teamId } } } @@ -105,10 +106,12 @@ export async function showDashboard(request: FastifyRequest) { const services = await prisma.service.findMany({ where: { teams: { some: { id: teamId === '0' ? undefined : teamId } } } }); + const settings = await listSettings(); return { applications, databases, services, + settings, }; } catch ({ status, message }) { return errorHandler({ status, message }) diff --git a/apps/api/src/routes/api/v1/settings/handlers.ts b/apps/api/src/routes/api/v1/settings/handlers.ts index 073dbd7e3..068d2c97e 100644 --- a/apps/api/src/routes/api/v1/settings/handlers.ts +++ b/apps/api/src/routes/api/v1/settings/handlers.ts @@ -33,12 +33,13 @@ export async function saveSettings(request: FastifyRequest, reply: minPort, maxPort, isAutoUpdateEnabled, - isDNSCheckEnabled + isDNSCheckEnabled, + DNSServers } = request.body const { id } = await listSettings(); await prisma.setting.update({ where: { id }, - data: { isRegistrationEnabled, dualCerts, isAutoUpdateEnabled, isDNSCheckEnabled } + data: { isRegistrationEnabled, dualCerts, isAutoUpdateEnabled, isDNSCheckEnabled, DNSServers } }); if (fqdn) { await prisma.setting.update({ where: { id }, data: { fqdn } }); @@ -54,6 +55,10 @@ export async function saveSettings(request: FastifyRequest, reply: export async function deleteDomain(request: FastifyRequest, reply: FastifyReply) { try { const { fqdn } = request.body + const { DNSServers } = await listSettings(); + if (DNSServers) { + dns.setServers([DNSServers]); + } let ip; try { ip = await dns.resolve(fqdn); diff --git a/apps/api/src/routes/api/v1/settings/types.ts b/apps/api/src/routes/api/v1/settings/types.ts index a33b614a4..d8fcf816d 100644 --- a/apps/api/src/routes/api/v1/settings/types.ts +++ b/apps/api/src/routes/api/v1/settings/types.ts @@ -8,7 +8,8 @@ export interface SaveSettings { minPort: number, maxPort: number, isAutoUpdateEnabled: boolean, - isDNSCheckEnabled: boolean + isDNSCheckEnabled: boolean, + DNSServers: string } } export interface DeleteDomain { diff --git a/apps/ui/src/lib/store.ts b/apps/ui/src/lib/store.ts index 89e38b6b8..7c851b96a 100644 --- a/apps/ui/src/lib/store.ts +++ b/apps/ui/src/lib/store.ts @@ -1,3 +1,4 @@ +import { dev } from '$app/env'; import cuid from 'cuid'; import { writable, readable, type Writable } from 'svelte/store'; @@ -73,7 +74,7 @@ export const location: Writable = writable(null) export const setLocation = (resource: any, settings?: any) => { if (resource.settings.isBot && resource.exposePort) { disabledButton.set(false); - return location.set(`http://${settings.ipv4}:${resource.exposePort}`) + return location.set(`http://${dev ? 'localhost' : settings.ipv4}:${resource.exposePort}`) } if (GITPOD_WORKSPACE_URL && resource.exposePort) { const { href } = new URL(GITPOD_WORKSPACE_URL); diff --git a/apps/ui/src/routes/applications/[id]/__layout.svelte b/apps/ui/src/routes/applications/[id]/__layout.svelte index 85f8001d2..3ec7107b7 100644 --- a/apps/ui/src/routes/applications/[id]/__layout.svelte +++ b/apps/ui/src/routes/applications/[id]/__layout.svelte @@ -141,8 +141,8 @@ if ( application.gitSourceId && application.destinationDockerId && - application.fqdn && - !application.settings.isBot + (application.fqdn || + application.settings.isBot) ) { await getStatus(); statusInterval = setInterval(async () => { @@ -409,37 +409,39 @@ - - + + + + + + + + + {/if} -
- changeSettings('previews')} - title={$t('application.enable_mr_pr_previews')} - description={$t('application.enable_preview_deploy_mr_pr_requests')} - /> -
+ {#if !application.settings.isBot} +
+ changeSettings('previews')} + title={$t('application.enable_mr_pr_previews')} + description={$t('application.enable_preview_deploy_mr_pr_requests')} + /> +
+ {/if}
Destination Missing
- {:else if !application.fqdn} + {:else if !application.fqdn && !application.settings.isBot}
URL Missing
diff --git a/apps/ui/src/routes/index.svelte b/apps/ui/src/routes/index.svelte index f28009843..63ae5fa47 100644 --- a/apps/ui/src/routes/index.svelte +++ b/apps/ui/src/routes/index.svelte @@ -20,35 +20,38 @@ -
+
Ghost
+
From 1627415ccad57f3c3c76ef166736e07f0150e7a4 Mon Sep 17 00:00:00 2001 From: Andras Bacsai Date: Wed, 17 Aug 2022 14:00:45 +0200 Subject: [PATCH 10/19] chore: version++ --- apps/api/src/lib/common.ts | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/api/src/lib/common.ts b/apps/api/src/lib/common.ts index bab76c725..f3c399eb5 100644 --- a/apps/api/src/lib/common.ts +++ b/apps/api/src/lib/common.ts @@ -17,7 +17,7 @@ import { checkContainer, removeContainer } from './docker'; import { day } from './dayjs'; import * as serviceFields from './serviceFields' -export const version = '3.5.1'; +export const version = '3.5.2'; export const isDev = process.env.NODE_ENV === 'development'; const algorithm = 'aes-256-ctr'; diff --git a/package.json b/package.json index 9f9423615..b8a7c62d0 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "coolify", "description": "An open-source & self-hostable Heroku / Netlify alternative.", - "version": "3.5.1", + "version": "3.5.2", "license": "Apache-2.0", "repository": "github:coollabsio/coolify", "scripts": { From 0c24134ac22b70c0833eefce73f81332f2c53c63 Mon Sep 17 00:00:00 2001 From: Andras Bacsai Date: Thu, 18 Aug 2022 11:53:42 +0200 Subject: [PATCH 11/19] feat: import public repos (wip) --- .../migration.sql | 42 ++++++ apps/api/prisma/schema.prisma | 22 ++-- apps/api/prisma/seed.js | 28 ++++ apps/api/src/lib/importers/github.ts | 1 - .../routes/api/v1/applications/handlers.ts | 39 ++++-- .../src/routes/api/v1/applications/types.ts | 2 +- .../configuration/_PublicRepository.svelte | 121 ++++++++++++++++++ .../[id]/configuration/buildpack.svelte | 3 +- .../[id]/configuration/repository.svelte | 1 + .../[id]/configuration/source.svelte | 5 + 10 files changed, 238 insertions(+), 26 deletions(-) create mode 100644 apps/api/prisma/migrations/20220818093615_public_repositories/migration.sql create mode 100644 apps/ui/src/routes/applications/[id]/configuration/_PublicRepository.svelte diff --git a/apps/api/prisma/migrations/20220818093615_public_repositories/migration.sql b/apps/api/prisma/migrations/20220818093615_public_repositories/migration.sql new file mode 100644 index 000000000..7f08c29fd --- /dev/null +++ b/apps/api/prisma/migrations/20220818093615_public_repositories/migration.sql @@ -0,0 +1,42 @@ +-- RedefineTables +PRAGMA foreign_keys=OFF; +CREATE TABLE "new_GitSource" ( + "id" TEXT NOT NULL PRIMARY KEY, + "name" TEXT NOT NULL, + "forPublic" BOOLEAN NOT NULL DEFAULT false, + "type" TEXT, + "apiUrl" TEXT, + "htmlUrl" TEXT, + "customPort" INTEGER NOT NULL DEFAULT 22, + "organization" TEXT, + "createdAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, + "updatedAt" DATETIME NOT NULL, + "githubAppId" TEXT, + "gitlabAppId" TEXT, + CONSTRAINT "GitSource_githubAppId_fkey" FOREIGN KEY ("githubAppId") REFERENCES "GithubApp" ("id") ON DELETE SET NULL ON UPDATE CASCADE, + CONSTRAINT "GitSource_gitlabAppId_fkey" FOREIGN KEY ("gitlabAppId") REFERENCES "GitlabApp" ("id") ON DELETE SET NULL ON UPDATE CASCADE +); +INSERT INTO "new_GitSource" ("apiUrl", "createdAt", "customPort", "githubAppId", "gitlabAppId", "htmlUrl", "id", "name", "organization", "type", "updatedAt") SELECT "apiUrl", "createdAt", "customPort", "githubAppId", "gitlabAppId", "htmlUrl", "id", "name", "organization", "type", "updatedAt" FROM "GitSource"; +DROP TABLE "GitSource"; +ALTER TABLE "new_GitSource" RENAME TO "GitSource"; +CREATE UNIQUE INDEX "GitSource_githubAppId_key" ON "GitSource"("githubAppId"); +CREATE UNIQUE INDEX "GitSource_gitlabAppId_key" ON "GitSource"("gitlabAppId"); +CREATE TABLE "new_ApplicationSettings" ( + "id" TEXT NOT NULL PRIMARY KEY, + "applicationId" TEXT NOT NULL, + "dualCerts" BOOLEAN NOT NULL DEFAULT false, + "debug" BOOLEAN NOT NULL DEFAULT false, + "previews" BOOLEAN NOT NULL DEFAULT false, + "autodeploy" BOOLEAN NOT NULL DEFAULT true, + "isBot" BOOLEAN NOT NULL DEFAULT false, + "isPublicRepository" BOOLEAN NOT NULL DEFAULT false, + "createdAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, + "updatedAt" DATETIME NOT NULL, + CONSTRAINT "ApplicationSettings_applicationId_fkey" FOREIGN KEY ("applicationId") REFERENCES "Application" ("id") ON DELETE RESTRICT ON UPDATE CASCADE +); +INSERT INTO "new_ApplicationSettings" ("applicationId", "autodeploy", "createdAt", "debug", "dualCerts", "id", "isBot", "previews", "updatedAt") SELECT "applicationId", "autodeploy", "createdAt", "debug", "dualCerts", "id", "isBot", "previews", "updatedAt" FROM "ApplicationSettings"; +DROP TABLE "ApplicationSettings"; +ALTER TABLE "new_ApplicationSettings" RENAME TO "ApplicationSettings"; +CREATE UNIQUE INDEX "ApplicationSettings_applicationId_key" ON "ApplicationSettings"("applicationId"); +PRAGMA foreign_key_check; +PRAGMA foreign_keys=ON; diff --git a/apps/api/prisma/schema.prisma b/apps/api/prisma/schema.prisma index 695478cef..6af0c4535 100644 --- a/apps/api/prisma/schema.prisma +++ b/apps/api/prisma/schema.prisma @@ -119,16 +119,17 @@ model Application { } model ApplicationSettings { - id String @id @default(cuid()) - applicationId String @unique - dualCerts Boolean @default(false) - debug Boolean @default(false) - previews Boolean @default(false) - autodeploy Boolean @default(true) - isBot Boolean @default(false) - createdAt DateTime @default(now()) - updatedAt DateTime @updatedAt - application Application @relation(fields: [applicationId], references: [id]) + id String @id @default(cuid()) + applicationId String @unique + dualCerts Boolean @default(false) + debug Boolean @default(false) + previews Boolean @default(false) + autodeploy Boolean @default(true) + isBot Boolean @default(false) + isPublicRepository Boolean @default(false) + createdAt DateTime @default(now()) + updatedAt DateTime @updatedAt + application Application @relation(fields: [applicationId], references: [id]) } model ApplicationPersistentStorage { @@ -238,6 +239,7 @@ model SshKey { model GitSource { id String @id @default(cuid()) name String + forPublic Boolean @default(false) type String? apiUrl String? htmlUrl String? diff --git a/apps/api/prisma/seed.js b/apps/api/prisma/seed.js index 96b55b105..9fa55136f 100644 --- a/apps/api/prisma/seed.js +++ b/apps/api/prisma/seed.js @@ -66,6 +66,34 @@ async function main() { } }); } + const github = await prisma.gitSource.findFirst({ + where: { htmlUrl: 'https://github.com', forPublic: true } + }); + const gitlab = await prisma.gitSource.findFirst({ + where: { htmlUrl: 'https://gitlab.com', forPublic: true } + }); + if (!github) { + await prisma.gitSource.create({ + data: { + apiUrl: 'https://api.github.com', + htmlUrl: 'https://github.com', + forPublic: true, + name: 'Github Public', + type: 'github' + } + }); + } + if (!gitlab) { + await prisma.gitSource.create({ + data: { + apiUrl: 'https://gitlab.com/api/v4', + htmlUrl: 'https://gitlab.com', + forPublic: true, + name: 'Gitlab Public', + type: 'gitlab' + } + }); + } } main() .catch((e) => { diff --git a/apps/api/src/lib/importers/github.ts b/apps/api/src/lib/importers/github.ts index bac460eca..afe1483a3 100644 --- a/apps/api/src/lib/importers/github.ts +++ b/apps/api/src/lib/importers/github.ts @@ -31,7 +31,6 @@ export default async function ({ const body = await prisma.githubApp.findUnique({ where: { id: githubAppId } }); if (body.privateKey) body.privateKey = decrypt(body.privateKey); const { privateKey, appId, installationId } = body - const githubPrivateKey = privateKey.replace(/\\n/g, '\n').replace(/"/g, ''); const payload = { diff --git a/apps/api/src/routes/api/v1/applications/handlers.ts b/apps/api/src/routes/api/v1/applications/handlers.ts index 5f0f2aa2d..0e2596f79 100644 --- a/apps/api/src/routes/api/v1/applications/handlers.ts +++ b/apps/api/src/routes/api/v1/applications/handlers.ts @@ -499,11 +499,21 @@ export async function deployApplication(request: FastifyRequest, reply: FastifyReply) { try { const { id } = request.params - const { gitSourceId } = request.body - await prisma.application.update({ - where: { id }, - data: { gitSource: { connect: { id: gitSourceId } } } - }); + const { gitSourceId, forPublic, type } = request.body + console.log({ id, gitSourceId, forPublic, type }) + if (forPublic) { + const publicGit = await prisma.gitSource.findFirst({ where: { type, forPublic } }); + await prisma.application.update({ + where: { id }, + data: { gitSource: { connect: { id: publicGit.id } } } + }); + } else { + await prisma.application.update({ + where: { id }, + data: { gitSource: { connect: { id: gitSourceId } } } + }); + } + return reply.code(201).send() } catch ({ status, message }) { return errorHandler({ status, message }) @@ -557,7 +567,7 @@ export async function checkRepository(request: FastifyRequest) export async function saveRepository(request, reply) { try { const { id } = request.params - let { repository, branch, projectId, autodeploy, webhookToken } = request.body + let { repository, branch, projectId, autodeploy, webhookToken, isPublicRepository = false } = request.body repository = repository.toLowerCase(); branch = branch.toLowerCase(); @@ -565,17 +575,19 @@ export async function saveRepository(request, reply) { if (webhookToken) { await prisma.application.update({ where: { id }, - data: { repository, branch, projectId, gitSource: { update: { gitlabApp: { update: { webhookToken: webhookToken ? webhookToken : undefined } } } }, settings: { update: { autodeploy } } } + data: { repository, branch, projectId, gitSource: { update: { gitlabApp: { update: { webhookToken: webhookToken ? webhookToken : undefined } } } }, settings: { update: { autodeploy, isPublicRepository } } } }); } else { await prisma.application.update({ where: { id }, - data: { repository, branch, projectId, settings: { update: { autodeploy } } } + data: { repository, branch, projectId, settings: { update: { autodeploy, isPublicRepository } } } }); } - const isDouble = await checkDoubleBranch(branch, projectId); - if (isDouble) { - await prisma.applicationSettings.updateMany({ where: { application: { branch, projectId } }, data: { autodeploy: false } }) + if (!isPublicRepository) { + const isDouble = await checkDoubleBranch(branch, projectId); + if (isDouble) { + await prisma.applicationSettings.updateMany({ where: { application: { branch, projectId } }, data: { autodeploy: false, isPublicRepository } }) + } } return reply.code(201).send() } catch ({ status, message }) { @@ -607,7 +619,8 @@ export async function getBuildPack(request) { projectId: application.projectId, repository: application.repository, branch: application.branch, - apiUrl: application.gitSource.apiUrl + apiUrl: application.gitSource.apiUrl, + isPublicRepository: application.settings.isPublicRepository } } catch ({ status, message }) { return errorHandler({ status, message }) @@ -658,7 +671,7 @@ export async function saveSecret(request: FastifyRequest, reply: Fas throw { status: 500, message: `Secret ${name} already exists.` } } else { value = encrypt(value.trim()); - console.log({value}) + console.log({ value }) await prisma.secret.create({ data: { name, value, isBuildSecret, isPRMRSecret, application: { connect: { id } } } }); diff --git a/apps/api/src/routes/api/v1/applications/types.ts b/apps/api/src/routes/api/v1/applications/types.ts index 1f06a37a8..f404e9bcb 100644 --- a/apps/api/src/routes/api/v1/applications/types.ts +++ b/apps/api/src/routes/api/v1/applications/types.ts @@ -50,7 +50,7 @@ export interface GetImages { Body: { buildPack: string, deploymentType: string } } export interface SaveApplicationSource extends OnlyId { - Body: { gitSourceId: string } + Body: { gitSourceId?: string | null, forPublic?: boolean, type?: string } } export interface CheckRepository extends OnlyId { Querystring: { repository: string, branch: string } diff --git a/apps/ui/src/routes/applications/[id]/configuration/_PublicRepository.svelte b/apps/ui/src/routes/applications/[id]/configuration/_PublicRepository.svelte new file mode 100644 index 000000000..a2543e381 --- /dev/null +++ b/apps/ui/src/routes/applications/[id]/configuration/_PublicRepository.svelte @@ -0,0 +1,121 @@ + + +
Public repository link
+ +
+ + + {#if branchSelectOptions.length > 0} +
+ + {#if isDisabled || application.settings.isPublicRepository} + {:else} {$t('application.git_repository')} - {#if isDisabled} - + {#if isDisabled || application.settings.isPublicRepository} + {:else} changeSettings('isBot')} title="Is your application a bot?" description="You can deploy applications without domains.
They will listen on IP:EXPOSEDPORT instead.

Useful to host Twitch bots." + disabled={$status.application.isRunning} />
{#if !isBot} @@ -770,15 +778,17 @@
{$t('application.features')}
-
- changeSettings('autodeploy')} - title={$t('application.enable_automatic_deployment')} - description={$t('application.enable_auto_deploy_webhooks')} - /> -
+ {#if !application.settings.isPublicRepository} +
+ changeSettings('autodeploy')} + title={$t('application.enable_automatic_deployment')} + description={$t('application.enable_auto_deploy_webhooks')} + /> +
+ {/if} {#if !application.settings.isBot}
-
- -
+ @@ -109,4 +107,7 @@
+
+ +
From 0922fd66a4807cd5d9688cdfcce207ad3f850469 Mon Sep 17 00:00:00 2001 From: Andras Bacsai Date: Thu, 18 Aug 2022 16:33:32 +0200 Subject: [PATCH 13/19] feat: force rebuild + env.PORT for port + public repo build --- apps/api/src/jobs/deployApplication.ts | 8 +- apps/api/src/lib/common.ts | 2 - apps/api/src/lib/docker.ts | 1 - .../routes/api/v1/applications/handlers.ts | 8 +- .../src/routes/api/v1/applications/types.ts | 5 +- .../routes/applications/[id]/__layout.svelte | 11 +- .../[id]/configuration/_BuildPack.svelte | 2 +- .../configuration/_PublicRepository.svelte | 209 +++++++++++----- .../[id]/configuration/buildpack.svelte | 1 - .../[id]/configuration/source.svelte | 231 +++++++++--------- .../src/routes/applications/[id]/index.svelte | 5 +- 11 files changed, 286 insertions(+), 197 deletions(-) diff --git a/apps/api/src/jobs/deployApplication.ts b/apps/api/src/jobs/deployApplication.ts index 4db0d5e26..9259e3976 100644 --- a/apps/api/src/jobs/deployApplication.ts +++ b/apps/api/src/jobs/deployApplication.ts @@ -56,6 +56,7 @@ import * as buildpacks from '../lib/buildPacks'; baseImage, baseBuildImage, deploymentType, + forceRebuild } = message let { branch, @@ -174,7 +175,6 @@ import * as buildpacks from '../lib/buildPacks'; if (!pullmergeRequestId) { - if (configHash !== currentHash) { deployNeeded = true; if (configHash) { @@ -198,6 +198,8 @@ import * as buildpacks from '../lib/buildPacks'; // } await copyBaseConfigurationFiles(buildPack, workdir, buildId, applicationId, baseImage); + + if (forceRebuild) deployNeeded = true if (!imageFound || deployNeeded) { // if (true) { if (buildpacks[buildPack]) @@ -248,7 +250,9 @@ import * as buildpacks from '../lib/buildPacks'; } catch (error) { // } - const envs = []; + const envs = [ + `PORT=${port}` + ]; if (secrets.length > 0) { secrets.forEach((secret) => { if (pullmergeRequestId) { diff --git a/apps/api/src/lib/common.ts b/apps/api/src/lib/common.ts index 78a23eb2b..9533b9473 100644 --- a/apps/api/src/lib/common.ts +++ b/apps/api/src/lib/common.ts @@ -1189,9 +1189,7 @@ export async function checkExposedPort({ id, configuredPort, exposePort, dockerI } } } else { - const availablePort = await getFreeExposedPort(id, exposePort, dockerId, remoteIpAddress); -console.log(availablePort, exposePort) if (availablePort.toString() !== exposePort.toString()) { throw { status: 500, message: `Port ${exposePort} is already in use.` } } diff --git a/apps/api/src/lib/docker.ts b/apps/api/src/lib/docker.ts index aa6a29cfd..c1ae977e5 100644 --- a/apps/api/src/lib/docker.ts +++ b/apps/api/src/lib/docker.ts @@ -71,7 +71,6 @@ export async function removeContainer({ }): Promise { try { const { stdout } = await executeDockerCmd({ dockerId, command: `docker inspect --format '{{json .State}}' ${id}` }) - console.log(id) if (JSON.parse(stdout).Running) { await executeDockerCmd({ dockerId, command: `docker stop -t 0 ${id}` }) await executeDockerCmd({ dockerId, command: `docker rm ${id}` }) diff --git a/apps/api/src/routes/api/v1/applications/handlers.ts b/apps/api/src/routes/api/v1/applications/handlers.ts index 7ddeb6b1c..57da91478 100644 --- a/apps/api/src/routes/api/v1/applications/handlers.ts +++ b/apps/api/src/routes/api/v1/applications/handlers.ts @@ -428,7 +428,7 @@ export async function deployApplication(request: FastifyRequest { @@ -256,7 +255,7 @@ -
+ handleDeploySubmit(true)}> - {#if branchSelectOptions.length > 0} -
- + {#if branchSelectOptions.length > 0} +
+ +
{/if}
From b76caabd32fc65dad471a3bda1359c779b910e1e Mon Sep 17 00:00:00 2001 From: Andras Bacsai Date: Thu, 18 Aug 2022 16:37:46 +0200 Subject: [PATCH 14/19] examples --- .../[id]/configuration/_PublicRepository.svelte | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/apps/ui/src/routes/applications/[id]/configuration/_PublicRepository.svelte b/apps/ui/src/routes/applications/[id]/configuration/_PublicRepository.svelte index b76c7da53..efad2263d 100644 --- a/apps/ui/src/routes/applications/[id]/configuration/_PublicRepository.svelte +++ b/apps/ui/src/routes/applications/[id]/configuration/_PublicRepository.svelte @@ -10,7 +10,7 @@ const { id } = $page.params; - let publicRepositoryLink: string = 'https://gitlab.com/aleveha/fastify-example'; + let publicRepositoryLink: string; let projectId: number; let repositoryName: string; let branchName: string; @@ -167,11 +167,12 @@ >
- + {#if branchSelectOptions.length > 0}
+ {#if branchSelectOptions.length > 0}