71 lines
1.5 KiB
Go
71 lines
1.5 KiB
Go
package cluster
|
|
|
|
import (
|
|
"errors"
|
|
"fmt"
|
|
"os"
|
|
|
|
"git.badhouseplants.net/allanger/shoebill/internal/config/release"
|
|
"git.badhouseplants.net/allanger/shoebill/internal/lockfile"
|
|
"git.badhouseplants.net/allanger/shoebill/internal/utils/githelper"
|
|
)
|
|
|
|
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
|
|
}
|
|
if err := gh.AddAllAndCommit(workdir, "Bootstrap the shoebill repo"); err != nil {
|
|
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
|
|
}
|