Skip to content

Commit

Permalink
Merge pull request #6537 from mthenw/fix-depeloy-individually
Browse files Browse the repository at this point in the history
Fix deploy command if package.individually set on a function-level
  • Loading branch information
medikoo committed Aug 14, 2019
2 parents 6a84748 + 896631d commit 312b4f5
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 27 deletions.
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -18,7 +18,7 @@ Serverless is an MIT open-source project, actively maintained by a full-time, ve

<a href="https://www.youtube.com/watch?v=-Nf0ui3qP2E" target="_blank">Watch the video overview here.</a>

[![serverless components notice](https://s3.amazonaws.com/assets.github.serverless/components/serverless_components_notice_dark.gif)](https://github.com/serverless/components)
[![serverless components notice](https://s3.amazonaws.com/assets.github.serverless/components/serverless_components_notice_dark.gif)](https://github.com/serverless/components)

## Contents

Expand Down
48 changes: 22 additions & 26 deletions lib/plugins/aws/deploy/lib/extendedValidate.js
Expand Up @@ -57,20 +57,31 @@ module.exports = {
});
}

if (
!_.isEmpty(this.serverless.service.functions) &&
this.serverless.service.package.individually
) {
// artifact file validation (multiple function artifacts)
if (!_.isEmpty(this.serverless.service.functions)) {
this.serverless.service.getAllFunctions().forEach(functionName => {
let artifactFileName = this.provider.naming.getFunctionArtifactName(functionName);
const functionObject = this.serverless.service.getFunction(functionName);
const individually =
(_.has(functionObject, ['package', 'individually']) &&
functionObject.package.individually) ||
this.serverless.service.package.individually;

// By default assume service-level package
let artifactFileName = this.provider.naming.getServiceArtifactName();
let artifactFilePath = path.join(this.packagePath, artifactFileName);

// check if an artifact is used in function package level
const functionObject = this.serverless.service.getFunction(functionName);
if (_.has(functionObject, ['package', 'artifact'])) {
artifactFilePath = functionObject.package.artifact;
artifactFileName = path.basename(artifactFilePath);
if (individually) {
// Use function-level generated artifact
artifactFileName = this.provider.naming.getFunctionArtifactName(functionName);
artifactFilePath = path.join(this.packagePath, artifactFileName);

if (_.has(functionObject, ['package', 'artifact'])) {
// Use function-level artifact
artifactFilePath = functionObject.package.artifact;
artifactFileName = path.basename(artifactFilePath);
}
} else if (this.serverless.service.package.artifact) {
// Use service-level artifact
artifactFileName = artifactFilePath = this.serverless.service.package.artifact;
}

if (!this.serverless.utils.fileExistsSync(artifactFilePath)) {
Expand All @@ -79,21 +90,6 @@ module.exports = {
);
}
});
} else if (!_.isEmpty(this.serverless.service.functions)) {
// artifact file validation (single service artifact)
let artifactFilePath;
let artifactFileName;
if (this.serverless.service.package.artifact) {
artifactFileName = artifactFilePath = this.serverless.service.package.artifact;
} else {
artifactFileName = this.provider.naming.getServiceArtifactName();
artifactFilePath = path.join(this.packagePath, artifactFileName);
}
if (!this.serverless.utils.fileExistsSync(artifactFilePath)) {
throw new this.serverless.classes.Error(
`No ${artifactFileName} file found in the package path you provided.`
);
}
}

return BbPromise.resolve();
Expand Down
14 changes: 14 additions & 0 deletions lib/plugins/aws/deploy/lib/extendedValidate.test.js
Expand Up @@ -113,6 +113,20 @@ describe('extendedValidate', () => {
});
});

it('should not throw error if individual packaging defined on a function level', () => {
awsDeploy.serverless.service.package.individually = false;
stateFileMock.service.functions = {
first: {
package: {
individually: true,
},
},
};
fileExistsSyncStub.returns(true);
readFileSyncStub.returns(stateFileMock);
return awsDeploy.extendedValidate();
});

it('should use function package level artifact when provided', () => {
stateFileMock.service.functions = {
first: {
Expand Down

0 comments on commit 312b4f5

Please sign in to comment.