Skip to content

Commit

Permalink
feat: enable a directory of chain configurations instead of a single …
Browse files Browse the repository at this point in the history
…file
  • Loading branch information
PFC-developer committed Sep 20, 2024
1 parent 64301f4 commit a891281
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 17 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.yaml](chains/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)



Expand All @@ -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 [chains.yaml](chains/chains.yaml) so it will be included in the automatic builds.

For further instructions see: [addChain.md](./addChain.md)

Expand Down Expand Up @@ -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/chains.yaml), build docker images, and push them.



Expand Down
2 changes: 1 addition & 1 deletion chains.yaml → chains/01_chains.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1332,4 +1332,4 @@
binaries:
- /go/bin/xplad
build-env:
- BUILD_TAGS=muslc
- BUILD_TAGS=muslc
2 changes: 2 additions & 0 deletions chains/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Chain definition
add your chain file in here, as well as the standard one
53 changes: 42 additions & 11 deletions cmd/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ package cmd

import (
"fmt"
"io/fs"
"os"
"path"
"path/filepath"

"github.com/spf13/cobra"
Expand Down Expand Up @@ -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: %w", configFile, 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
}

Expand All @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion cmd/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down

0 comments on commit a891281

Please sign in to comment.