fix: shrink the CLI binary by 36% - #449
Merged
Merged
Conversation
The CLI imported Hydra, Kratos and Keto command packages that mixed API-only commands with server commands. Go resolves dependencies per package, so importing a single API command linked the whole server - database drivers, migrations and every social sign-in SDK - into the binary. Those packages were split upstream. Bumping to the split versions drops the binary from 57.6 MB to 37.0 MB and removes 115 modules from the dependency tree, with no change to any command. Also stop registering Kratos' `--endpoint` flag on the Hydra-backed OAuth2 commands. It was only there to declare a flag named `endpoint`, which put "The URL of Ory Kratos' Admin API" in the help text of `ory get jwk` and friends, and it linked the Kratos server. The wrapped Hydra commands read the flag through cmdx.NewClient, so register it via cmdx instead. The flag itself is unchanged.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: ⛔ Files ignored due to path filters (1)
📒 Files selected for processing (2)
📝 WalkthroughWalkthroughWrapped Hydra commands gain an ChangesHydra endpoint configuration
Estimated code review effort: 2 (Simple) | ~10 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The
orybinary drops from 57.6 MB to 37.0 MB (−20.6 MB, −35.8%) and its dependency tree from 241 to 126 modules, with no change to any command.-s -w, darwin/arm64)go.modrequire entriesWhy the binary was so large
The CLI imports
hydra/v2/cmd,kratos/cmd/identitiesandketo/cmd/checkpurely to manage a remote Ory Network project. Those packages mixed API-only commands with server commands, and Go resolves dependencies per package — so importing one API command linked the entire Hydra, Kratos and Keto servers into the CLI: persistence layers, migrations, gRPC, and every social sign-in SDK.Among the 115 modules this removes:
modernc.org/sqlite,jackc/pgx,go-sql-driver/mysql,ory/pop,go-webauthn,go-tpm,discordgo,spotify,slack-go,dockertest,moby/moby/client,go-faker,gobuffalo/plush. Nopop,sqlite,pgxor*/driverpackage is linked any more.What changed
Dependency bumps. The upstream packages were split in ory-corp/cloud#13250 (merged). This bumps to those versions:
One code change.
wrapHydraCmdcalled Kratos'cliclient.RegisterClientFlagson the Hydra-backed OAuth2 commands. It was only there to declare a flag namedendpoint— but it put "The URL of Ory Kratos' Admin API" into the help text ofory get jwk,ory create oauth2-clientand friends, and it linked the whole Kratos server. The wrapped Hydra commands read that flag throughcmdx.NewClient, so it is now registered viacmdxdirectly.--endpoint/-ebehaves exactly as before.Verification
--helpoutput for every one of them is byte-identical to a pre-upgrade build.go build ./...andgo vet ./...clean.Notes
The release build already used
-s -w; there was no build-flag win left. The-tags=sqlite,hsm,json1release tags used to add 26 KB viapopand are now inert for this binary.The remaining 37 MB is mostly legitimate:
ory/client-go, the Jsonnet VM (~4.6 MB, powersory dev jsonnet), and theory devtooling (~2.7 MB).Summary by CodeRabbit
New Features
--endpointoption to Hydra-related command-line operations for specifying the target API URL.ORY_SDK_URLenvironment variable.Improvements