From 2306644d906bc6949e69ccbb0346a65a7d67c358 Mon Sep 17 00:00:00 2001 From: denyhs Date: Mon, 12 Jul 2021 06:05:35 -0400 Subject: [PATCH] #639 - Push to Deploy - We should have a user able to deploy to any account --- tools/cli/commands.js | 8 +++++-- tools/meteor-services/deploy.js | 40 ++++++++++++++++++++++++--------- 2 files changed, 36 insertions(+), 12 deletions(-) diff --git a/tools/cli/commands.js b/tools/cli/commands.js index ae383e8c1a..8a11dcd550 100644 --- a/tools/cli/commands.js +++ b/tools/cli/commands.js @@ -1472,7 +1472,9 @@ main.registerCommand({ 'build-only': { type: Boolean }, free: { type: Boolean }, plan: { type: String }, - mongo: { type: Boolean } + 'deploy-token': { type: String }, + mongo: { type: Boolean }, + owner: { type: String } }, allowUnrecognizedOptions: true, requiresApp: function (options) { @@ -1503,7 +1505,7 @@ function deployCommand(options, { rawOptions }) { } const loggedIn = auth.isLoggedIn(); - if (! loggedIn) { + if (! loggedIn && !options["deploy-token"]) { Console.error( "You must be logged in to deploy, just enter your email address."); Console.error(); @@ -1559,6 +1561,8 @@ function deployCommand(options, { rawOptions }) { site, settingsFile: options.settings, free: options.free, + deployToken: options['deploy-token'], + owner: options.owner, mongo: options.mongo, buildOptions: buildOptions, plan, diff --git a/tools/meteor-services/deploy.js b/tools/meteor-services/deploy.js index 80e4a37237..c1f89eec41 100644 --- a/tools/meteor-services/deploy.js +++ b/tools/meteor-services/deploy.js @@ -89,8 +89,12 @@ function deployRpc(options) { if (options.headers.cookie) { throw new Error("sorry, can't combine cookie headers yet"); } - options.qs = Object.assign({}, options.qs, - {capabilities: CAPABILITIES.slice()}); + options.qs = Object.assign( + {}, + options.qs, + { capabilities: CAPABILITIES.slice() }, + options.deployWithTokenProps || {} + ); // If we are waiting for deploy, we let Galaxy know so it can // use that information to send us the right deploy message response. if (options.waitForDeploy) { @@ -351,13 +355,13 @@ function canonicalizeSite(site) { // Executes the poll to check for deployment success and outputs proper messages // to user about the status of their app during the polling process -async function pollForDeploymentSuccess(versionId, deployPollTimeout, result, site) { +async function pollForDeploymentSuccess(versionId, deployPollTimeout, result, site, deployWithTokenProps) { // Create a default polling configuration for polling for deploy / build // In the future, we may change this to be user-configurable or smart // The user can only currently configure the polling timeout via a flag const pollingState = new PollingState(deployPollTimeout); await sleepForMilliseconds(pollingState.initialWaitTimeMs); - const deploymentPollResult = await pollForDeploy(pollingState, versionId, site); + const deploymentPollResult = await pollForDeploy(pollingState, versionId, site, deployWithTokenProps); if (deploymentPollResult && deploymentPollResult.isActive) { return 0; } @@ -398,7 +402,7 @@ class PollingState { // messages pertaining to the status of the version, which will then be reported // directly to the user. When the poll is complete, it will return an object // with information about the final state of the version and the app. -async function pollForDeploy(pollingState, versionId, site) { +async function pollForDeploy(pollingState, versionId, site, deployWithTokenProps) { const { deadline, pollIntervalMs, @@ -413,6 +417,7 @@ async function pollForDeploy(pollingState, versionId, site) { operand: versionId, expectPayload: ['message', 'finishStatus'], printDeployURL: false, + deployWithTokenProps }); // Check the details of the Version Status response and compare message to last call @@ -437,7 +442,7 @@ async function pollForDeploy(pollingState, versionId, site) { } else if (new Date() < deadline) { Console.warn(`Error checking deploy status; will retry: ${errorMessage}`); await sleepForMilliseconds(pollIntervalMs); - return await pollForDeploy(pollingState, versionId, site); + return await pollForDeploy(pollingState, versionId, site, deployWithTokenProps); } } @@ -446,7 +451,7 @@ async function pollForDeploy(pollingState, versionId, site) { if(new Date() < deadline && !finishStatus.isFinished) { // Wait for a set interval and then poll again await sleepForMilliseconds(pollIntervalMs); - return await pollForDeploy(pollingState, versionId, site); + return await pollForDeploy(pollingState, versionId, site, deployWithTokenProps); } else if (!finishStatus.isFinished) { Console.info(`Polling timed out. To check the status of your app, visit ${versionStatusResult.payload.galaxyUrl}. To wait longer, pass a timeout @@ -516,7 +521,14 @@ export async function bundleAndDeploy(options) { site: site, preflight: true, promptIfAuthFails: promptIfAuthFails, - qs: options.rawOptions, + qs: Object.assign( + {}, + options.rawOptions, + { + deployToken: options.deployToken, + owner: options.owner, + } + ), printDeployURL: true }); @@ -628,6 +640,11 @@ export async function bundleAndDeploy(options) { return 0; } + const deployWithTokenProps = { + deployToken: options.deployToken, + owner: options.owner + }; + Console.info('Preparing to upload your app...'); const result = buildmessage.enterJob({ title: "uploading" @@ -643,7 +660,8 @@ export async function bundleAndDeploy(options) { { free: options.free, plan: options.plan, - mongo: options.mongo + mongo: options.mongo, + ...deployWithTokenProps, }, ), bodyStream: createTarGzStream(pathJoin(buildDir, 'bundle')), @@ -676,7 +694,9 @@ export async function bundleAndDeploy(options) { result.payload.newVersionId, options.deployPollingTimeoutMs, result, - site); + site, + deployWithTokenProps, + ); } return 0; };