Skip to content

Commit

Permalink
feat: add example environment configs
Browse files Browse the repository at this point in the history
  • Loading branch information
Zebradil committed Jun 11, 2023
1 parent b5d7ff9 commit 8edba12
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#@data/values-schema
---
#@overlay/match-child-defaults missing_ok=True
application:
gcpServiceAccountEmail: argocd-repo-server@mykso-dev.iam.gserviceaccount.com
8 changes: 8 additions & 0 deletions internal/myks/assets/envs/mykso/dev/env-data.ytt.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#@data/values
---
environment:
id: mykso-dev
applications:
- proto: argocd
- proto: argocd-apps
- proto: httpbingo
1 change: 1 addition & 0 deletions internal/myks/assets/envs_gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
**/.myks/tmp/
27 changes: 26 additions & 1 deletion internal/myks/globe.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,15 @@ import (
//go:embed assets/env-data.ytt.yaml
var dataSchema []byte

//go:embed assets/prototypes
//go:embed assets/envs_gitignore
var envsGitignore []byte

//go:embed all:assets/prototypes
var prototypesFs embed.FS

//go:embed all:assets/envs
var environmentsFs embed.FS

// Define the main structure
type Globe struct {
/// Globe configuration
Expand Down Expand Up @@ -149,6 +155,11 @@ func (g *Globe) Bootstrap() error {
return err
}

log.Info().Msg("Creating sample environment")
if err := g.createSampleEnvironment(); err != nil {
return err
}

return nil
}

Expand All @@ -157,11 +168,13 @@ func (g *Globe) createBaseFileStructure() error {
protoDir := filepath.Join(g.RootDir, g.PrototypesDir)
renderedDir := filepath.Join(g.RootDir, g.RenderedDir)
dataSchemaFile := filepath.Join(envDir, g.EnvironmentDataFileName)
envsGitignoreFile := filepath.Join(envDir, ".gitignore")

log.Debug().Str("environments directory", envDir).Msg("")
log.Debug().Str("prototypes directory", protoDir).Msg("")
log.Debug().Str("rendered directory", renderedDir).Msg("")
log.Debug().Str("data schema file", dataSchemaFile).Msg("")
log.Debug().Str("environments .gitignore file", envsGitignoreFile).Msg("")

// TODO: interactively ask for confirmation and overwrite without checking
notCleanErr := fmt.Errorf("Target directory is not clean, aborting")
Expand Down Expand Up @@ -194,6 +207,13 @@ func (g *Globe) createBaseFileStructure() error {
return err
}

if _, err := os.Stat(envsGitignoreFile); err == nil {
return notCleanErr
}
if err := os.WriteFile(envsGitignoreFile, envsGitignore, 0o644); err != nil {
return err
}

return nil
}

Expand All @@ -202,6 +222,11 @@ func (g *Globe) createSamplePrototypes() error {
return copyFileSystemToPath(prototypesFs, "assets/prototypes", protoDir)
}

func (g *Globe) createSampleEnvironment() error {
envDir := filepath.Join(g.RootDir, g.EnvironmentBaseDir)
return copyFileSystemToPath(environmentsFs, "assets/envs", envDir)
}

func (g *Globe) collectEnvironments(searchPaths []string) {
if len(searchPaths) == 0 {
searchPaths = []string{g.EnvironmentBaseDir}
Expand Down

0 comments on commit 8edba12

Please sign in to comment.