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

chore: ensure nodedjs/eks dependencies are deduplicated #1559

Merged
merged 2 commits into from
Jan 7, 2025

Conversation

t0yv0
Copy link
Member

@t0yv0 t0yv0 commented Dec 23, 2024

In particular yarn may link two copies of @pulumi/pulumi into the provider causing difficult to diagnose failures. This change applies the approach from @pulumi/pulumi-awsx where the dependencies are proactively deduplicated at build time.

Also note that yarn install should receive a --frozen-lockfile option to actually respect the lockfile during build.

@t0yv0 t0yv0 requested review from blampe and flostadler December 23, 2024 22:23
Copy link

Does the PR have any schema changes?

Looking good! No breaking changes found.
No new resources/functions.

In particular yarn may link two copies of @pulumi/pulumi into the provider causing difficult to diagnose failures. This
change applies the approach from @pulumi/pulumi-awsx where the dependencies are proactively deduplicated at build time.

Also note that `yarn install` should receive a --frozen-lockfile option to actually respect the lockfile during build.
@t0yv0 t0yv0 force-pushed the t0yv0/dedupe-deps branch from 8ca467f to 6517513 Compare December 23, 2024 23:08
@t0yv0 t0yv0 requested a review from a team December 27, 2024 19:36
Copy link
Member

@iwahbe iwahbe left a comment

Choose a reason for hiding this comment

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

Looks like a sensible fix.

@@ -147,7 +147,8 @@ install_java_sdk::
#Intentionally empty for CI / CD templating

nodejs/eks/node_modules: nodejs/eks/package.json nodejs/eks/yarn.lock
yarn install --cwd nodejs/eks --no-progress
yarn install --frozen-lockfile --cwd nodejs/eks --no-progress
Copy link
Contributor

Choose a reason for hiding this comment

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

Won't this break auto-update PRs?

The behavior of yarn install without --forzen-lockfile is to do the following:

If yarn.lock is present and is enough to satisfy all the dependencies listed in package.json, the exact versions recorded in yarn.lock are installed, and yarn.lock will be unchanged. Yarn will not check for newer versions. If yarn.lock is absent, or is not enough to satisfy all the dependencies listed in package.json (for example, if you manually add a dependency to package.json), Yarn looks for the newest versions available that satisfy the constraints in package.json. The results are written to yarn.lock.

I'd say we want the lockfile to be updated when it cannot satisfy what's defined in package.json

Copy link
Member Author

Choose a reason for hiding this comment

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

My intuition is that these changes should be reflected in commit history, pushing us toward hermetic builds. The default behavior is such that the checked in yarn.lock may no longer reflect the actual dependencies selected for the software.

If PRs that update dependencies modify the lock file in them I believe they will continue to work as expected with this change.

Copy link
Contributor

@flostadler flostadler Jan 7, 2025

Choose a reason for hiding this comment

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

But how would the dependency PRs update the lockfile? with --frozen-lockfile this wouldn't happen.

I don't quite understand how we could reach a point where package.json and yarn.lock would drift apart. Shouldn't the worktree clean check catch those cases?
The lock file would only be regenerated if the package.json was updated without running yarn install and if that's done, the worktree clean checks fail.

Copy link
Member Author

Choose a reason for hiding this comment

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

In a Renovate PR the bot is updating yarn.lock by calling yarn without --frozen-lockfile, that is the update procedure is bypassing this Make target AFAIK.

Perhaps relevant, some places where we use frozen-lockfile:

https://github.com/search?q=org%3Apulumi%20frozen-lockfile&type=code

Copy link
Member Author

Choose a reason for hiding this comment

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

You raise a good point about yarn.lock changes being detected by the worktree check. Unfortunately that does not seem to be trustworthy. First we do not do worktree checks on provider builds AFIAK but only on the SDK builds where code is expected to be generated. Then also it seems that we allow some files to drift:

      - name: Check worktree clean
        uses: pulumi/git-status-check-action@v1
        with:
          allowed-changes: |
            sdk/**/pulumi-plugin.json
            sdk/dotnet/Pulumi.*.csproj
            sdk/go/**/pulumiUtilities.go
            sdk/nodejs/package.json
            sdk/python/pyproject.toml

Copy link
Contributor

@flostadler flostadler Jan 7, 2025

Choose a reason for hiding this comment

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

Shouldn't this check everything except those few allowed changes in sdk? (I.e. include provider changes like the lockfile)

Don't get me wrong, overall I agree that --frozen-lockfile is the right thing to do. I was just concerned that it will break renovate.
I didn't know that renovate automatically updates the lockfile (docs). I thought that this happens through one of our make targets.. Good to know!

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah it would still catch lockfile changes it seems. But I am not sure if it is running in the same job that builds the provider.

Copy link
Contributor

Choose a reason for hiding this comment

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

It is (or at least was), but the approach with the frozen lock file is definitely better! :)

@t0yv0 t0yv0 merged commit 6fd7126 into master Jan 7, 2025
34 checks passed
@t0yv0 t0yv0 deleted the t0yv0/dedupe-deps branch January 7, 2025 16:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants