Skip to content

Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.

fix: check deploy status to avoid message

adilsonafe2f331e108
diff --git a/backend/src/services/app-connection/railway/railway-connection-constants.ts b/backend/src/services/app-connection/railway/railway-connection-constants.ts
index aabec10274..af03411a41 100644
--- a/backend/src/services/app-connection/railway/railway-connection-constants.ts
+++ b/backend/src/services/app-connection/railway/railway-connection-constants.ts
@@ -3,3 +3,35 @@ export enum RailwayConnectionMethod {
ProjectToken = "project-token",
TeamToken = "team-token"
}
+
+// Railway DeploymentStatus enum values (https://docs.railway.com/reference/public-api)
+export enum RailwayDeploymentStatus {
+ Building = "BUILDING",
+ Crashed = "CRASHED",
+ Deploying = "DEPLOYING",
+ Failed = "FAILED",
+ Initializing = "INITIALIZING",
+ NeedsApproval = "NEEDS_APPROVAL",
+ Queued = "QUEUED",
+ Removed = "REMOVED",
+ Removing = "REMOVING",
+ Skipped = "SKIPPED",
+ Sleeping = "SLEEPING",
+ Success = "SUCCESS",
+ Waiting = "WAITING"
+}
+
+// Deployments in these states have no build snapshot to replay, so Railway rejects
+// `deploymentRedeploy` with "Cannot redeploy without a snapshot". Skip them when
+// selecting a deployment to redeploy.
+export const RAILWAY_NON_REDEPLOYABLE_STATUSES = new Set<string>([
+ RailwayDeploymentStatus.Building,
+ RailwayDeploymentStatus.Queued,
+ RailwayDeploymentStatus.Initializing,
+ RailwayDeploymentStatus.Waiting,
+ RailwayDeploymentStatus.NeedsApproval,
+ RailwayDeploymentStatus.Skipped,
+ RailwayDeploymentStatus.Failed,
+ RailwayDeploymentStatus.Removed,
+ RailwayDeploymentStatus.Removing
+]);
diff --git a/backend/src/services/app-connection/railway/railway-connection-public-client.ts b/backend/src/services/app-connection/railway/railway-connection-public-client.ts
index 2fda1f022d..0be81de617 100644
--- a/backend/src/services/app-connection/railway/railway-connection-public-client.ts
+++ b/backend/src/services/app-connection/railway/railway-connection-public-client.ts
@@ -123,8 +123,8 @@ class RailwayPublicClient {
config: RailwaySendReqOptions,
variables: { input: { serviceId: string; environmentId: string }; first?: number }
) {
- return this.send<TRailwayResponse<{ deployments: { edges: { node: { id: string } }[] } }>>(
- `query deployments($input: DeploymentListInput!, $first: Int) { deployments(first: $first, input: $input) { edges { node { id } } } }`,
+ return this.send<TRailwayResponse<{ deployments: { edges: { node: { id: string; status: string } }[] } }>>(
+ `query deployments($input: DeploymentListInput!, $first: Int) { deployments(first: $first, input: $input) { edges { node { id status } } } }`,
config,
variables
);
diff --git a/backend/src/services/secret-sync/railway/railway-sync-fns.ts b/backend/src/services/secret-sync/railway/railway-sync-fns.ts
index 941873ff40..c02c4e011c 100644
--- a/backend/src/services/secret-sync/railway/railway-sync-fns.ts
+++ b/backend/src/services/secret-sync/railway/railway-sync-fns.ts
@@ -1,6 +1,8 @@
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
+import { logger } from "@app/lib/logger";
+import { RAILWAY_NON_REDEPLOYABLE_STATUSES } from "@app/services/app-connection/railway/railway-connection-constants";
import { RailwayPublicAPI } from "@app/services/app-connection/railway/railway-connection-public-client";
import { matchesSchema } from "@app/services/secret-sync/secret-sync-fns";
@@ -93,19 +95,25 @@ export const RailwaySyncFns = {
serviceId: config.serviceId,
environmentId: config.environmentId
},
- first: 1
+ first: 10
});
- const latestDeploymentId = latestDeployment?.deployments.edges[0]?.node.id;
+ const edges = latestDeployment?.deployments.edges ?? [];
- if (!latestDeploymentId)
- throw new SecretSyncError({
- message: "Failed to get latest deployment from Railway"
- });
+ // Only deployments with a build snapshot can be redeployed; deployments in states like
+ // BUILDING/FAILED/REMOVED have no snapshot and Railway rejects them with
+ // "Cannot redeploy without a snapshot". Pick the most recent redeployable deployment.
+ const redeployableDeploymentId = edges.find((edge) => !RAILWAY_NON_REDEPLOYABLE_STATUSES.has(edge.node.status))
+ ?.node.id;
+
+ // No redeployable deployment exists yet (e.g. service has never successfully deployed);
+ // the variables are already upserted, so skip the redeploy rather than failing the sync.
+ logger.info({ redeployableDeploymentId }, "Skipping redeploy. No redeployable deployment found.");
+ if (!redeployableDeploymentId) return;
await RailwayPublicAPI.redeployDeployment(secretSync.connection, {
input: {
- deploymentId: latestDeploymentId
+ deploymentId: redeployableDeploymentId
}
});
} catch (error) {