Skip to content

Commit d6a7057

Browse files
authored
fix: save anvil docker-compose.yaml to projects dir (#289)
<!-- 🚨 ATTENTION! 🚨 This PR template is REQUIRED. PRs not following this format will be closed without review. Requirements: - PR title must follow commit conventions: https://www.conventionalcommits.org/en/v1.0.0/ - Label your PR with the correct type (e.g., 🐛 Bug, ✨ Enhancement, 🧪 Test, etc.) - Provide clear and specific details in each section --> **Motivation:** <!-- Explain here the context, and why you're making that change. What is the problem you're trying to solve. --> As a devkit user, I want all temp dir usage to happen inside my project so that I do not need any `$TMPDIR` workarounds. **Modifications:** <!-- Describe the modifications you've done from a high level. What are the key technical decisions and why were they made? --> - Writes anvils devnet `docker-compose.yaml` to `./devnet/docker-compose.yaml` **Result:** <!-- *After your change, what will change. --> - All tmpdir usage is now pointing at the project root
1 parent 345f2cb commit d6a7057

File tree

1 file changed

+14
-15
lines changed

1 file changed

+14
-15
lines changed

docker/anvil/devnetembed.go

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package assets
22

33
import (
44
_ "embed"
5+
"fmt"
56
"os"
67
"path/filepath"
78
)
@@ -11,22 +12,20 @@ var DockerCompose []byte
1112

1213
// WriteDockerComposeToPath writes docker-compose.yaml to a fixed path.
1314
func WriteDockerComposeToPath() (string, error) {
14-
dir := filepath.Join(os.TempDir(), "devkit-compose")
15+
// Get project's absolute path
16+
absProjectPath, err := os.Getwd()
17+
if err != nil {
18+
return "", fmt.Errorf("failed to get current working directory: %w", err)
19+
}
20+
// Store anvils docker-compose.yaml in devnet dir at project root
21+
dir := filepath.Join(absProjectPath, "devnet")
1522
if err := os.MkdirAll(dir, 0o755); err != nil {
16-
return "", err
23+
return "", fmt.Errorf("failed to create %s: %w", dir, err)
1724
}
25+
// Write embed each devnet start to ensure any changes are propagated
1826
path := filepath.Join(dir, "docker-compose.yaml")
19-
err := os.WriteFile(path, DockerCompose, 0o644)
20-
return path, err
21-
}
22-
23-
24-
// GetDockerComposePath returns the known path to docker-compose.yaml without writing.
25-
func GetDockerComposePath() string {
26-
return filepath.Join(os.TempDir(), "devkit-compose", "docker-compose.yaml")
27-
}
28-
29-
// GetStateJSONPath returns the known path to state.json without writing.
30-
func GetStateJSONPath() string {
31-
return filepath.Join(os.TempDir(), "devkit-state", "state.json")
27+
if err = os.WriteFile(path, DockerCompose, 0o644); err != nil {
28+
return "", fmt.Errorf("failed to write %s: %w", path, err)
29+
}
30+
return path, nil
3231
}

0 commit comments

Comments
 (0)