Skip to content

Commit

Permalink
Merge 4308c8a into adb77a5
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Memering authored Jan 31, 2019
2 parents adb77a5 + 4308c8a commit 89d9910
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 54 deletions.
3 changes: 2 additions & 1 deletion changelog.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
fixed - Prevent Firestore index creation from encountering contention issues.
fixed - Prevent Firestore index creation from encountering contention issues.
fixed - Multi-Site predeploy and postdeploy hooks now trigger
135 changes: 82 additions & 53 deletions src/deploy/lifecycleHooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,69 +42,98 @@ function runCommand(command, childOptions) {
});
}

module.exports = function(target, hook) {
// Errors in postdeploy script will not exit the process since it's too late to stop the deploy.
var exit = hook !== "postdeploy" ? undefined : { exit: 2 };
function getChildEnvironment(target, overallOptions, config) {
// active project ID
var projectId = getProjectId(overallOptions);
// root directory where firebase.json can be found
var projectDir = overallOptions.projectRoot;
// location of hosting site or functions deploy, defaults project directory
var resourceDir;
switch (target) {
case "hosting":
resourceDir = overallOptions.config.path(config["public"]);
break;
case "functions":
resourceDir = overallOptions.config.path(config["source"]);
break;
default:
resourceDir = overallOptions.config.path(overallOptions.config.projectDir);
}

return function(context, options) {
var commands = options.config.get(target + "." + hook);
// Copying over environment variables
return_.assign({}, process.env, {
GCLOUD_PROJECT: projectId,
PROJECT_DIR: projectDir,
RESOURCE_DIR: resourceDir,
});
}

if (!commands) {
return Promise.resolve();
}
if (typeof commands === "string") {
commands = [commands];
}
function runTargetCommands(target, hook, overallOptions, config) {
let commands = config[hook];
if (!commands) {
return Promise.resolve();
}
if (typeof commands === "string") {
commands = [commands];
}

// active project ID
var projectId = getProjectId(options);
// root directory where firebase.json can be found
var projectDir = options.projectRoot;
// location of hosting site or functions deploy, defaults project directory
var resourceDir;
switch (target) {
case "hosting":
resourceDir = options.config.path(options.config.get("hosting.public"));
break;
case "functions":
resourceDir = options.config.path(options.config.get("functions.source"));
break;
default:
resourceDir = options.config.path(options.config.projectDir);
}
var childOptions = {
cwd: overallOptions.config.projectDir,
env: getChildEnvironment(target, overallOptions, config),
shell: true,
stdio: [0, 1, 2], // Inherit STDIN, STDOUT, and STDERR
};

var runAllCommands = _.reduce(
commands,
function(soFar, command) {
return soFar.then(function() {
return runCommand(command, childOptions);
});
},
Promise.resolve()
);

// Copying over environment variables
var childEnv = _.assign({}, process.env, {
GCLOUD_PROJECT: projectId,
PROJECT_DIR: projectDir,
RESOURCE_DIR: resourceDir,
// Errors in postdeploy script will not exit the process since it's too late to stop the deploy.
const exit = hook !== "postdeploy" ? undefined : { exit: 2 };

// We currently use the resource name in info logs in the rest of the deploy.
// However we don't have access to that here because predeploy hooks will
// happen before we figure that out. Internal bug tracking number: 123715324
let logIdentifier = target;
if (config.target) {
logIdentifier += `[${config.target}]`;
}

return runAllCommands
.then(function() {
utils.logSuccess(
clc.green.bold(logIdentifier + ":") + " Finished running " + clc.bold(hook) + " script."
);
})
.catch(function(err) {
throw new FirebaseError(logIdentifier + " " + hook + " error: " + err.message, exit);
});
}

var childOptions = {
cwd: options.config.projectDir,
env: childEnv,
shell: true,
stdio: [0, 1, 2], // Inherit STDIN, STDOUT, and STDERR
};
module.exports = function(target, hook) {
return function(context, options) {
let targetConfigs = options.config.get(target);
if (!targetConfigs) {
return Promise.resolve();
}
if (!_.isArray(targetConfigs)) {
targetConfigs = [targetConfigs];
}

var runAllCommands = _.reduce(
commands,
function(soFar, command) {
return soFar.then(function() {
return runCommand(command, childOptions);
return _.reduce(
targetConfigs,
function(previousCommands, individualConfig) {
return previousCommands.then(function() {
return runTargetCommands(target, hook, options, individualConfig);
});
},
Promise.resolve()
);

return runAllCommands
.then(function() {
utils.logSuccess(
clc.green.bold(target + ":") + " Finished running " + clc.bold(hook) + " script."
);
})
.catch(function(err) {
throw new FirebaseError(target + " " + hook + " error: " + err.message, exit);
});
};
};

0 comments on commit 89d9910

Please sign in to comment.