Skip to content

Refactor CLI manager to support multiple deployments #213

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

Merged
merged 21 commits into from
Apr 7, 2023

Conversation

code-asher
Copy link
Member

@code-asher code-asher commented Mar 31, 2023

This is just phase one; the SSH config itself does not support multiple deployments yet. For that I think I will end up doing a prefix thing just like our VS Code extension does.

I enabled auto-formatting so there are a bunch of added newlines, indents, and import optimizations. Edit: Going to remove these changes, too much noise in the PR. Also should be using explicit imports as that is the general practice. Done.

More info in the commit messages.

@code-asher code-asher changed the base branch from main to update-platform-version March 31, 2023 01:12
@code-asher code-asher force-pushed the refactor-cli-manager branch 9 times, most recently from 0e8c4e0 to 171555b Compare March 31, 2023 21:13
Base automatically changed from update-platform-version to main March 31, 2023 21:18
@code-asher code-asher force-pushed the refactor-cli-manager branch 5 times, most recently from fa39f57 to 49235fb Compare March 31, 2023 23:37
Also rename the function since it loads all workspaces, not just one.
Since the comments are now out of date I removed them; I figure it is
more or less as easy to just read the workflow to see what it does.
@code-asher code-asher force-pushed the refactor-cli-manager branch 6 times, most recently from a522c74 to b5ef3df Compare April 3, 2023 16:36
@code-asher code-asher marked this pull request as ready for review April 3, 2023 17:07
@code-asher code-asher requested a review from johnstcn April 3, 2023 17:07
@code-asher code-asher marked this pull request as draft April 3, 2023 20:50
Currently multiple deployments will delete each other's binaries so this
uses a directory for each deployment host to store the binaries.

Add a catch for download errors; previously they would go unnoticed.
Also refactor the download a little; instead of checking for the file's
existence catch the appropriate error and set the permissions from
Kotlin code rather than spawning chmod.

Remove a chunk of code where we configure the CLI again before moving to
the next step; we already do that when we first connect (plus it is
missing some checks like making sure the CLI has actually been
downloaded and is the right version, etc).  This also makes it
unnecessary to globally store the version and CLI path on the model
since we now only do it in one spot.

This is just a first step; in a future PR the config code will all be
extracted out since we will want to configure every time we try to
connect (rather than just in the initial setup step) since otherwise the
recent connections can fail if you have configured a different
deployment in the meantime (and probably reconnections would also fail
if you already have an IDE open) or if you have restarted (since the
binaries are currently in tmp).  We will also need to configure
ourselves since `config-ssh` does not support multiple deployments and
we want to add an environment variable via SetEnv.
We will need to create a new function for config-ssh anyway since we
will be doing our own thing rather than spawning the CLI in order to
support multiple deployments so this preemptively encapsulates that
logic.
@code-asher code-asher force-pushed the refactor-cli-manager branch from b5ef3df to 125b1f2 Compare April 3, 2023 21:08
@code-asher code-asher marked this pull request as ready for review April 3, 2023 21:10
Copy link
Member

@johnstcn johnstcn left a comment

Choose a reason for hiding this comment

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

My only concern is how we handle the old-CLI-version deleting; I'd like for us to be super careful about deleting anything from user's local systems.

This way we will not need to name the binaries with their versions or
otherwise extract the version from each binary since we can just grab
their hash and set that in the request.  This also means we will not
need to remove old versions as there will only be the one file.
The @jvmoverloads annotations make Kotlin generate overloads otherwise
the test code thinks the optional arguments are not optional.
@code-asher code-asher force-pushed the refactor-cli-manager branch from 0241244 to 6636f31 Compare April 5, 2023 20:19
@code-asher code-asher marked this pull request as draft April 5, 2023 21:13
@code-asher code-asher force-pushed the refactor-cli-manager branch 3 times, most recently from c0805a2 to 6a0895a Compare April 5, 2023 23:43
Environment variables can be used to test against a real deployment.

I now just check if the file is executable rather than trying to
actually execute it since we would need to actually compile something
that can run as a .exe on Windows.
@code-asher code-asher force-pushed the refactor-cli-manager branch from 6a0895a to 9b0d21e Compare April 5, 2023 23:53
Copy link
Member

@johnstcn johnstcn left a comment

Choose a reason for hiding this comment

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

👍

@code-asher code-asher force-pushed the refactor-cli-manager branch from 48e19fd to 0c47258 Compare April 6, 2023 18:14
That is enough to prove the downloading works and the rest can just test
their own extra assumptions on top of that.
@code-asher code-asher force-pushed the refactor-cli-manager branch from c8db570 to 1e87ae3 Compare April 6, 2023 19:20
@code-asher code-asher marked this pull request as ready for review April 6, 2023 19:32
def ccm = new CoderCLIManager(new URL("https://test.😉.invalid"))

expect:
ccm.localBinaryPath.getParent() == CoderCLIManager.getDataDir().resolve("test.xn--n28h.invalid")
Copy link
Member

Choose a reason for hiding this comment

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

👍

Comment on lines +109 to +112
def url = System.getenv("CODER_GATEWAY_TEST_DEPLOYMENT")
if (url == null) {
url = "https://dev.coder.com"
}
Copy link
Member

Choose a reason for hiding this comment

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

nice!

private fun getBinaryETag(): String? {
try {
return try {
Copy link
Member

Choose a reason for hiding this comment

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

👀 this is a cool thing that I didn't know was a thing!

Copy link
Member Author

Choose a reason for hiding this comment

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

Same!! Thank goodness for IDE suggestions lol

@code-asher code-asher merged commit f311f16 into main Apr 7, 2023
@code-asher code-asher deleted the refactor-cli-manager branch April 7, 2023 20:01
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.

2 participants