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
3 changes: 1 addition & 2 deletions agent/internal/container/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,6 @@ func Deploy(config *DeployConfig) (*DeployResult, error) {

image := config.Image

exec.Command("podman", "rm", "-f", config.Name).Run()

logFunc("stdout", fmt.Sprintf("Pulling image: %s", image))

pullCmd := exec.Command("podman", "pull", "--tls-verify=false", image)
Expand All @@ -92,6 +90,7 @@ func Deploy(config *DeployConfig) (*DeployResult, error) {
}

args := buildPodmanRunArgs(config, image)
exec.Command("podman", "rm", "-f", config.Name).Run()

logFunc("stdout", fmt.Sprintf("Starting container: %s", config.Name))

Expand Down
3 changes: 0 additions & 3 deletions web/actions/projects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1161,9 +1161,6 @@ export async function updateServiceConfig(
if (config.ports) {
if (config.ports.remove && config.ports.remove.length > 0) {
for (const portId of config.ports.remove) {
await db
.delete(deploymentPorts)
.where(eq(deploymentPorts.servicePortId, portId));
await db.delete(servicePorts).where(eq(servicePorts.id, portId));
}
}
Expand Down
45 changes: 39 additions & 6 deletions web/app/api/projects/[id]/services/route.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export const dynamic = "force-dynamic";

import { and, desc, eq, isNull } from "drizzle-orm";
import { and, desc, eq, inArray, isNull } from "drizzle-orm";
import { headers } from "next/headers";
import { db } from "@/db";
import {
Expand All @@ -12,12 +12,14 @@ import {
servers,
servicePorts,
serviceReplicas,
serviceRevisions,
services,
serviceVolumes,
volumeBackups,
} from "@/db/schema";
import { auth } from "@/lib/auth";
import { getTimestamp } from "@/lib/date";
import { revisionSpecToDeployedConfig } from "@/lib/service-config";

export async function GET(
request: Request,
Expand Down Expand Up @@ -114,20 +116,50 @@ export async function GET(
: Promise.resolve(null),
]);

const activeDeployment = serviceDeployments.find(
(deployment) =>
deployment.trafficState === "active" &&
deployment.runtimeDesiredState !== "removed",
);
const activeRevision = activeDeployment
? await db
.select({ specification: serviceRevisions.specification })
.from(serviceRevisions)
.where(eq(serviceRevisions.id, activeDeployment.serviceRevisionId))
.then((rows) => rows[0])
: null;
const revisionServers = activeRevision
? await db
.select({ id: servers.id, name: servers.name })
.from(servers)
.where(
inArray(
servers.id,
activeRevision.specification.placements.map(
(placement) => placement.serverId,
),
),
)
: [];
const activeConfig = activeRevision
? revisionSpecToDeployedConfig(
activeRevision.specification,
Object.fromEntries(
revisionServers.map((server) => [server.id, server.name]),
),
)
: null;

const deploymentsWithDetails = await Promise.all(
serviceDeployments.map(async (deployment) => {
const [depPorts, server] = await Promise.all([
db
.select({
id: deploymentPorts.id,
hostPort: deploymentPorts.hostPort,
containerPort: servicePorts.port,
containerPort: deploymentPorts.containerPort,
})
.from(deploymentPorts)
.innerJoin(
servicePorts,
eq(deploymentPorts.servicePortId, servicePorts.id),
)
.where(eq(deploymentPorts.deploymentId, deployment.id)),
db
.select({ name: servers.name, wireguardIp: servers.wireguardIp })
Expand Down Expand Up @@ -205,6 +237,7 @@ export async function GET(
volumes,
lockedServer,
latestBuild,
activeConfig,
deletionBackupFallback,
};
}),
Expand Down
8 changes: 2 additions & 6 deletions web/components/service/service-layout-client.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,7 @@ import useSWR from "swr";
import type { ServiceWithDetails as Service } from "@/db/types";
import { fetcher } from "@/lib/fetcher";
import type { ConfigChange } from "@/lib/service-config";
import {
buildCurrentConfig,
diffConfigs,
parseDeployedConfig,
} from "@/lib/service-config";
import { buildCurrentConfig, diffConfigs } from "@/lib/service-config";
import { cn } from "@/lib/utils";

const ACTIVE_BUILD_STATUSES = [
Expand Down Expand Up @@ -77,7 +73,7 @@ export function ServiceLayoutClient({
const pendingChanges = useMemo(() => {
if (!service) return [];

const deployed = parseDeployedConfig(service.deployedConfig);
const deployed = service.activeConfig ?? null;
const replicas = (service.configuredReplicas || []).map((r) => ({
serverId: r.serverId,
serverName: r.serverName,
Expand Down
49 changes: 44 additions & 5 deletions web/db/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,18 @@ import { relations, sql } from "drizzle-orm";
import {
bigint,
boolean,
foreignKey,
index,
integer,
jsonb,
pgTable,
real,
text,
timestamp,
unique,
uniqueIndex,
} from "drizzle-orm/pg-core";
import type { ServiceRevisionSpec } from "@/lib/service-revision-spec";

export const user = pgTable("user", {
id: text("id").primaryKey(),
Expand Down Expand Up @@ -417,7 +420,6 @@ export const services = pgTable("services", {
serverlessWakeTimeoutSeconds: integer("serverless_wake_timeout_seconds")
.notNull()
.default(300),
deployedConfig: text("deployed_config"),
deploymentSchedule: text("deployment_schedule"),
lastScheduledDeploymentRunAt: timestamp("last_scheduled_deployment_run_at", {
withTimezone: true,
Expand Down Expand Up @@ -547,13 +549,37 @@ export const secrets = pgTable("secrets", {
.notNull(),
});

export const serviceRevisions = pgTable(
"service_revisions",
{
id: text("id").primaryKey(),
serviceId: text("service_id")
.notNull()
.references(() => services.id, { onDelete: "cascade" }),
specification: jsonb("specification")
.$type<ServiceRevisionSpec>()
.notNull(),
createdAt: timestamp("created_at", { withTimezone: true })
.defaultNow()
.notNull(),
},
(table) => [
unique("service_revisions_id_service_id_unique").on(
table.id,
table.serviceId,
),
index("service_revisions_service_id_idx").on(table.serviceId),
],
);

export const deployments = pgTable(
"deployments",
{
id: text("id").primaryKey(),
serviceId: text("service_id")
.notNull()
.references(() => services.id, { onDelete: "cascade" }),
serviceRevisionId: text("service_revision_id").notNull(),
serverId: text("server_id")
.notNull()
.references(() => servers.id, { onDelete: "cascade" }),
Expand Down Expand Up @@ -611,12 +637,18 @@ export const deployments = pgTable(
index("deployments_container_id_idx").on(table.containerId),
index("deployments_rollout_id_idx").on(table.rolloutId),
index("deployments_service_id_idx").on(table.serviceId),
index("deployments_service_revision_id_idx").on(table.serviceRevisionId),
index("deployments_server_id_idx").on(table.serverId),
index("deployments_runtime_desired_state_idx").on(
table.runtimeDesiredState,
),
index("deployments_traffic_state_idx").on(table.trafficState),
index("deployments_observed_phase_idx").on(table.observedPhase),
foreignKey({
name: "deployments_service_revision_service_fk",
columns: [table.serviceRevisionId, table.serviceId],
foreignColumns: [serviceRevisions.id, serviceRevisions.serviceId],
}).onDelete("no action"),
],
);

Expand All @@ -627,6 +659,7 @@ export const rollouts = pgTable(
serviceId: text("service_id")
.notNull()
.references(() => services.id, { onDelete: "cascade" }),
serviceRevisionId: text("service_revision_id"),
status: text("status", {
enum: ["queued", "in_progress", "completed", "failed", "rolled_back"],
})
Expand All @@ -638,17 +671,23 @@ export const rollouts = pgTable(
.notNull(),
completedAt: timestamp("completed_at", { withTimezone: true }),
},
(table) => [index("rollouts_service_id_idx").on(table.serviceId)],
(table) => [
index("rollouts_service_id_idx").on(table.serviceId),
index("rollouts_service_revision_id_idx").on(table.serviceRevisionId),
foreignKey({
name: "rollouts_service_revision_service_fk",
columns: [table.serviceRevisionId, table.serviceId],
foreignColumns: [serviceRevisions.id, serviceRevisions.serviceId],
}).onDelete("no action"),
],
);

export const deploymentPorts = pgTable("deployment_ports", {
id: text("id").primaryKey(),
deploymentId: text("deployment_id")
.notNull()
.references(() => deployments.id, { onDelete: "cascade" }),
servicePortId: text("service_port_id")
.notNull()
.references(() => servicePorts.id, { onDelete: "cascade" }),
containerPort: integer("container_port").notNull(),
hostPort: integer("host_port").notNull(),
createdAt: timestamp("created_at", { withTimezone: true })
.defaultNow()
Expand Down
2 changes: 2 additions & 0 deletions web/db/types.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type { DeployedConfig } from "@/lib/service-config";
import type {
builds,
deploymentPorts,
Expand Down Expand Up @@ -54,6 +55,7 @@ export type HealthStats = {
};

export type ServiceWithDetails = Service & {
activeConfig?: DeployedConfig | null;
ports: ServicePort[];
configuredReplicas: Array<
ServiceReplica & { serverName: string; serverIsProxy: boolean }
Expand Down
Loading
Loading