|
5 | 5 | "os" |
6 | 6 | "path/filepath" |
7 | 7 |
|
| 8 | + "github.com/validatedpatterns/patternizer/internal/embedded" |
8 | 9 | "github.com/validatedpatterns/patternizer/internal/fileutils" |
9 | 10 | "github.com/validatedpatterns/patternizer/internal/helm" |
10 | 11 | "github.com/validatedpatterns/patternizer/internal/pattern" |
@@ -35,44 +36,27 @@ func runInit(withSecrets bool) error { |
35 | 36 | return fmt.Errorf("error processing cluster group values: %w", err) |
36 | 37 | } |
37 | 38 |
|
38 | | - // Copy pattern.sh and Makefile from resources |
39 | | - resourcesDir, err := fileutils.GetResourcesPath() |
40 | | - if err != nil { |
41 | | - return fmt.Errorf("error getting resource path: %w", err) |
42 | | - } |
43 | | - |
44 | | - patternShSrc := filepath.Join(resourcesDir, "pattern.sh") |
45 | | - patternShDst := filepath.Join(repoRoot, "pattern.sh") |
46 | | - if err := fileutils.CopyFile(patternShSrc, patternShDst); err != nil { |
| 39 | + if err := fileutils.WriteEmbeddedFile(embedded.Resources, "resources/pattern.sh", filepath.Join(repoRoot, "pattern.sh"), 0o755); err != nil { |
47 | 40 | return fmt.Errorf("error copying pattern.sh: %w", err) |
48 | 41 | } |
49 | 42 |
|
50 | | - // Always copy ansible.cfg to the pattern repo |
51 | | - ansibleCfgSrc := filepath.Join(resourcesDir, "ansible.cfg") |
52 | | - ansibleCfgDst := filepath.Join(repoRoot, "ansible.cfg") |
53 | | - if err := fileutils.CopyFile(ansibleCfgSrc, ansibleCfgDst); err != nil { |
| 43 | + if err := fileutils.WriteEmbeddedFile(embedded.Resources, "resources/ansible.cfg", filepath.Join(repoRoot, "ansible.cfg"), 0o644); err != nil { |
54 | 44 | return fmt.Errorf("error copying ansible.cfg: %w", err) |
55 | 45 | } |
56 | 46 |
|
57 | | - // Always copy Makefile-common to the pattern repo |
58 | | - makefilePatternSrc := filepath.Join(resourcesDir, "Makefile-common") |
59 | | - makefilePatternDst := filepath.Join(repoRoot, "Makefile-common") |
60 | | - if err := fileutils.CopyFile(makefilePatternSrc, makefilePatternDst); err != nil { |
| 47 | + if err := fileutils.WriteEmbeddedFile(embedded.Resources, "resources/Makefile-common", filepath.Join(repoRoot, "Makefile-common"), 0o644); err != nil { |
61 | 48 | return fmt.Errorf("error copying Makefile-common: %w", err) |
62 | 49 | } |
63 | 50 |
|
64 | | - // Create a simple Makefile that includes Makefile-common (only if it doesn't exist) |
65 | | - makefileSrc := filepath.Join(resourcesDir, "Makefile") |
66 | 51 | makefileDst := filepath.Join(repoRoot, "Makefile") |
67 | 52 | if _, err := os.Stat(makefileDst); os.IsNotExist(err) { |
68 | | - if err := fileutils.CopyFile(makefileSrc, makefileDst); err != nil { |
| 53 | + if err := fileutils.WriteEmbeddedFile(embedded.Resources, "resources/Makefile", makefileDst, 0o644); err != nil { |
69 | 54 | return fmt.Errorf("error copying Makefile: %w", err) |
70 | 55 | } |
71 | 56 | } |
72 | 57 |
|
73 | | - // Handle secrets setup if requested |
74 | 58 | if withSecrets { |
75 | | - if err := fileutils.HandleSecretsSetup(resourcesDir, repoRoot); err != nil { |
| 59 | + if err := fileutils.HandleSecretsSetup(embedded.Resources, repoRoot); err != nil { |
76 | 60 | return fmt.Errorf("error setting up secrets: %w", err) |
77 | 61 | } |
78 | 62 | } |
|
0 commit comments