diff --git a/README.md b/README.md index ee906b1f..333c1a72 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,7 @@ Heighliner container images are useful for anyone who's responsible for infrastr Heighliner images are minimally constructed from scratch images, packaging only the chain binary and a useful reduced set of busybox utilities. -This repository has a CI/CD pipeline to automatically build images when new git tags are detected on the chain repos in [chains.yaml](./chains.yaml). These images are hosted as packages in the Github Container Registry (ghcr) [here](https://github.com/orgs/strangelove-ventures/packages?repo_name=heighliner) +This repository has a CI/CD pipeline to automatically build images when new git tags are detected on the chain repos in [chains/](chains). These images are hosted as packages in the Github Container Registry (ghcr) [here](https://github.com/orgs/strangelove-ventures/packages?repo_name=heighliner) @@ -31,7 +31,7 @@ This repository has a CI/CD pipeline to automatically build images when new git ## Add a New Chain -To add a chain to the heighliner built-in configuration and have your chain images available on our repository's [ghcr](https://github.com/orgs/strangelove-ventures/packages?repo_name=heighliner), submit a PR adding it to [chains.yaml](./chains.yaml) so it will be included in the automatic builds. +To add a chain to the heighliner built-in configuration and have your chain images available on our repository's [ghcr](https://github.com/orgs/strangelove-ventures/packages?repo_name=heighliner), submit a PR adding it to the [chains directory](chains) so it will be included in the automatic builds. For further instructions see: [addChain.md](./addChain.md) @@ -115,7 +115,7 @@ export GH_USER=github_username GH_PAT=github_personal_access_token heighliner build -r ghcr.io/strangelove-ventures/heighliner -n 3 ``` -heighliner will fetch the last 3 release tags from github for all chains in [chains.yaml](./chains.yaml), build docker images, and push them. +heighliner will fetch the last 3 release tags from github for all chains in [chains.yaml](chains/01_chains.yaml), build docker images, and push them. diff --git a/chains.yaml b/chains/01_chains.yaml similarity index 100% rename from chains.yaml rename to chains/01_chains.yaml diff --git a/chains/README.md b/chains/README.md new file mode 100644 index 00000000..8cc6300c --- /dev/null +++ b/chains/README.md @@ -0,0 +1,2 @@ +# Chain definition +add your chain file in here, as well as the standard one diff --git a/cmd/build.go b/cmd/build.go index 6719cfa2..4ef8f20b 100644 --- a/cmd/build.go +++ b/cmd/build.go @@ -2,7 +2,9 @@ package cmd import ( "fmt" + "io/fs" "os" + "path" "path/filepath" "github.com/spf13/cobra" @@ -70,19 +72,48 @@ const ( ) func loadChainsYaml(configFile string) error { - if _, err := os.Stat(configFile); err != nil { - return fmt.Errorf("error checking for file: %s: %w", configFile, err) - } - bz, err := os.ReadFile(configFile) + fi, err := os.Stat(configFile) if err != nil { - return fmt.Errorf("error reading file: %s: %w", configFile, err) + return fmt.Errorf("error checking for file: %s: %w", configFile, err) } - var newChains []builder.ChainNodeConfig - err = yaml.Unmarshal(bz, &newChains) - if err != nil { - return fmt.Errorf("error unmarshalling yaml from file: %s: %w", configFile, err) + switch mode := fi.Mode(); { + case mode.IsDir(): + { + dir := os.DirFS(configFile) + configFiles, err := fs.Glob(dir, "*.yaml") + if err != nil { + return fmt.Errorf("error checking for yaml files in : %s: %w", configFile, err) + } + var combinedChains []builder.ChainNodeConfig + for _, v := range configFiles { + bz, err := os.ReadFile(path.Join(configFile, v)) + if err != nil { + return fmt.Errorf("error reading file: %s - %s: %w", configFile, v, err) + } + var newChains []builder.ChainNodeConfig + err = yaml.Unmarshal(bz, &newChains) + if err != nil { + return fmt.Errorf("error unmarshalling yaml from file: %s- %s: %w", configFile, v, err) + } + combinedChains = append(combinedChains, newChains...) + } + chains = combinedChains + } + case mode.IsRegular(): + { + bz, err := os.ReadFile(configFile) + if err != nil { + return fmt.Errorf("error reading file: %s: %w", configFile, err) + } + var newChains []builder.ChainNodeConfig + err = yaml.Unmarshal(bz, &newChains) + if err != nil { + return fmt.Errorf("error unmarshalling yaml from file: %s: %w", configFile, err) + } + chains = newChains + } } - chains = newChains + return nil } @@ -104,7 +135,7 @@ it will be built and pushed`, // try to load a local chains.yaml, but do not panic for any error, will fall back to embedded chains. cwd, err := os.Getwd() if err == nil { - chainsYamlSearchPath := filepath.Join(cwd, "chains.yaml") + chainsYamlSearchPath := filepath.Join(cwd, "chains/") if err := loadChainsYaml(chainsYamlSearchPath); err != nil { fmt.Printf("No config found at %s, using embedded chains. pass -f to configure chains.yaml path.\n", chainsYamlSearchPath) } else { diff --git a/cmd/list.go b/cmd/list.go index 5faee881..b7afbe2e 100644 --- a/cmd/list.go +++ b/cmd/list.go @@ -22,7 +22,7 @@ func loadLocalChainsYaml() error { if err != nil { return err } - chainsYamlSearchPath := filepath.Join(cwd, "chains.yaml") + chainsYamlSearchPath := filepath.Join(cwd, "chains/") err = loadChainsYaml(chainsYamlSearchPath) if err != nil { fmt.Printf("No config found at %s, using embedded chains. pass -f to configure chains.yaml path.\n", chainsYamlSearchPath) diff --git a/main.go b/main.go index dc723189..b694b60b 100644 --- a/main.go +++ b/main.go @@ -6,7 +6,7 @@ import ( "github.com/strangelove-ventures/heighliner/cmd" ) -//go:embed chains.yaml +//go:embed chains/01_chains.yaml var chainsYaml []byte func main() {