fix: deploy runtime image from source during backfill

This commit is contained in:
Felipe Domingues 2026-05-28 16:24:23 -03:00
commit d84074d150
4 changed files with 223 additions and 3 deletions

View file

@ -134,10 +134,13 @@ export async function deployRailwayService(opts: {
environmentId: string;
/** Use true on the first deploy of a freshly-created service (no prior deployment exists). */
firstDeploy?: boolean;
/** Use true after changing the configured source image so Railway pulls the current source. */
fromSource?: boolean;
}): Promise<void> {
// serviceInstanceRedeploy só funciona se já existe um deployment.
// Para o primeiro deploy de um serviço recém-criado, usamos serviceInstanceDeployV2.
if (opts.firstDeploy) {
// Para o primeiro deploy de um serviço recém-criado, ou após trocar source.image,
// usamos DeployV2 para puxar a fonte/imagem configurada em vez de reusar o último deploy.
if (opts.firstDeploy || opts.fromSource) {
const mutation = `
mutation ServiceInstanceDeployV2($serviceId: String!, $environmentId: String!) {
serviceInstanceDeployV2(serviceId: $serviceId, environmentId: $environmentId)
@ -169,7 +172,7 @@ export async function deployRailwayService(opts: {
// Fallback: serviço novo sem deploy anterior — redeploy falha, tenta V2.
if (errStr.includes("no deployment") || errStr.includes("No deployments") || errStr.includes("not found")) {
console.warn(`[deployRailwayService] redeploy sem deploy anterior, fallback para serviceInstanceDeployV2`);
await deployRailwayService({ ...opts, firstDeploy: true });
await deployRailwayService({ ...opts, firstDeploy: true, fromSource: false });
return;
}
throw new Error(`serviceInstanceRedeploy failed: ${errStr}`);