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
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const statusBadgeVariants = cva(
enabled: "text-successA-11 bg-successA-3",
disabled: "text-warningA-11 bg-warningA-3",
live: "text-feature-11 bg-feature-4",
rolledBack: "text-warningA-11 bg-warningA-2",
rolledBack: "text-warningA-11 bg-warningA-4",
},
},
defaultVariants: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export const DeploymentsList = () => {
} | null>(null);
const isCompactView = useIsMobile({ breakpoint: COMPACT_BREAKPOINT });

const { liveDeployment, deployments } = useDeployments();
const { liveDeployment, deployments, project } = useDeployments();

const columns: Column<{
deployment: Deployment;
Expand All @@ -60,7 +60,7 @@ export const DeploymentsList = () => {
headerClassName: "pl-[18px]",
render: ({ deployment, environment }) => {
const isLive = liveDeployment?.id === deployment.id;
const isRolledBack = deployment.isRolledBack;
const isRolledBack = deployment.id === project?.rolledBackDeploymentId;
const isSelected = deployment.id === selectedDeployment?.deployment.id;
const iconContainer = (
<div
Expand Down Expand Up @@ -297,7 +297,7 @@ export const DeploymentsList = () => {
},
},
];
}, [selectedDeployment?.deployment.id, isCompactView, liveDeployment]);
}, [selectedDeployment?.deployment.id, isCompactView, liveDeployment, project]);

return (
<VirtualTable
Expand All @@ -307,7 +307,13 @@ export const DeploymentsList = () => {
onRowClick={setSelectedDeployment}
selectedItem={selectedDeployment}
keyExtractor={(deployment) => deployment.id}
rowClassName={(deployment) => getRowClassName(deployment, selectedDeployment?.deployment.id)}
rowClassName={(deployment) =>
getRowClassName(
deployment,
selectedDeployment?.deployment.id ?? null,
project?.rolledBackDeploymentId ?? null,
)
}
emptyState={
<div className="w-full flex justify-center items-center h-full">
<Empty className="w-[400px] flex items-start">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,15 @@ export const ROLLED_BACK_STYLES = {
focusRing: "focus:ring-warning-7",
};

export const getRowClassName = (deployment: Deployment, selectedDeploymentId?: string) => {
export const getRowClassName = (
deployment: Deployment,
selectedDeploymentId: string | null,
rolledBackDeploymentId: string | null,
) => {
const isFailed = deployment.status === "failed";
const style = isFailed
? FAILED_STATUS_STYLES
: deployment.isRolledBack
? ROLLED_BACK_STYLES
: STATUS_STYLES;
const isRolledBack = deployment.id === rolledBackDeploymentId;

const style = isFailed ? FAILED_STATUS_STYLES : isRolledBack ? ROLLED_BACK_STYLES : STATUS_STYLES;
const isSelected =
typeof selectedDeploymentId !== "undefined" && deployment.id === selectedDeploymentId;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ export const useDeployments = () => {
);

return {
project,
deployments,
liveDeployment,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export const CreateProjectDialog = () => {
slug: values.slug,
gitRepositoryUrl: values.gitRepositoryUrl || null,
liveDeploymentId: null,
rolledBackDeploymentId: null,
updatedAt: null,
id: "will-be-replace-by-server",
author: "will-be-replace-by-server",
Expand Down
1 change: 0 additions & 1 deletion apps/dashboard/lib/collections/deploy/deployments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ const schema = z.object({
cpus: z.number().min(1).max(16),
memory: z.number().min(1).max(1024),
}),
isRolledBack: z.boolean(),
// Deployment status
status: z.enum(["pending", "building", "deploying", "network", "ready", "failed"]),
createdAt: z.number(),
Expand Down
2 changes: 2 additions & 0 deletions apps/dashboard/lib/collections/deploy/projects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const schema = z.object({
gitRepositoryUrl: z.string().nullable(),
updatedAt: z.number().int().nullable(),
liveDeploymentId: z.string().nullable(),
rolledBackDeploymentId: z.string().nullable(),
// Flattened deployment fields for UI
commitTitle: z.string(),
branch: z.string(),
Expand Down Expand Up @@ -43,6 +44,7 @@ export const projects = createCollection<Project>(
queryClient,
queryKey: ["projects"],
retry: 3,
refetchInterval: 5000,
queryFn: async () => {
return await trpcClient.deploy.project.list.query();
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ export const listDeployments = t.procedure
gitCommitTimestamp: true,
runtimeConfig: true,
status: true,
isRolledBack: true,
createdAt: true,
},
limit: 500,
Expand Down
3 changes: 3 additions & 0 deletions apps/dashboard/lib/trpc/routers/deploy/project/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ type ProjectRow = {
updated_at: number | null;
git_repository_url: string | null;
live_deployment_id: string | null;
rolled_back_deployment_id: string | null;
git_commit_message: string | null;
git_branch: string | null;
git_commit_author_name: string | null;
Expand All @@ -32,6 +33,7 @@ export const listProjects = t.procedure
${projects.updatedAt},
${projects.gitRepositoryUrl},
${projects.liveDeploymentId},
${projects.rolledBackDeploymentId},
${deployments.gitCommitMessage},
${deployments.gitBranch},
${deployments.gitCommitAuthorName},
Expand All @@ -57,6 +59,7 @@ export const listProjects = t.procedure
updatedAt: row.updated_at,
gitRepositoryUrl: row.git_repository_url,
liveDeploymentId: row.live_deployment_id,
rolledBackDeploymentId: row.rolled_back_deployment_id,
commitTitle: row.git_commit_message ?? "[DUMMY] Initial commit",
branch: row.git_branch ?? "main",
author: row.git_commit_author_name ?? "[DUMMY] Unknown Author",
Expand Down
40 changes: 17 additions & 23 deletions go/apps/ctrl/services/deployment/deploy_workflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -393,36 +393,30 @@ func (w *DeployWorkflow) Run(ctx hydra.WorkflowContext, req *DeployRequest) erro
}

// Update deployment status to ready
_, err = hydra.Step(ctx, "update-deployment-ready", func(stepCtx context.Context) (*DeploymentResult, error) {
w.logger.Info("updating deployment status to ready", "deployment_id", req.DeploymentID)
completionTime := time.Now().UnixMilli()
activeErr := db.Query.UpdateDeploymentStatus(stepCtx, w.db.RW(), db.UpdateDeploymentStatusParams{
err = hydra.StepVoid(ctx, "update-deployment-ready", func(stepCtx context.Context) error {
return db.Query.UpdateDeploymentStatus(stepCtx, w.db.RW(), db.UpdateDeploymentStatusParams{
ID: req.DeploymentID,
Status: db.DeploymentsStatusReady,
UpdatedAt: sql.NullInt64{Valid: true, Int64: completionTime},
UpdatedAt: sql.NullInt64{Valid: true, Int64: time.Now().UnixMilli()},
})
if activeErr != nil {
return nil, fmt.Errorf("failed to update deployment %s status to ready: %w", req.DeploymentID, activeErr)
}
w.logger.Info("deployment status updated to ready", "deployment_id", req.DeploymentID)
})
if err != nil {
return err
}

// TODO: This section will be removed in the future in favor of "Promote to Production"
err = db.Query.UpdateProjectLiveDeploymentId(stepCtx, w.db.RW(), db.UpdateProjectLiveDeploymentIdParams{
ID: req.ProjectID,
LiveDeploymentID: sql.NullString{Valid: true, String: req.DeploymentID},
UpdatedAt: sql.NullInt64{Valid: true, Int64: time.Now().UnixMilli()},
if !project.RolledBackDeploymentID.Valid {
// only update this if the deployment is not rolled back
err = hydra.StepVoid(ctx, "update-project-deployment-pointers", func(stepCtx context.Context) error {
return db.Query.UpdateProjectDeployments(stepCtx, w.db.RW(), db.UpdateProjectDeploymentsParams{
ID: req.ProjectID,
LiveDeploymentID: sql.NullString{Valid: true, String: req.DeploymentID},
RolledBackDeploymentID: sql.NullString{Valid: false, String: ""},
UpdatedAt: sql.NullInt64{Valid: true, Int64: time.Now().UnixMilli()},
})
})
if err != nil {
return nil, fmt.Errorf("failed to update project %s active deployment ID to %s: %w", req.ProjectID, req.DeploymentID, err)
return err
}

return &DeploymentResult{
DeploymentID: req.DeploymentID,
Status: "ready",
}, nil
})
if err != nil {
return err
}
/*

Expand Down
37 changes: 6 additions & 31 deletions go/apps/ctrl/services/deployment/rollback.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,45 +166,20 @@ func (s *Service) Rollback(ctx context.Context, req *connect.Request[ctrlv1.Roll
}
}

err = db.Query.UpdateProjectLiveDeploymentId(ctx, s.db.RW(), db.UpdateProjectLiveDeploymentIdParams{
ID: project.ID,
LiveDeploymentID: sql.NullString{Valid: true, String: targetDeployment.ID},
UpdatedAt: sql.NullInt64{Valid: true, Int64: time.Now().UnixMilli()},
err = db.Query.UpdateProjectDeployments(ctx, s.db.RW(), db.UpdateProjectDeploymentsParams{
ID: project.ID,
LiveDeploymentID: sql.NullString{Valid: true, String: targetDeployment.ID},
RolledBackDeploymentID: sql.NullString{Valid: true, String: sourceDeployment.ID},
UpdatedAt: sql.NullInt64{Valid: true, Int64: time.Now().UnixMilli()},
})
if err != nil {
s.logger.Error("failed to update project active deployment ID",
s.logger.Error("failed to update project deployments",
"project_id", project.ID,
"error", err.Error(),
)
return nil, connect.NewError(connect.CodeInternal, fmt.Errorf("failed to update project's live deployment id: %w", err))
}

err = db.Query.UpdateDeploymentRollback(ctx, s.db.RW(), db.UpdateDeploymentRollbackParams{
ID: sourceDeployment.ID,
IsRolledBack: false,
UpdatedAt: sql.NullInt64{Valid: true, Int64: time.Now().UnixMilli()},
})
if err != nil {
s.logger.Error("failed to update deployment rollback status",
"deployment_id", sourceDeployment.ID,
"error", err.Error(),
)
return nil, connect.NewError(connect.CodeInternal, fmt.Errorf("failed to update deployment: %w", err))
}

err = db.Query.UpdateDeploymentRollback(ctx, s.db.RW(), db.UpdateDeploymentRollbackParams{
ID: targetDeployment.ID,
IsRolledBack: true,
UpdatedAt: sql.NullInt64{Valid: true, Int64: time.Now().UnixMilli()},
})
if err != nil {
s.logger.Error("failed to update deployment rollback status",
"deployment_id", targetDeployment.ID,
"error", err.Error(),
)
return nil, connect.NewError(connect.CodeInternal, fmt.Errorf("failed to update deployment: %w", err))
}

res := &ctrlv1.RollbackResponse{
Domains: make([]string, len(domainChanges)),
}
Expand Down
33 changes: 0 additions & 33 deletions go/pkg/db/deployment_update_rollback.sql_generated.go

This file was deleted.

22 changes: 11 additions & 11 deletions go/pkg/db/models_generated.go

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

24 changes: 14 additions & 10 deletions go/pkg/db/project_find_by_id.sql_generated.go

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

Loading