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

Support all DOCKER_* environment variables as VS Code settings #998

Merged
merged 5 commits into from
Jun 17, 2019

Conversation

ejizba
Copy link
Contributor

@ejizba ejizba commented Jun 17, 2019

Previously we only supported "docker.host" (aka "DOCKER_HOST") as a VS Code setting. I added support for the 4 main environment variables used in docker machine. Users want these as VS Code settings so that they can have per-workspace setups and so that they can modify a setting without reloading VS Code or changing their environment variables.

Also we were parsing "docker.host" ourselves in the past, which led to a lot of problems because our parsing logic was very simplistic. Instead, I will let docker_modem (a dependency of Dockerode) do all the parsing for us. See here for more info.

Fixes #962
Fixes #914
Fixes #649
Fixes #580
Fixes #216

Related to #646

@ejizba ejizba requested a review from a team as a code owner June 17, 2019 17:19
Eric Jizba and others added 2 commits June 17, 2019 14:51
@@ -293,8 +294,12 @@ export abstract class LocalRootTreeItemBase<TItem extends ILocalItem, TProperty
}

private async getSortedItems(): Promise<TItem[]> {
const items: TItem[] = await this.getItems() || [];
return items.sort((a, b) => a.treeId.localeCompare(b.treeId));
if (ext.dockerodeError === undefined) {
Copy link
Member

Choose a reason for hiding this comment

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

Why have this attached to the extensionVariables rather than just bubbling the error up from refreshDockerode?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Because refreshDockerode gets called in two places:

  1. On extension activation
  2. Every time you update a docker setting

I feel like showing an error in either of those cases is too aggressive and would get annoying. I would rather delay the error and show it in a place that's actually relevant (aka the tree).

Copy link
Member

Choose a reason for hiding this comment

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

I just don't like that it has to be manually reset to undefined. I could see a case where the error is stale or not attached to the right tree node. What happens if you update a bunch of docker settings at once??

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is the current experience
Screen Shot 2019-06-17 at 3 47 46 PM

This is what you might get if I showed the error in refreshDockerode:
Screen Shot 2019-06-17 at 3 49 35 PM

I'm open to suggestions for refactoring the code, but I definitely don't want to change the user experience.

I could see a case where the error is stale or not attached to the right tree node.

Worst case the user has to hit refresh and it won't be stale any more. I don't think it can be attached to the wrong tree node. This logic is unique to LocalRootTreeItemBase, which is the root node for all views (containers, images, volumes, etc.)

What happens if you update a bunch of docker settings at once??

It works? I'm not entirely sure what your concern is.

Copy link
Member

Choose a reason for hiding this comment

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

I was wondering if you could have errors from one treeItem and have it affect another valid treeItem since it's only checking of the ext.dockerodeError is equal to undefined. But I'm not familiar with the code flow for this, so if it doesn't seem like a realistic scenario, I'm totally fine with dropping it. Just wanted to get the reason since it's not a pattern I've seen you use before.

addDockerSettingToEnv("machineName", 'DOCKER_MACHINE_NAME', env);
}

function addDockerSettingToEnv(settingKey: string, envVar: string, env: {}): void {
Copy link
Member

Choose a reason for hiding this comment

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

So VS Code settings are respected above env settings that may currently exist? For instance, DOCKER_HOST would get overridden if I had the host setting in my project?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, that's what users requested. They might have the environment variable set on their machine, but they want VS Code settings to override that on a per-workspace level

Copy link
Member

Choose a reason for hiding this comment

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

It definitely makes sense, but I was wondering if we should alert users in the output that their env variable is getting overwritten. I could totally see myself forgetting I had a setting and wondering why my environment variables weren't being used 😅

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added a warning

@ejizba ejizba merged commit 769d58c into master Jun 17, 2019
@ejizba ejizba deleted the ej/dockerHost branch June 17, 2019 23:40
@microsoft microsoft locked and limited conversation to collaborators Oct 27, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
2 participants