Skip to content

Move Teleport Connect over to Vite#36921

Merged
gzdunek merged 33 commits intomasterfrom
ryan/connect-vite
Jan 26, 2024
Merged

Move Teleport Connect over to Vite#36921
gzdunek merged 33 commits intomasterfrom
ryan/connect-vite

Conversation

@ryanclark
Copy link
Copy Markdown
Member

@ryanclark ryanclark commented Jan 19, 2024

This moves Connect's build & development tooling over to Vite.

In order to use Vite (which doesn't like CommonJS includes unless it's a 3rd party module), I had to swap over our JS protobuf generation to TypeScript - this is actually a nice advantage, because we can now use the protobuf types in the Teleport codebase. It also fixes a few type issues/FIXMEs in the codebase. I moved user preferences over to using the protobuf files as there was intertwined logic between Teleterm, Teleport & the gRPC representation, so I simplified it.

Sorry for the large PR. These changes were a result of changing one thing and then fixing the errors, changing another, fixing those, etc - it was hard to keep these concise and in separate, ordered commits.

Speed improvements

Start -
Vite - 5.89 seconds
Webpack 22.7 seconds

Build -
Vite - 14.28 seconds
Vite (bytecode) - 168.26 seconds
Webpack - 92.64 seconds

Caveats

The oneOf representation in @protobuf-ts/plugin only works if strictNullChecks is enabled. I tried to enable this, but I couldn't get Connect to only be checked and not Teleport.

To get around this, I added some helpers to ensure type safety. There's only 3 different oneOf values to check in the codebase, and I don't think it's too tedious to add new helpers for new values. If the protobuf representation changes, the types will break, so they will always be in sync.

Things to test

  • Bundling and packaging
    • agentCleanupDaemon.js requires winston, but it's not included in node_modules. Webpack used to bundle it into agentCleanupDaemon.js itself.
  • Passwordless login
  • Shell test plan
    • Detecting $HOME doesn't seem to work, opening a new local shell tab while DocumentCluster is active opens / instead of ~.
  • File transfer
  • Hot module replacement
  • F6 to reload main in dev mode
    • electron-vite supports hot reloading of the main process, but they say "Because the timing of reloading is uncontrollable, hot reloading cannot be perfectly implemented. In practice, hot reloading is not always beneficial,so it is recommended to use the CLI option to flexibly decide whether to enable or not."
  • Removing unreachable code (process.env.NODE_ENV)
  • CSP matches that generated by Webpack
  • yarn dev-term and packaged app are considered to be the same app by Electron, preventing both from running at the same time.
    • Not a blocker, we can deal with this later. Most likely a result of the dev version of the app using the same package.json (and thus package name) as the packaged prod version.
  • Usage events

@ryanclark ryanclark added the no-changelog Indicates that a PR does not require a changelog entry label Jan 19, 2024
@public-teleport-github-review-bot
Copy link
Copy Markdown

@ryanclark - this PR will require admin approval to merge due to its size. Consider breaking it up into a series smaller changes.

@github-actions github-actions Bot requested review from avatus and gzdunek January 19, 2024 12:33
@gzdunek gzdunek requested review from ravicious and removed request for avatus January 19, 2024 12:45
@ryanclark
Copy link
Copy Markdown
Member Author

Note - I had tried to add strictNullChecks, so there may be code changes to account for that, but they're not needed now. Please point out any you see and I'll revert

Comment thread web/packages/teleterm/src/services/tshd/createClient.ts
Copy link
Copy Markdown
Member

@ravicious ravicious left a comment

Choose a reason for hiding this comment

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

I went through the tshd client. I'm yet to build the app, but I definitely want to look into how the final packaged app looks like structure-wise. I can also do a local signed build before we take it to CI.

Comment thread web/packages/teleterm/src/services/tshd/createClient.ts Outdated
Comment thread web/packages/teleterm/src/services/tshd/createClient.ts Outdated
Comment thread web/packages/teleterm/src/services/tshd/createClient.ts Outdated
Comment thread web/packages/teleterm/src/services/tshd/createClient.ts Outdated
Comment thread build.assets/Dockerfile Outdated
@ravicious ravicious self-requested a review January 19, 2024 15:10
Copy link
Copy Markdown

@orca-security-us orca-security-us Bot left a comment

Choose a reason for hiding this comment

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

Orca Security Scan Summary

Status Check Issues by priority
Passed Passed Infrastructure as Code high 0   medium 0   low 0   info 0 View in Orca
Failed Failed Vulnerabilities high 0   medium 1   low 0   info 0 View in Orca
Passed Passed Secrets high 0   medium 0   low 0   info 0 View in Orca

Comment thread web/packages/teleterm/electron.vite.config.mts Outdated
Comment thread package.json Outdated
Comment thread web/packages/teleterm/src/ui/services/workspacesService/workspacesService.ts Outdated
Comment thread web/packages/teleterm/src/helpers.ts Outdated
@ravicious
Copy link
Copy Markdown
Member

Grzegorz and I want to go through Connect's test plan again once we merge this into master and make a dev build off of v15 with these changes. But what about the changes in Web UI, how are we going to test them?

@ravicious
Copy link
Copy Markdown
Member

If we merge it to master and backport to v15 only after a few days, it'll be inconvenient to anyone working on the Web UI code that interacts with types from protos. Once we get everything working in this PR, we should probably do tests on the v15 dev build and only then merge to master, followed by a quick backport to v15.

Comment thread web/packages/teleterm/package.json Outdated
Comment thread .eslintignore Outdated
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Could someone double check this change here?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This change should be fine I think, @gzdunek AFAIK it was to accommodate for some weird Timestamp shenanigans in protos?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think so, I will make sure that the correct date is sent with the usage events.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Except for the wrong environment, usage events are sent correctly.

Comment thread web/packages/teleterm/src/types.ts Outdated
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is so much nicer than how I implemented it!

Copy link
Copy Markdown
Member

@ravicious ravicious left a comment

Choose a reason for hiding this comment

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

I went through the whole PR and everything appears to be okay just from looking at the code alone. We'll run the Connect test plan on 15.0.0-dev.ravicious.10 just to double check.

Copy link
Copy Markdown
Member

@ravicious ravicious left a comment

Choose a reason for hiding this comment

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

Okay, we ran the test plan against v15.0.0-dev.ravicious.10 and it looks everything works fine. What's next, do we wait for the protobuf PRs to land in master?

@ryanclark
Copy link
Copy Markdown
Member Author

Okay, we ran the test plan against v15.0.0-dev.ravicious.10 and it looks everything works fine. What's next, do we wait for the protobuf PRs to land in master?

Yep

Comment thread web/packages/teleport/src/services/userPreferences/userPreferences.ts Outdated
ravicious and others added 8 commits January 26, 2024 12:09
Otherwise process.env in the main process is always replaced with an
object containing just NODE_ENV.

We need process.env to be properly populated since it's then used when
spawning tsh daemon and other processes.

Using define like this guarantees that only callsites using
process.env.NODE_ENV directly will be affected.
@ryanclark ryanclark force-pushed the ryan/connect-vite branch 2 times, most recently from a5410b4 to e9df594 Compare January 26, 2024 11:13
@ryanclark ryanclark mentioned this pull request Jan 26, 2024
Comment thread web/packages/teleterm/src/ui/AppInitializer/AppInitializer.tsx Outdated
@ryanclark ryanclark enabled auto-merge January 26, 2024 14:46
@ryanclark ryanclark added this pull request to the merge queue Jan 26, 2024
@github-merge-queue github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Jan 26, 2024
@gzdunek gzdunek added this pull request to the merge queue Jan 26, 2024
@github-merge-queue github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Jan 26, 2024
@gzdunek gzdunek added this pull request to the merge queue Jan 26, 2024
Merged via the queue into master with commit 200553c Jan 26, 2024
@gzdunek gzdunek deleted the ryan/connect-vite branch January 26, 2024 16:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

no-changelog Indicates that a PR does not require a changelog entry size/xl ui

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants