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

fix(aws-cdk): Move version check TTL file to home directory #2774

Merged
merged 5 commits into from
Jun 11, 2019
Merged

fix(aws-cdk): Move version check TTL file to home directory #2774

merged 5 commits into from
Jun 11, 2019

Conversation

nija-at
Copy link
Contributor

@nija-at nija-at commented Jun 6, 2019

Motivation & Change

Originally, the version check TTL file was located alongside the CDK
node installation directory. This caused issues for people who had CDK
installed on a readonly filesystem.

This change moves this file to the user's home directory, specifically
under $HOMEDIR/.cdk/cache. This directory is already being used by
account-cache.ts.

The old logic is maintained where a repo check is run once a day against
NPM, when a CDK command is invoked, and when a new version is present
will generate a console banner notifying the user of this.

The edge case with the updated implementation is when there are 2+
active installations of CDK and they are used interchangably. When
this happens, the user will only get one notification per non-latest
installation of CDK per day.

Manual Testing

Unit tests exist but beyond that, manual checks run using the command cdk init --list

  • With no TTL file present and latest version locally. Confirmed no upgrade message. Confirmed TTL file exists at the right location.
  • With no TTL file present, manually downgraded version in package.json. Confirmed upgrade message. Confirmed that TTL file exists at the right location.
  • With TTL file present and unexpired, manually downgraded version in package.json. Confirmed no upgrade message.
  • Manually forced home directory to ‘/Users’ (on Mac). Confirmed error message is displayed.

Pull Request Checklist

  • Testing
    • Unit test added (prefer not to modify an existing test, otherwise, it's probably a breaking change)
  • Title and Description
    • Change type: title prefixed with fix, feat and module name in parens, which will appear in changelog
    • Title: use lower-case and doesn't end with a period
    • Breaking?: last paragraph: "BREAKING CHANGE: <describe what changed + link for details>"
    • Issues: Indicate issues fixed via: "Fixes #xxx" or "Closes #xxx"

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license.

Originally, the version check TTL file was located alongside the CDK
node installation directory. This caused issues for people who had CDK
installed on a readonly filesystem.

This change moves this file to the user's home directory, specifically
under $HOMEDIR/.cdk/cache. This directory is already being used by
account-cache.ts.

The old logic is maintained where a repo check is run once a day against
NPM, when a CDK command is invoked, and when a new version is present
will generate a console banner notifying the user of this.

The edge case with the updated implementation is when there are 2+
active installations of CDK and they are used interchangably. When
this happens, the user will only get one notification per non-latest
installation of CDK per day.
@nija-at nija-at requested a review from a team as a code owner June 6, 2019 15:32
@nija-at
Copy link
Contributor Author

nija-at commented Jun 6, 2019

Can someone from the @awslabs/aws-cdk-team either provide access to the failing CodeBuild or provide the details on what commands are run on the CodeBuild fleet along with the output somewhere?

The code related to my commit and their associated unit tests seems to run fine on my laptop. However, I have a failing test test.diff.js in the aws-cdk package but it seems to exist from before my commit.

@rix0rrr
Copy link
Contributor

rix0rrr commented Jun 7, 2019

aws-cdk: ·[31m✖ initialization fails on unwritable directory·[39m 
aws-cdk: AssertionError:  
aws-cdk:     at _throws (/codebuild/output/src058680918/src/github.com/awslabs/aws-cdk/tools/cdk-build-tools/node_modules/nodeunit/lib/assert.js:335:5) 
aws-cdk:     at assert.throws (/codebuild/output/src058680918/src/github.com/awslabs/aws-cdk/tools/cdk-build-tools/node_modules/nodeunit/lib/assert.js:352:11) 
aws-cdk:     at Object.throws (/codebuild/output/src058680918/src/github.com/awslabs/aws-cdk/tools/cdk-build-tools/node_modules/nodeunit/lib/types.js:83:39) 
aws-cdk:     at Object.initialization fails on unwritable directory (/codebuild/output/src058680918/src/github.com/awslabs/aws-cdk/packages/aws-cdk/test/test.version.ts:22:10) 
aws-cdk:     at Object.<anonymous> (/codebuild/output/src058680918/src/github.com/awslabs/aws-cdk/tools/cdk-build-tools/node_modules/nodeunit/lib/core.js:236:16) 
aws-cdk:     at /codebuild/output/src058680918/src/github.com/awslabs/aws-cdk/tools/cdk-build-tools/node_modules/nodeunit/lib/core.js:236:16 
aws-cdk:     at Object.exports.runTest (/codebuild/output/src058680918/src/github.com/awslabs/aws-cdk/tools/cdk-build-tools/node_modules/nodeunit/lib/core.js:70:9) 
aws-cdk:     at /codebuild/output/src058680918/src/github.com/awslabs/aws-cdk/tools/cdk-build-tools/node_modules/nodeunit/lib/core.js:118:25 
aws-cdk:     at /codebuild/output/src058680918/src/github.com/awslabs/aws-cdk/tools/cdk-build-tools/node_modules/nodeunit/deps/async.js:513:13 
aws-cdk:     at iterate (/codebuild/output/src058680918/src/github.com/awslabs/aws-cdk/tools/cdk-build-tools/node_modules/nodeunit/deps/async.js:123:13) 

mkdirsSync(path.dirname(this.file));
fs.accessSync(path.dirname(this.file), fs.constants.W_OK);
} catch {
throw new Error(`Directory (${path.dirname(this.file)}) is not writable.`);
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this worth throwing? Shouldn't we flip a boolean that says "can't do any work, soz" ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The "can't do any work" message is printed by the catch block at the calling point of this constructor.

I did consider flipping a boolean and keeping it as a class member. This would mean the other methods on the class (like hasExpired()) return an additional state to the caller, which the caller will need to take care of.

Throwing an exception here seemed simpler and achieves the same experience.

packages/aws-cdk/lib/version.ts Outdated Show resolved Hide resolved
packages/aws-cdk/lib/version.ts Outdated Show resolved Hide resolved
packages/aws-cdk/lib/version.ts Outdated Show resolved Hide resolved
* Drop use of fs and use fs-extra exclusively.
* Cleaned up file write.
* Fixed breaking unit test.

#2774
Copy link
Contributor

@eladb eladb left a comment

Choose a reason for hiding this comment

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

Sorry for chiming in late in the game... one piece of feedback: I want to make sure this will never fail or block the user or even show an error message in case it couldn’t reach the network. The only situation where it should emit any output should be when there is a new version to be installed. In all other cases, it should be completely hidden from the user experience.

(I got some nasty error messages when I was in the plane).

@nija-at
Copy link
Contributor Author

nija-at commented Jun 7, 2019

@eladb - Thanks for that. I did some digging here and I think I know what caused this for you.

If there is no internet connectivity *and* npm has not cached any previous version of aws-cdk, that does seem to generate a nasty error message.

There's one log message at warn level. I'll change this to debug level so no errors are displayed from this part of the system.

@rix0rrr rix0rrr merged commit 1ae11c0 into aws:master Jun 11, 2019
@NGL321 NGL321 added the contribution/core This is a PR that came from AWS. label Sep 27, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
contribution/core This is a PR that came from AWS.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants