Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions web/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ BETTER_AUTH_SECRET=your-secret-key-here
ENCRYPTION_KEY=your-64-character-hex-string

# Public URL
APP_URL=https://your-domain.com
APP_URL=http://localhost:3000

# Logging (optional)
VICTORIA_LOGS_URL=http://username:password@victoria-logs:9428
Expand All @@ -25,10 +25,11 @@ VM_RETENTION=30d
# Docker Registry for builds (optional)
REGISTRY_HOST=registry.example.com

# Inngest (required for production)
INNGEST_BASE_URL=http://inngest:8288
INNGEST_SIGNING_KEY=signkey-xxx
INNGEST_EVENT_KEY=xxx
# Inngest (local dev via ../compose.dev.yml)
INNGEST_BASE_URL=http://localhost:8288
INNGEST_DEV=1
INNGEST_SIGNING_KEY=
INNGEST_EVENT_KEY=

# GitHub App Integration (optional)
GITHUB_APP_ID=your-github-app-id
Expand Down
3 changes: 3 additions & 0 deletions web/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,13 @@ Next.js-based control plane for Techulus Cloud container deployment platform.

```bash
pnpm install
cp .env.example .env
docker compose -f ../compose.dev.yml up -d
pnpm dev
```

Open [http://localhost:3000](http://localhost:3000) to access the control plane.
Open [http://localhost:8288](http://localhost:8288) to access the Inngest dev server.

## Stack

Expand Down
59 changes: 43 additions & 16 deletions web/lib/inngest/functions/rollout-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ export async function cleanupTerminalDeployments(

export async function cleanupExistingDeployments(
serviceId: string,
): Promise<void> {
): Promise<{ deletedCount: number }> {
const existingDeployments = await db
.select()
.from(deployments)
Expand All @@ -214,35 +214,55 @@ export async function cleanupExistingDeployments(
.where(eq(deploymentPorts.deploymentId, dep.id));
await db.delete(deployments).where(eq(deployments.id, dep.id));
}

return { deletedCount: existingDeployments.length };
}

export type CertificateProvisioningResult = {
domains: string[];
existingDomains: string[];
issuedDomains: string[];
failedDomains: string[];
};

export async function issueCertificatesForService(
serviceId: string,
): Promise<void> {
): Promise<CertificateProvisioningResult> {
const servicePortsList = await db
.select()
.from(servicePorts)
.where(eq(servicePorts.serviceId, serviceId));

const domainsNeedingCerts = servicePortsList
.filter((p) => p.isPublic && p.domain)
.map((p) => p.domain as string);
const domainsNeedingCerts = Array.from(
new Set(
servicePortsList
.filter((p) => p.isPublic && p.domain)
.map((p) => (p.domain as string).trim())
.filter(Boolean),
),
);

const existingDomains: string[] = [];
const issuedDomains: string[] = [];
const failedDomains: string[] = [];

for (const domain of domainsNeedingCerts) {
const existingCert = await getCertificate(domain);
if (!existingCert) {
try {
await issueCertificate(domain);
console.log(`[deploy] issued certificate for ${domain}`);
} catch (error) {
console.error(
`[deploy] failed to issue certificate for ${domain}:`,
error,
);
failedDomains.push(domain);
}
if (existingCert) {
existingDomains.push(domain);
continue;
}

try {
await issueCertificate(domain);
console.log(`[deploy] issued certificate for ${domain}`);
issuedDomains.push(domain);
} catch (error) {
console.error(
`[deploy] failed to issue certificate for ${domain}:`,
error,
);
failedDomains.push(domain);
}
}

Expand All @@ -251,6 +271,13 @@ export async function issueCertificatesForService(
`Certificate provisioning failed for: ${failedDomains.join(", ")}`,
);
}

return {
domains: domainsNeedingCerts,
existingDomains,
issuedDomains,
failedDomains,
};
}

export async function createDeploymentRecords(
Expand Down
50 changes: 29 additions & 21 deletions web/lib/inngest/functions/rollout-workflow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,13 +178,15 @@ export const rolloutWorkflow = inngest.createFunction(
});
} else {
await step.run("cleanup-existing", async () => {
await cleanupExistingDeployments(serviceId);
await ingestRolloutLog(
rolloutId,
serviceId,
"preparing",
"Cleaned up existing deployments",
);
const { deletedCount } = await cleanupExistingDeployments(serviceId);
if (deletedCount > 0) {
await ingestRolloutLog(
rolloutId,
serviceId,
"preparing",
`Cleaned up ${deletedCount} existing deployment(s)`,
);
}
});
}

Expand All @@ -194,13 +196,15 @@ export const rolloutWorkflow = inngest.createFunction(
.set({ currentStage: "certificates" })
.where(eq(rollouts.id, rolloutId));
try {
await issueCertificatesForService(serviceId);
await ingestRolloutLog(
rolloutId,
serviceId,
"certificates",
"Certificates issued",
);
const result = await issueCertificatesForService(serviceId);
if (result.issuedDomains.length > 0) {
await ingestRolloutLog(
rolloutId,
serviceId,
"certificates",
`Certificates issued for ${result.issuedDomains.length} domain(s)`,
);
}
return { success: true as const };
} catch (error) {
const message =
Expand Down Expand Up @@ -452,21 +456,25 @@ export const rolloutWorkflow = inngest.createFunction(

if (isRollingUpdate) {
await step.run("stop-old-deployments", async () => {
await db
const stoppedDeployments = await db
.update(deployments)
.set({ status: "stopping", desired: false })
.where(
and(
eq(deployments.serviceId, serviceId),
eq(deployments.status, "draining"),
),
)
.returning({ id: deployments.id });

if (stoppedDeployments.length > 0) {
await ingestRolloutLog(
rolloutId,
serviceId,
"dns_sync",
`Stopping ${stoppedDeployments.length} old deployment(s) after DNS sync`,
);
await ingestRolloutLog(
rolloutId,
serviceId,
"dns_sync",
"Stopping old deployments after DNS sync",
);
}
});
}

Expand Down
16 changes: 13 additions & 3 deletions web/lib/s3.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { DeleteObjectCommand, S3Client } from "@aws-sdk/client-s3";
import { getBackupStorageConfig } from "@/db/queries";

const DEFAULT_S3_DELETE_TIMEOUT_MS = 15000;
const DEFAULT_S3_DELETE_TIMEOUT_MS = 60000;

let cachedClient: S3Client | null = null;
let cachedConfigHash: string | null = null;
Expand All @@ -10,8 +10,18 @@ function hashConfig(config: {
region: string;
endpoint: string | null;
accessKey: string;
secretKey: string;
}): string {
return `${config.region}-${config.endpoint}-${config.accessKey}`;
return `${config.region}-${config.endpoint}-${config.accessKey}-${config.secretKey}`;
}

function getS3DeleteTimeoutMs(): number {
const configuredTimeout = Number(process.env.S3_DELETE_TIMEOUT_MS);
if (Number.isFinite(configuredTimeout) && configuredTimeout > 0) {
return configuredTimeout;
}

return DEFAULT_S3_DELETE_TIMEOUT_MS;
}

async function getS3Client(): Promise<S3Client | null> {
Expand Down Expand Up @@ -44,7 +54,7 @@ async function getS3Client(): Promise<S3Client | null> {
export async function deleteFromS3(
bucket: string,
key: string,
timeoutMs = DEFAULT_S3_DELETE_TIMEOUT_MS,
timeoutMs = getS3DeleteTimeoutMs(),
): Promise<void> {
const client = await getS3Client();
if (!client) {
Expand Down
6 changes: 0 additions & 6 deletions web/next.config.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
import type { NextConfig } from "next";

const allowedDevOrigins = (process.env.ALLOWED_DEV_ORIGINS ?? "")
.split(",")
.map((value) => value.trim())
.filter(Boolean);

const nextConfig: NextConfig = {
output: "standalone",
allowedDevOrigins,
};

export default nextConfig;
3 changes: 1 addition & 2 deletions web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"version": "0.1.0",
"private": true,
"scripts": {
"dev": "portless cloud --app-port 3000 next dev",
"dev": "next dev",
"build": "next build",
"start": "next start",
"test": "vitest run",
Expand Down Expand Up @@ -58,7 +58,6 @@
"drizzle-kit": "^0.31.8",
"eslint": "^9",
"eslint-config-next": "16.2.9",
"portless": "^0.13.0",
"tailwindcss": "^4",
"tsx": "^4.19.2",
"typescript": "^5",
Expand Down
11 changes: 0 additions & 11 deletions web/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading