Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support V3 log interface #284

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
14 changes: 13 additions & 1 deletion deploy/googleDeploy.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,15 @@ class GoogleDeploy {
this.options = options;
this.provider = this.serverless.getProvider('google');

let deployProgress;

if (this.provider.progress) {
deployProgress = this.provider.progress.create({
message: 'Beginning deployment',
name: 'deploy',
});
}

Object.assign(
this,
validate,
Expand All @@ -39,7 +48,10 @@ class GoogleDeploy {
.then(this.uploadArtifacts)
.then(this.updateDeployment),

'after:deploy:deploy': () => BbPromise.bind(this).then(this.cleanupDeploymentBucket),
'after:deploy:deploy': () =>
BbPromise.bind(this)
.then(this.cleanupDeploymentBucket)
.finally(() => deployProgress && deployProgress.remove()),
};
}
}
Expand Down
6 changes: 5 additions & 1 deletion deploy/lib/cleanupDeploymentBucket.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,11 @@ module.exports = {
removeObjects(objectsToRemove) {
if (!objectsToRemove.length) return BbPromise.resolve();

this.serverless.cli.log('Removing old artifacts...');
if (this.provider.progress) {
this.provider.progress.get('deploy').update('Removing old artifacts from deployment bucket');
} else {
this.serverless.cli.log('Removing old artifacts...');
}

const removePromises = objectsToRemove.map((object) => {
const params = {
Expand Down
6 changes: 5 additions & 1 deletion deploy/lib/createDeployment.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,11 @@ module.exports = {
createIfNotExists(foundDeployment) {
if (foundDeployment) return BbPromise.resolve();

this.serverless.cli.log('Creating deployment...');
if (this.provider.progress) {
this.provider.progress.get('deploy').update('Creating deployment via Deployment Manager');
} else {
this.serverless.cli.log('Creating deployment...');
}

const filePath = path.join(
this.serverless.config.servicePath,
Expand Down
6 changes: 5 additions & 1 deletion deploy/lib/updateDeployment.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,11 @@ module.exports = {
},

update(deployment) {
this.serverless.cli.log('Updating deployment...');
if (this.provider.progress) {
this.provider.progress.get('deploy').update('Updating deployment');
} else {
this.serverless.cli.log('Updating deployment...');
}

const filePath = path.join(
this.serverless.config.servicePath,
Expand Down
10 changes: 8 additions & 2 deletions deploy/lib/uploadArtifacts.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@ const fs = require('fs');

module.exports = {
uploadArtifacts() {
this.serverless.cli.log('Uploading artifacts...');
if (this.provider.progress) {
this.provider.progress.get('deploy').update('Uploading artifacts');
} else {
this.serverless.cli.log('Uploading artifacts...');
}

const params = {
bucket: this.serverless.service.provider.deploymentBucketName,
Expand All @@ -19,7 +23,9 @@ module.exports = {
};

return this.provider.request('storage', 'objects', 'insert', params).then(() => {
this.serverless.cli.log('Artifacts successfully uploaded...');
if (!this.provider.progress) {
this.serverless.cli.log('Artifacts successfully uploaded...');
}
});
},
};
8 changes: 7 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,16 @@ const GoogleLogs = require('./logs/googleLogs');
const GoogleInfo = require('./info/googleInfo');

class GoogleIndex {
constructor(serverless, options) {
constructor(serverless, options, v3Utils) {
this.serverless = serverless;
this.options = options;

if (v3Utils) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is setup on GoogleIndex level where everywhere in the code you reference it from this.provider - I believe it's not reachable on GoogleProvider level.

this.log = v3Utils.log;
this.progress = v3Utils.progress;
this.writeText = v3Utils.writeText;
}

this.serverless.pluginManager.addPlugin(GoogleProvider);
this.serverless.pluginManager.addPlugin(GooglePackage);
this.serverless.pluginManager.addPlugin(GoogleDeploy);
Expand Down
33 changes: 32 additions & 1 deletion info/lib/displayServiceInfo.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ module.exports = {
return BbPromise.resolve(data);
},

printInfo(data) {
printInfoV2(data) {
let message = '';

// get all the service related information
Expand All @@ -89,6 +89,37 @@ module.exports = {
}

this.serverless.cli.consoleLog(message);
},

printInfoV3(data) {
// get all the service related information
this.serverless.addServiceOutputSection('Service', data.service);
this.serverless.addServiceOutputSection('Project', data.project);
this.serverless.addServiceOutputSection('Stage', data.stage);
this.serverless.addServiceOutputSection('Region', data.region);

// get all the functions
if (data.resources.functions.length) {
this.serverless.addServiceOutputSection(
'Deployed Functions',
data.resources.functions.reduce((previous, current) => {
return previous.push(current.name);
}, [])
);
} else {
this.serverless.addServiceOutputSection(
'Deployed Functions',
'No functions currently deployed'
);
}
},

printInfo(data) {
if (this.provider.log) {
this.printInfoV3(data);
} else {
this.printInfoV2(data);
}

return BbPromise.resolve();
},
Expand Down
6 changes: 5 additions & 1 deletion invoke/lib/invokeFunction.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,11 @@ module.exports = {

const log = `${chalk.grey(res.executionId)} ${res.result}`;

this.serverless.cli.log(log);
if (this.provider.writeText) {
this.provider.writeText(log);
} else {
this.serverless.cli.log(log);
}

return BbPromise.resolve();
},
Expand Down
6 changes: 5 additions & 1 deletion logs/lib/retrieveLogs.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,11 @@ module.exports = {
output = `Displaying the ${logs.entries.length} most recent log(s):\n\n${output}`; // prettify output
output = output.slice(0, output.length - 1); // remove "\n---\n\n" for the last log entry

this.serverless.cli.log(output);
if (this.provider.writeText) {
this.provider.writeText(output);
} else {
this.serverless.cli.log(output);
}

return BbPromise.resolve();
},
Expand Down
6 changes: 5 additions & 1 deletion package/lib/compileFunctions.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@ module.exports = {

let vpcEgress = funcObject.vpcEgress || this.serverless.service.provider.vpcEgress;

this.serverless.cli.log(`Compiling function "${functionName}"...`);
if (this.log) {
this.log.notice(`Compiling function "${functionName}"...`);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like a candidate for progress as it can take some time

} else {
this.serverless.cli.log(`Compiling function "${functionName}"...`);
}

validateHandlerProperty(funcObject, functionName);
validateEventsProperty(funcObject, functionName);
Expand Down
14 changes: 13 additions & 1 deletion remove/googleRemove.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,15 @@ class GoogleRemove {
this.options = options;
this.provider = this.serverless.getProvider('google');

let removeProgress;

if (this.provider.progress) {
removeProgress = this.provider.progress.create({
message: 'Removing deployment',
name: 'remove',
});
}

Object.assign(
this,
validate,
Expand All @@ -33,7 +42,10 @@ class GoogleRemove {
.then(this.setDeploymentBucketName),

'remove:remove': () =>
BbPromise.bind(this).then(this.emptyDeploymentBucket).then(this.removeDeployment),
BbPromise.bind(this)
.then(this.emptyDeploymentBucket)
.then(this.removeDeployment)
.finally(() => removeProgress && removeProgress.remove()),
};
}
}
Expand Down
6 changes: 5 additions & 1 deletion remove/lib/emptyDeploymentBucket.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@ module.exports = {
removeObjects(objectsToRemove) {
if (!objectsToRemove.length) return BbPromise.resolve();

this.serverless.cli.log('Removing artifacts in deployment bucket...');
if (this.log) {
this.provider.progress.get('remove').update('Removing artifacts from deployment bucket');
} else {
this.serverless.cli.log('Removing artifacts in deployment bucket...');
}

const removePromises = objectsToRemove.map((object) => {
const params = {
Expand Down
6 changes: 5 additions & 1 deletion remove/lib/removeDeployment.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@

module.exports = {
removeDeployment() {
this.serverless.cli.log('Removing deployment...');
if (this.log) {
this.provider.progress.get('remove').update('Removing deployment from Deployment Manager');
} else {
this.serverless.cli.log('Removing deployment...');
}

const deploymentName = `sls-${this.serverless.service.service}-${this.options.stage}`;

Expand Down
13 changes: 9 additions & 4 deletions shared/monitorDeployment.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ module.exports = {

let deploymentStatus = null;

this.serverless.cli.log(`Checking deployment ${action} progress...`);
if (!this.provider.log) {
this.serverless.cli.log(`Checking deployment ${action} progress...`);
}

return new BbPromise((resolve, reject) => {
async.whilst(
Expand Down Expand Up @@ -53,9 +55,12 @@ module.exports = {
},

() => {
// empty console.log for a prettier output
this.serverless.cli.consoleLog('');
this.serverless.cli.log('Done...');
if (!this.provider.log) {
// empty console.log for a prettier output
this.serverless.cli.consoleLog('');
this.serverless.cli.log('Done...');
}

resolve(deploymentStatus);
}
);
Expand Down