shoebill/internal/config/cluster/cluster.go

71 lines
1.5 KiB
Go
Raw Normal View History

2023-07-20 09:26:25 +00:00
package cluster
import (
"errors"
"fmt"
"os"
2023-08-02 15:00:34 +00:00
"git.badhouseplants.net/allanger/shoebill/internal/config/release"
"git.badhouseplants.net/allanger/shoebill/internal/lockfile"
"git.badhouseplants.net/allanger/shoebill/internal/utils/githelper"
2023-07-20 09:26:25 +00:00
)
type Cluster struct {
// Public
Name string
Git string
Releases []string
Provider string
// Internal
ReleasesObj release.Releases `yaml:"-"`
}
type Clusters []*Cluster
func (c *Cluster) CloneRepo(gh githelper.Githelper, workdir string, dry bool) error {
return gh.CloneRepo(workdir, c.Git, dry)
}
func (c *Cluster) BootstrapRepo(gh githelper.Githelper, workdir string, dry bool) error {
// - Create an empty lockfile
lockfilePath := fmt.Sprintf("%s/%s", workdir, lockfile.LOCKFILE_NAME)
if _, err := os.Stat(lockfilePath); errors.Is(err, os.ErrNotExist) {
file, err := os.Create(lockfilePath)
if err != nil {
return err
}
if _, err := file.WriteString("[]"); err != nil {
return err
}
srcDir := fmt.Sprintf("%s/src", workdir)
if err := os.MkdirAll(srcDir, 0777); err != nil {
return err
}
_, err = os.Create(fmt.Sprintf("%s/.gitkeep", srcDir))
if err != nil {
return err
}
2023-08-02 15:00:34 +00:00
if err := gh.AddAllAndCommit(workdir, "Bootstrap the shoebill repo"); err != nil {
2023-07-20 09:26:25 +00:00
return err
}
if !dry {
if err := gh.Push(workdir); err != nil {
return err
}
}
} else {
return err
}
return nil
}
func (c *Cluster) PopulateReleases(releases release.Releases) {
c.ReleasesObj = releases
}
func (c *Cluster) CreateNewLockfile() error {
return nil
}