Skip to content

Commit ab6799a

Browse files
blinkagent[bot]blink-so[bot]mdanter
authored
fix(git-clone): use unique temp file for post_clone_script to avoid race condition (#601)
## Summary Fixes a race condition when multiple `git-clone` modules with `post_clone_script` run concurrently. ## Problem All instances of the git-clone module use the same hardcoded `/tmp/post_clone.sh` path. When multiple modules run concurrently (or overlap), they collide on the same temp file, causing: ``` rm: cannot remove '/tmp/post_clone.sh': No such file or directory ``` This results in a non-zero exit code, causing the workspace to appear unhealthy. ## Solution Use `mktemp` to generate a unique temporary filename for each module instance: ```bash POST_CLONE_TMP=$(mktemp /tmp/post_clone_XXXXXX.sh) ``` This ensures each concurrent execution uses its own temp file, eliminating the race condition. Fixes #600 --------- Co-authored-by: blink-so[bot] <211532188+blink-so[bot]@users.noreply.github.com> Co-authored-by: Matyas Danter <[email protected]>
1 parent bda3eb9 commit ab6799a

File tree

2 files changed

+21
-16
lines changed

2 files changed

+21
-16
lines changed

registry/coder/modules/git-clone/README.md

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ This module allows you to automatically clone a repository by URL and skip if it
1414
module "git-clone" {
1515
count = data.coder_workspace.me.start_count
1616
source = "registry.coder.com/coder/git-clone/coder"
17-
version = "1.2.2"
17+
version = "1.2.3"
1818
agent_id = coder_agent.example.id
1919
url = "https://github.com/coder/coder"
2020
}
@@ -28,7 +28,7 @@ module "git-clone" {
2828
module "git-clone" {
2929
count = data.coder_workspace.me.start_count
3030
source = "registry.coder.com/coder/git-clone/coder"
31-
version = "1.2.2"
31+
version = "1.2.3"
3232
agent_id = coder_agent.example.id
3333
url = "https://github.com/coder/coder"
3434
base_dir = "~/projects/coder"
@@ -43,11 +43,12 @@ To use with [Git Authentication](https://coder.com/docs/v2/latest/admin/git-prov
4343
module "git-clone" {
4444
count = data.coder_workspace.me.start_count
4545
source = "registry.coder.com/coder/git-clone/coder"
46-
version = "1.2.2"
46+
version = "1.2.3"
4747
agent_id = coder_agent.example.id
4848
url = "https://github.com/coder/coder"
4949
}
5050
51+
5152
data "coder_external_auth" "github" {
5253
id = "github"
5354
}
@@ -69,11 +70,12 @@ data "coder_parameter" "git_repo" {
6970
module "git_clone" {
7071
count = data.coder_workspace.me.start_count
7172
source = "registry.coder.com/coder/git-clone/coder"
72-
version = "1.2.2"
73+
version = "1.2.3"
7374
agent_id = coder_agent.example.id
7475
url = data.coder_parameter.git_repo.value
7576
}
7677
78+
7779
# Create a code-server instance for the cloned repository
7880
module "code-server" {
7981
count = data.coder_workspace.me.start_count
@@ -103,13 +105,14 @@ Configuring `git-clone` for a self-hosted GitHub Enterprise Server running at `g
103105
module "git-clone" {
104106
count = data.coder_workspace.me.start_count
105107
source = "registry.coder.com/coder/git-clone/coder"
106-
version = "1.2.2"
108+
version = "1.2.3"
107109
agent_id = coder_agent.example.id
108110
url = "https://github.example.com/coder/coder/tree/feat/example"
109111
git_providers = {
110112
"https://github.example.com/" = {
111113
provider = "github"
112114
}
115+
113116
}
114117
}
115118
```
@@ -122,7 +125,7 @@ To GitLab clone with a specific branch like `feat/example`
122125
module "git-clone" {
123126
count = data.coder_workspace.me.start_count
124127
source = "registry.coder.com/coder/git-clone/coder"
125-
version = "1.2.2"
128+
version = "1.2.3"
126129
agent_id = coder_agent.example.id
127130
url = "https://gitlab.com/coder/coder/-/tree/feat/example"
128131
}
@@ -134,13 +137,14 @@ Configuring `git-clone` for a self-hosted GitLab running at `gitlab.example.com`
134137
module "git-clone" {
135138
count = data.coder_workspace.me.start_count
136139
source = "registry.coder.com/coder/git-clone/coder"
137-
version = "1.2.2"
140+
version = "1.2.3"
138141
agent_id = coder_agent.example.id
139142
url = "https://gitlab.example.com/coder/coder/-/tree/feat/example"
140143
git_providers = {
141144
"https://gitlab.example.com/" = {
142145
provider = "gitlab"
143146
}
147+
144148
}
145149
}
146150
```
@@ -155,7 +159,7 @@ For example, to clone the `feat/example` branch:
155159
module "git-clone" {
156160
count = data.coder_workspace.me.start_count
157161
source = "registry.coder.com/coder/git-clone/coder"
158-
version = "1.2.2"
162+
version = "1.2.3"
159163
agent_id = coder_agent.example.id
160164
url = "https://github.com/coder/coder"
161165
branch_name = "feat/example"
@@ -173,7 +177,7 @@ For example, this will clone into the `~/projects/coder/coder-dev` folder:
173177
module "git-clone" {
174178
count = data.coder_workspace.me.start_count
175179
source = "registry.coder.com/coder/git-clone/coder"
176-
version = "1.2.2"
180+
version = "1.2.3"
177181
agent_id = coder_agent.example.id
178182
url = "https://github.com/coder/coder"
179183
folder_name = "coder-dev"
@@ -191,8 +195,8 @@ If not defined, the default, `0`, performs a full clone.
191195
```tf
192196
module "git-clone" {
193197
count = data.coder_workspace.me.start_count
194-
source = "registry.coder.com/modules/git-clone/coder"
195-
version = "1.2.2"
198+
source = "registry.coder.com/coder/git-clone/coder"
199+
version = "1.2.3"
196200
agent_id = coder_agent.example.id
197201
url = "https://github.com/coder/coder"
198202
depth = 1
@@ -208,7 +212,7 @@ This is useful for running initialization tasks like installing dependencies or
208212
module "git-clone" {
209213
count = data.coder_workspace.me.start_count
210214
source = "registry.coder.com/coder/git-clone/coder"
211-
version = "1.2.2"
215+
version = "1.2.3"
212216
agent_id = coder_agent.example.id
213217
url = "https://github.com/coder/coder"
214218
post_clone_script = <<-EOT

registry/coder/modules/git-clone/run.sh

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,10 @@ fi
5858
# Run post-clone script if provided
5959
if [ -n "$POST_CLONE_SCRIPT" ]; then
6060
echo "Running post-clone script..."
61-
echo "$POST_CLONE_SCRIPT" | base64 -d > /tmp/post_clone.sh
62-
chmod +x /tmp/post_clone.sh
61+
POST_CLONE_TMP=$(mktemp)
62+
echo "$POST_CLONE_SCRIPT" | base64 -d > "$POST_CLONE_TMP"
63+
chmod +x "$POST_CLONE_TMP"
6364
cd "$CLONE_PATH" || exit
64-
/tmp/post_clone.sh
65-
rm /tmp/post_clone.sh
65+
$POST_CLONE_TMP
66+
rm "$POST_CLONE_TMP"
6667
fi

0 commit comments

Comments
 (0)