Skip to content

Bug: Deployment checks erroneously fail if local artifacts are placed in ".serverless/NAME.zip" #8350

Closed

Description

@ryan-roemer

Extracting this issue from #8187 (comment) so I can do a quick PR... I'll have a full regression test in the PR which will hopefully explain the isolated situation more.

The code at issue is:

const zipFiles = globby.sync(['**.zip'], { cwd: serverlessDirPath, dot: true, silent: true });
if (this.serverless.service.package.artifact) {
zipFiles.push(
path.resolve(this.serverless.config.servicePath, this.serverless.service.package.artifact)
);
}
const zipFilePaths = zipFiles.map(zipFile => path.resolve(serverlessDirPath, zipFile));

The issue is that if a plugin (like jetpack does) or outside build process places it's own artifact into .serverless/<FROM_PACKAGE_ARTIFACT>.zip and sets package.artifact we end up with a case wherein we glob .serverless/<FROM_PACKAGE_ARTIFACT>.zip first in the sync glob and then add the exact same file(s) again in the package.artifact code in the conditional. This has the effect of (1) doing extra unneeded I/O for the hash calculation and (2) adding extra identical hashes to the localHashes array which causes the _.isEqual() check to be false and ultimately serverless will deploy when it otherwise shouldn't.

serverless.yml
# .. Just a sample:
functions:
  my-fun:
    handler: index.handler
    package:
      # Assume this is created out of band by a separate process.
      artifact: ".serverless/my-fun.zip"
serverless deploy output
# EXPECT
Serverless: Service files not changed. Skipping deployment...

# ACTUAL => Gets a full deployment.

Installed version

Framework Core: 2.4.0
Plugin: 4.0.4
SDK: 2.3.2
Components: 3.2.1

Activity

  1. changed the title [-]Bugfix: Ensure deployment check for local artifacts only reads/hashes unique files once.[/-] [+]Bug: Deployment checks erroneously fail if local artifacts are placed in ".serverless/NAME.zip"[/+] on Oct 7, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions