coder / envbuilder

Build development environments from a Dockerfile on Docker, Kubernetes, and OpenShift. Enable developers to modify their development environment quickly.
Apache License 2.0
140 stars 26 forks source link

clone via branch does not create a project dir #380

Open ericpaulsen opened 21 hours ago

ericpaulsen commented 21 hours ago

from a prospective customer:

when creating a devcontainer workspace via a direct repo link (e.g. https://github.com/org/repo-name), the envbuilder clones the repo into the repo-name directory, so you get /workspaces/repo-name/… , but when creating via a branch link (e.g. https://github.com/org/repo-name/#refs/heads/jon-coder), the envbuilder seems to clone the repo contents directly into workspaces, so you get /workspaces/

this is blocking their devcontainer use-case with Coder, because their build/service scripts rely on the source path in order to work, so the project not being in /workspaces/repo-name/ is breaking the services.

mafredri commented 10 hours ago

@ericpaulsen I'm trying to reproduce this with envbuilder 1.0 but it seems to work as expected. Could you provide the following additional information:

Edit: This was possibly fixed in #188.

JonathanSun commented 4 minutes ago

I believe it’s a bug in this code: https://github.com/coder/envbuilder/blob/46c97a46b96f3ca12f9718766b7eb610e0f1e80d/options/defaults.go#L20 I’m able to reproduce by testing the code locally on an input like https://github.com/[org]/[repo]/#refs/heads/[branch]

Specifically this line: https://github.com/coder/envbuilder/blob/46c97a46b96f3ca12f9718766b7eb610e0f1e80d/options/defaults.go#L28

For the URL https://github.com/[org]/[repo]/#refs/heads/[branch], this results in name: ["", "[org]", "[repo]", ""] and the last argument ("") is chosen as the repo name instead of the proper name.

The same issue can be noticed by adding an extra / to any non-branch URL, i.e. https://github.com/[org]/[repo]/. Also note that it doesn't matter whether .git is added to the repo identifier or not.