Default Folder for VSCode

I would like to set the default (start) folder for VSCode to /home/coder/my-project (rather than the default /home/coder. Or as alternative I would like to start a my-project.code-workspace file. How can I accomplish this?
17 Replies
Codercord
Codercordβ€’5mo ago
Codercord
Codercordβ€’5mo ago
<#1374825130030792754>
Category
Help needed
Product
Coder (v2)
Platform
macOS
Logs
Please post any relevant logs/error messages.
Phorcys
Phorcysβ€’5mo ago
you can set dir in your coder_agent resource block, this will set the default dir for everything
Dirk Schiffner
Dirk SchiffnerOPβ€’5mo ago
That does not really work. My project.code-workspace is a file not a folder. It can not be (and must not be) the default folder for everything. For the code-server it works perfectly with the folder property:
module "code-server" {
source = "registry.coder.com/modules/code-server/coder"

...

# open working repo as workspace folder
folder = "/home/coder/ufo-layout"
}
module "code-server" {
source = "registry.coder.com/modules/code-server/coder"

...

# open working repo as workspace folder
folder = "/home/coder/ufo-layout"
}
I am looking for a similar way to tell VSCode Desktop: what to open first (mainly which workspace to open). It would be possible to provide the workspace file as a parameter to code. But this is something the Coder UI is controlling... When I click on the VS Code Desktop button VS Code Desktop is starting and asks me which agent I want to connect to. That's strange... When I click on the button in the UI agent I would have expected to connect to the UI agent. When I click on the button on the DB agent I should be connected to the DB agent. So it would be nice if we could control the behaviour of that VS Code Desktop button in the UI.
matifali
matifaliβ€’5mo ago
Hi @Dirk Schiffner try using the VSCode Desktop module. And setting the folder to your workspace file It will open the right workspace directory https://registry.coder.com/modules/coder/vscode-desktop
Phorcys
Phorcysβ€’5mo ago
you have to use the VSCode Desktop module as Atif pointed out because the built-in one doesn't support setting the folder
Dirk Schiffner
Dirk SchiffnerOPβ€’5mo ago
We are getting closer... First: Thank you - I was not aware of the module registry and this vscode-desktop module. It works and I can jump right into the correct folder.
Dirk Schiffner
Dirk SchiffnerOPβ€’5mo ago
But: I still need to select the agent:
No description
Dirk Schiffner
Dirk SchiffnerOPβ€’5mo ago
Why? The button is already placed in an agent. Both agents are connected to different containers. But regardless which agent I choose - I always end up in the ui agent (container). Hmmm... Maybe the containers are configured in a wrong way. Regardless which agent I connect to (in the VSCode editor - see above), I always end up in a random container, sometimes in the ui container, sometimes in the db container. This happens for the original VSCode Desktop button too. My container configurations:
resource "docker_container" "ui" {
count = data.coder_workspace.me.start_count
image = "codercom/enterprise-base:ubuntu"
# Uses lower() to avoid Docker restriction on container names.
name = local.container_name_ui
# Hostname makes the shell more user friendly: coder@my-workspace:~$
hostname = data.coder_workspace.me.name
# Use the docker gateway if the access URL is 127.0.0.1
entrypoint = ["sh", "-c", replace(coder_agent.ui.init_script, "/localhost|127\\.0\\.0\\.1/", "host.docker.internal")]
env = ["CODER_AGENT_TOKEN=${coder_agent.ui.token}"]
host {
host = "host.docker.internal"
ip = "host-gateway"
}
volumes {
container_path = "/home/coder"
volume_name = docker_volume.ui_volume.name
read_only = false
}

# Add labels in Docker to keep track of orphan resources.
# omitted...
}

resource "docker_container" "db" {
count = data.coder_workspace.me.start_count
image = docker_image.db_image.name # πŸ‘ˆ Reference the built image
name = local.container_name_db
# Hostname makes the shell more user friendly: coder@my-workspace:~$
hostname = "${data.coder_workspace.me.name}-db"
# Use the docker gateway if the access URL is 127.0.0.1
entrypoint = [
"sh", "-c", replace(coder_agent.db.init_script, "/localhost|127\\.0\\.0\\.1/", "host.docker.internal")
]
env = [
"CODER_AGENT_TOKEN=${coder_agent.db.token}",
"POSTGRES_PASSWORD=***redacted***", # βœ… Required
"POSTGRES_USER=***redacted***", # Optional
]
host {
host = "host.docker.internal"
ip = "host-gateway"
}
volumes {
container_path = "/home/coder"
volume_name = docker_volume.db_volume.name
}
}
resource "docker_container" "ui" {
count = data.coder_workspace.me.start_count
image = "codercom/enterprise-base:ubuntu"
# Uses lower() to avoid Docker restriction on container names.
name = local.container_name_ui
# Hostname makes the shell more user friendly: coder@my-workspace:~$
hostname = data.coder_workspace.me.name
# Use the docker gateway if the access URL is 127.0.0.1
entrypoint = ["sh", "-c", replace(coder_agent.ui.init_script, "/localhost|127\\.0\\.0\\.1/", "host.docker.internal")]
env = ["CODER_AGENT_TOKEN=${coder_agent.ui.token}"]
host {
host = "host.docker.internal"
ip = "host-gateway"
}
volumes {
container_path = "/home/coder"
volume_name = docker_volume.ui_volume.name
read_only = false
}

# Add labels in Docker to keep track of orphan resources.
# omitted...
}

resource "docker_container" "db" {
count = data.coder_workspace.me.start_count
image = docker_image.db_image.name # πŸ‘ˆ Reference the built image
name = local.container_name_db
# Hostname makes the shell more user friendly: coder@my-workspace:~$
hostname = "${data.coder_workspace.me.name}-db"
# Use the docker gateway if the access URL is 127.0.0.1
entrypoint = [
"sh", "-c", replace(coder_agent.db.init_script, "/localhost|127\\.0\\.0\\.1/", "host.docker.internal")
]
env = [
"CODER_AGENT_TOKEN=${coder_agent.db.token}",
"POSTGRES_PASSWORD=***redacted***", # βœ… Required
"POSTGRES_USER=***redacted***", # Optional
]
host {
host = "host.docker.internal"
ip = "host-gateway"
}
volumes {
container_path = "/home/coder"
volume_name = docker_volume.db_volume.name
}
}
So the only link to the agent is the entry point...
matifali
matifaliβ€’5mo ago
This looks like a bug report. Could you file a bug on coder/coder GitHub? Please include as many details as you can. I found a related issue. 1. https://github.com/coder/coder/issues/13358 Thanks
GitHub
Problems with adding a coder_app to a coder_agent when there are mu...
I&#39;m having some issues with setting a coder_app for a single coder_agent in a template. When I do, I get a &quot;internal provisionerserver error&quot; (no other errors can be seen) Here&#39;s ...
zounce
zounceβ€’5mo ago
Taking a quick look at the module source:
resource "coder_app" "vscode" {
agent_id = var.agent_id
external = true
icon = "/icon/code.svg"
slug = "vscode"
display_name = "VS Code Desktop"
order = var.order
url = join("", [
"vscode://coder.coder-remote/open",
"?owner=",
data.coder_workspace_owner.me.name,
"&workspace=",
data.coder_workspace.me.name,
var.folder != "" ? join("", ["&folder=", var.folder]) : "",
var.open_recent ? "&openRecent" : "",
"&url=",
data.coder_workspace.me.access_url,
"&token=$SESSION_TOKEN",
])
}
resource "coder_app" "vscode" {
agent_id = var.agent_id
external = true
icon = "/icon/code.svg"
slug = "vscode"
display_name = "VS Code Desktop"
order = var.order
url = join("", [
"vscode://coder.coder-remote/open",
"?owner=",
data.coder_workspace_owner.me.name,
"&workspace=",
data.coder_workspace.me.name,
var.folder != "" ? join("", ["&folder=", var.folder]) : "",
var.open_recent ? "&openRecent" : "",
"&url=",
data.coder_workspace.me.access_url,
"&token=$SESSION_TOKEN",
])
}
The agent name never gets inserted into the URL, so it makes sense this is the case Presumably this was never noticed because multi-agent workspaces aren't very popular, and neither is this module the agent_id field on the coder_app just makes sure the app button appears in the right place in the web UI (so #13358 is unrelated here), the name of the agent must appear in the url in order for the VSCode extension to know which you're connecting to. We'd need to add an (optional?) agent_name field to the module, we're not going to be able to figure it out from the agent ID alone. The provisioners just don't support doing anything like that Actually we could also update the vscode extension to handle &agent=<agent_name> and &agent=<agent_id> (and also update the modle), but we'd be doing so just for this module, so I'm not sure if that's a great idea Same deal with the jetbrains gateway module - we never pass the agent name in The UX of this isn't great too because when we say agent_name, we mean the name of the coder_agent resource, and there's no way to describe that name in Terraform. i.e. you can't do something like coder_agent.main.name to produce main because name isn't a field on the resource - you have to supply "main". The default vscode button in the web ui (from display_apps) doesn’t have this problem because the frontend creates the link itself, instead if it being defined in Terraform. It does so after it’s fetched all the agent info, including the name.
matifali
matifaliβ€’5mo ago
You are spot on Ethan. The reason we removed agent name from gateway plugin and started supporting agent_id is because it's difficult to get in terraform. So if we can handle agent _id in VSCode plugin as we do in JetBrains plugins that's a more suitable solution
zounce
zounceβ€’5mo ago
as we do in JetBrains plugins
If we do handle agent_id in the JetBrains gateway plugin, we're still not passing it in anywhere in the module. the agent_id field on coder_app isn't passed through to the URL.
resource "coder_app" "gateway" {
agent_id = var.agent_id
slug = var.slug
display_name = local.display_name
icon = local.icon
external = true
order = var.order
url = join("", [
"jetbrains-gateway://connect#type=coder&workspace=",
data.coder_workspace.me.name,
"&owner=",
data.coder_workspace_owner.me.name,
"&folder=",
var.folder,
"&url=",
data.coder_workspace.me.access_url,
"&token=",
"$SESSION_TOKEN",
"&ide_product_code=",
data.coder_parameter.jetbrains_ide.value,
"&ide_build_number=",
local.build_number,
"&ide_download_link=",
local.download_link,
])
}
resource "coder_app" "gateway" {
agent_id = var.agent_id
slug = var.slug
display_name = local.display_name
icon = local.icon
external = true
order = var.order
url = join("", [
"jetbrains-gateway://connect#type=coder&workspace=",
data.coder_workspace.me.name,
"&owner=",
data.coder_workspace_owner.me.name,
"&folder=",
var.folder,
"&url=",
data.coder_workspace.me.access_url,
"&token=",
"$SESSION_TOKEN",
"&ide_product_code=",
data.coder_parameter.jetbrains_ide.value,
"&ide_build_number=",
local.build_number,
"&ide_download_link=",
local.download_link,
])
}
matifali
matifaliβ€’5mo ago
We will fix that. Its very rare to have workspace with multiple agents and for a single agent workspace it just works
Dirk Schiffner
Dirk SchiffnerOPβ€’4mo ago
Sorry for being quite - I'm just back from the hospital - almost fit again... Still interested in a solution. I am going to file a bug report. However I am wondering why multi agents are not very popular... May be I am doing something wrong? As I have understood multiple containers means multiple agents - correct? I have an UI project (angular) and a demo database / demo API. I do not want to bring them to the same container. So I have to use multiple agents - right?
Phorcys
Phorcysβ€’4mo ago
yes, you do have to use multi agents in that case the usual use-case when you want separate containers for the same workspaces though is to allow the workspace to run its own Docker instance through Docker in Docker/Kubernetes

Did you find this page helpful?