Is there any way to persist files when restarting a coder workspace?
I’m using coder_agent, and in the startup_script, I have logic that clones a Git repo and runs yarn install. The problem is that the yarn install step takes about 10 minutes, which significantly slows down workspace startup.
However, I only really need this to run the first time the workspace is created — not every time it’s restarted.
I tried adding a check like this:
But the condition always returns false (the repo isn't present). Is there a recommended way to run expensive setup steps only on initial workspace creation, and skip them on restarts?
Thanks in advance!
16 Replies
<#1358895812154888452>
Category
Help needed
Product
Coder (v2)
Platform
Linux
Logs
Please post any relevant logs/error messages.
Still can't make it work
What runtime environment are you running Coder in?
Docker, k8s, VM?
VM, on an EC2 Instance
/close
hey, were you able to get this solved?
apologies for the delays
Yes, I just needed to alocate an EIP manually in my main.tf template
I think it's because of my specific need (VPN, private subnets, etc)
But now it works
I have one question, is there a way to force a port forward in the template? I currently need to add a port (10000) manually in my VSCode port forward
good
thanks for following up
what do you mean?
you can define a
coder_app
resource to have a custom button in the web ui like VSCode and others that points to a specific URL
https://registry.terraform.io/providers/coder/coder/latest/docs/resources/appMy application needs a specific port, it automatically forwards some of them (like in the image), but some of them (like the 10000) I needed to add manually

I don't really know if it's a Coder specific question tbh
VSCode is detecting these ports automatically by what's running in the env and what you're running in the terminal
there should be a way to tell VSCode to automatically forward certain ports but I can't seem to find it, it should be some kind of json file in your project
but honestly i would recommend using
coder_app
s instead, or Coder's port-forwarding feature, it will save you the hassle of having to forward something locallyall these buttons are
coder_app
s and can be configured to reverse-proxy a specific URL through Coder
and the port-forwarding lets you open any http server that's listening in the workspace

of course this is all limited to http/https in the web, so if you need other protocols then VSCode's port-forwarding or
coder port-forward
is your best betFor my team's setup we ended up just extending our config.json file that had some other configs to port forward what we needed, it was only 5 ports so it wasn't much of a problem to do it this way
But thank you so much for taking the time to explain the
coder_app
feature, it will be useful for another part of our projectyeah pretty much
sounds good!
@Phorcys closed the thread.