Skip to content

Commit

Permalink
feat(CLI): First iteration of support for verbose mode in deploy
Browse files Browse the repository at this point in the history
  • Loading branch information
pgrzesik committed Sep 14, 2021
1 parent 5a303bf commit fbdd124
Show file tree
Hide file tree
Showing 9 changed files with 49 additions and 12 deletions.
1 change: 1 addition & 0 deletions lib/plugins/aws/deploy/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ class AwsDeploy {
'aws:deploy:finalize:cleanup': async () => {
if (this.serverless.service.provider.shouldNotDeploy) return;
progress.get('main').notice('Updating');
log.info('Updating');
await this.cleanupS3Bucket();
if (this.options.package || this.serverless.service.package.path) {
await this.serverless.pluginManager.spawn('aws:common:cleanupTempDir');
Expand Down
3 changes: 2 additions & 1 deletion lib/plugins/aws/deploy/lib/cleanupS3Bucket.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
const _ = require('lodash');
const findAndGroupDeployments = require('../../utils/findAndGroupDeployments');
const getS3ObjectsFromStacks = require('../../utils/getS3ObjectsFromStacks');
const { legacy } = require('@serverless/utils/log');
const { legacy, log } = require('@serverless/utils/log');

module.exports = {
async getObjectsToRemove() {
Expand All @@ -30,6 +30,7 @@ module.exports = {
async removeObjects(objectsToRemove) {
if (!objectsToRemove || !objectsToRemove.length) return;
legacy.log('Removing old service artifacts from S3...');
log.info('Removing old service artifacts from S3');
await this.provider.request('S3', 'deleteObjects', {
Bucket: this.bucketName,
Delete: { Objects: objectsToRemove },
Expand Down
6 changes: 4 additions & 2 deletions lib/plugins/aws/deploy/lib/createStack.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@

const BbPromise = require('bluebird');
const ServerlessError = require('../../../../serverless-error');
const { legacy, progress } = require('@serverless/utils/log');
const { legacy, progress, log } = require('@serverless/utils/log');

module.exports = {
async create() {
// Note: using three dots instead of ellipsis to support non uni-code consoles.
legacy.log('Creating Stack...');
progress.get('main').notice('Creating CloudFormation stack');
log.info('Creating CloudFormation stack');
const stackName = this.provider.naming.getStackName();

let stackTags = { STAGE: this.provider.getStage() };
Expand Down Expand Up @@ -87,7 +88,8 @@ module.exports = {
);

if (!isAlreadyAccelerated) {
this.serverless.cli.log('Not using S3 Transfer Acceleration (1st deploy)');
legacy.log('Not using S3 Transfer Acceleration (1st deploy)');
log.info('Not using S3 Transfer Acceleration (1st deploy)');
this.provider.disableTransferAccelerationForCurrentDeploy();
}
}
Expand Down
9 changes: 7 additions & 2 deletions lib/plugins/aws/deploy/lib/uploadArtifacts.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const filesize = require('filesize');
const normalizeFiles = require('../../lib/normalizeFiles');
const getLambdaLayerArtifactPath = require('../../utils/getLambdaLayerArtifactPath');
const ServerlessError = require('../../../../serverless-error');
const { legacy, progress } = require('@serverless/utils/log');
const { legacy, progress, log } = require('@serverless/utils/log');

const MAX_CONCURRENT_ARTIFACTS_UPLOADS =
Number(process.env.SLS_MAX_CONCURRENT_ARTIFACTS_UPLOADS) || 3;
Expand Down Expand Up @@ -38,6 +38,7 @@ module.exports = {
} else {
progress.get('main').notice(`Uploading (0/${artifactFilePaths.length})`);
}
log.info('Uploading');

await this.uploadCloudFormationFile();
await this.uploadFunctionsAndLayers();
Expand All @@ -46,6 +47,7 @@ module.exports = {

async uploadCloudFormationFile() {
legacy.log('Uploading CloudFormation file to S3...');
log.info('Uploading CloudFormation file to S3');

const compiledTemplateFileName = this.provider.naming.getCompiledTemplateS3Suffix();

Expand Down Expand Up @@ -149,7 +151,8 @@ module.exports = {
.map((name) => {
const layerObject = this.serverless.service.getLayer(name);
if (layerObject.artifactAlreadyUploaded) {
this.serverless.cli.log(`Skip uploading ${name}`);
legacy.log(`Skip uploading ${name}`);
log.info(`Skipped uploading ${name}`);
return null;
}
return getLambdaLayerArtifactPath(
Expand Down Expand Up @@ -177,6 +180,7 @@ module.exports = {
const stats = await this.getFileStats(artifactFilePath);
const fileName = path.basename(artifactFilePath);
legacy.log(`Uploading service ${fileName} file to S3 (${filesize(stats.size)})...`);
log.info(`Uploading service ${fileName} file to S3 (${filesize(stats.size)})`);
if (shouldReportDetailedProgress) {
progress
.get(`upload:${fileName}`)
Expand Down Expand Up @@ -204,6 +208,7 @@ module.exports = {

if (this.serverless.utils.fileExistsSync(artifactFilePath)) {
legacy.log('Uploading custom CloudFormation resources...');
log.info('Uploading custom CloudFormation resources');
await this.uploadZipFile(artifactFilePath);
}
},
Expand Down
11 changes: 10 additions & 1 deletion lib/plugins/aws/info/display.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

const chalk = require('chalk');
const { style, legacy, writeText } = require('@serverless/utils/log');
const { style, legacy, writeText, isVerboseMode } = require('@serverless/utils/log');

module.exports = {
displayServiceInfo() {
Expand Down Expand Up @@ -172,6 +172,15 @@ module.exports = {
legacy.consoleLog(message);
}

if (isVerboseMode && this.gatheredData.outputs.length) {
const outputSectionItems = [];
this.gatheredData.outputs.forEach((output) => {
outputSectionItems.push(`${output.OutputKey}: ${output.OutputValue}`);
});

this.serverless.addServiceOutputSection('\nStack Outputs', outputSectionItems);
}

return message;
},

Expand Down
7 changes: 6 additions & 1 deletion lib/plugins/aws/lib/monitorStack.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const BbPromise = require('bluebird');
const chalk = require('chalk');
const wait = require('timers-ext/promise/sleep');
const ServerlessError = require('../../../serverless-error');
const { legacy, progress } = require('@serverless/utils/log');
const { log, legacy, progress, style } = require('@serverless/utils/log');

const validStatuses = new Set(['CREATE_COMPLETE', 'UPDATE_COMPLETE', 'DELETE_COMPLETE']);

Expand Down Expand Up @@ -77,6 +77,11 @@ module.exports = {
stackLatestError = event;
}
// Log stack events
log.info(
style.aside(
` ${eventStatus} - ${event.ResourceType} - ${event.LogicalResourceId}`
)
);
if (this.options.verbose) {
if (eventStatus && eventStatus.endsWith('FAILED')) {
eventStatus = chalk.red(eventStatus);
Expand Down
7 changes: 5 additions & 2 deletions lib/plugins/aws/lib/updateStack.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@

const BbPromise = require('bluebird');
const getS3EndpointForRegion = require('../utils/getS3EndpointForRegion');
const { legacy, progress } = require('@serverless/utils/log');
const { legacy, progress, log } = require('@serverless/utils/log');

const NO_UPDATE_MESSAGE = 'No updates are to be performed.';

module.exports = {
async createFallback() {
this.createLater = false;
this.serverless.cli.log('Creating Stack...');
legacy.log('Creating Stack...');
progress.get('main').notice('Creating CloudFormation stack');
log.info('Creating CloudFormation stack');

const stackName = this.provider.naming.getStackName();
let stackTags = { STAGE: this.provider.getStage() };
Expand Down Expand Up @@ -73,6 +75,7 @@ module.exports = {

legacy.log('Updating Stack...');
progress.get('main').notice('Updating CloudFormation stack');
log.info('Updating CloudFormation stack');
const stackName = this.provider.naming.getStackName();
let stackTags = { STAGE: this.provider.getStage() };

Expand Down
10 changes: 8 additions & 2 deletions lib/plugins/package/lib/packageService.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const _ = require('lodash');
const micromatch = require('micromatch');
const ServerlessError = require('../../../serverless-error');
const parseS3URI = require('../../aws/utils/parse-s3-uri');
const { legacy, progress } = require('@serverless/utils/log');
const { legacy, progress, log } = require('@serverless/utils/log');

module.exports = {
defaultExcludes: [
Expand Down Expand Up @@ -69,14 +69,17 @@ module.exports = {
async packageService() {
legacy.log('Packaging service...');
progress.get('main').notice('Packaging');
log.info();
log.info('Packaging');
let shouldPackageService = false;
const allFunctions = this.serverless.service.getAllFunctions();
let packagePromises = allFunctions.map(async (functionName) => {
const functionObject = this.serverless.service.getFunction(functionName);
if (functionObject.image) return;
functionObject.package = functionObject.package || {};
if (functionObject.package.disable) {
this.serverless.cli.log(`Packaging disabled for function: "${functionName}"`);
legacy.log(`Packaging disabled for function: "${functionName}"`);
log.info(`Packaging disabled for function: "${functionName}"`);
return;
}
if (functionObject.package.artifact) {
Expand Down Expand Up @@ -204,6 +207,7 @@ module.exports = {
await this.excludeDevDependencies({
exclude: this.getExcludes([], true),
include: this.getIncludes(),
contextName: 'service package',
})
);
},
Expand All @@ -219,6 +223,7 @@ module.exports = {
...(funcPackageConfig.include || []),
...(funcPackageConfig.patterns || []),
]),
contextName: `function "${functionName}"`,
})
);
},
Expand All @@ -234,6 +239,7 @@ module.exports = {
...(layerPackageConfig.include || []),
...(layerPackageConfig.patterns || []),
]),
contextName: `layer "${layerName}"`,
}),
layerObject.path
);
Expand Down
7 changes: 6 additions & 1 deletion lib/plugins/package/lib/zipService.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const childProcess = BbPromise.promisifyAll(require('child_process'));
const globby = require('globby');
const _ = require('lodash');
const ServerlessError = require('../../../serverless-error');
const { legacy } = require('@serverless/utils/log');
const { legacy, log } = require('@serverless/utils/log');

const excludeNodeDevDependenciesMemoized = _.memoize(excludeNodeDevDependencies);

Expand All @@ -34,6 +34,11 @@ module.exports = {

if (excludeDevDependencies) {
legacy.log('Excluding development dependencies...');
if (params.contextName) {
log.info(`Excluding development dependencies for ${params.contextName}`);
} else {
log.info('Excluding development dependencies');
}

const exAndInNode = await excludeNodeDevDependenciesMemoized(serviceDir);
params.exclude = _.union(params.exclude, exAndInNode.exclude);
Expand Down

0 comments on commit fbdd124

Please sign in to comment.