-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #46 from beclab/feat/local_release
feat: add command to build local release of Olares
- Loading branch information
Showing
9 changed files
with
789 additions
and
210 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
package os | ||
|
||
import ( | ||
"bytetrade.io/web3os/installer/pkg/core/common" | ||
"bytetrade.io/web3os/installer/pkg/core/util" | ||
"bytetrade.io/web3os/installer/pkg/release/builder" | ||
"fmt" | ||
"os" | ||
"os/user" | ||
"path/filepath" | ||
"time" | ||
|
||
"github.com/spf13/cobra" | ||
) | ||
|
||
func NewCmdRelease() *cobra.Command { | ||
var ( | ||
baseDir string | ||
version string | ||
cdn string | ||
ignoreMissingImages bool | ||
extract bool | ||
) | ||
|
||
cmd := &cobra.Command{ | ||
Use: "release", | ||
Short: "Build release based on a local Olares repository", | ||
Run: func(cmd *cobra.Command, args []string) { | ||
cwd, err := os.Getwd() | ||
if err != nil { | ||
fmt.Printf("failed to get current working directory: %s\n", err) | ||
os.Exit(1) | ||
} | ||
if filepath.Base(cwd) != "Olares" { | ||
fmt.Println("error: please run release command under the root path of Olares repo") | ||
os.Exit(1) | ||
} | ||
if baseDir == "" { | ||
usr, err := user.Current() | ||
if err != nil { | ||
fmt.Printf("failed to get current user: %s\n", err) | ||
os.Exit(1) | ||
} | ||
baseDir = filepath.Join(usr.HomeDir, common.DefaultBaseDir) | ||
fmt.Printf("--base-dir unspecified, using: %s\n", baseDir) | ||
time.Sleep(1 * time.Second) | ||
} | ||
|
||
if version == "" { | ||
version = fmt.Sprintf("0.0.0-local-dev-%s", time.Now().Format("20060102150405")) | ||
fmt.Printf("--version unspecified, using: %s\n", version) | ||
time.Sleep(1 * time.Second) | ||
} | ||
|
||
wizardFile, err := builder.NewBuilder(cwd, version, cdn, ignoreMissingImages).Build() | ||
if err != nil { | ||
fmt.Printf("failed to build release: %s\n", err) | ||
os.Exit(1) | ||
} | ||
fmt.Printf("\nsuccessfully built release\nversion: %s\n package: %s\n", version, wizardFile) | ||
if extract { | ||
dest := filepath.Join(baseDir, "versions", "v"+version) | ||
if err := os.MkdirAll(dest, 0755); err != nil { | ||
fmt.Printf("Failed to create new version directory for this release: %s\n", err) | ||
os.Exit(1) | ||
} | ||
if err := util.Untar(wizardFile, dest); err != nil { | ||
fmt.Printf("failed to extract release package: %s\n", err) | ||
os.Exit(1) | ||
} | ||
fmt.Printf("\nrelease package is extracted to: %s\n", dest) | ||
} | ||
}, | ||
} | ||
|
||
cmd.Flags().StringVarP(&baseDir, "base-dir", "b", "", "base directory of Olares, where this release will be extracted to as a new version if --extract/-e is not disabled, defaults to $HOME/"+common.DefaultBaseDir) | ||
cmd.Flags().StringVarP(&version, "version", "v", "", "version of this release, defaults to 0.0.0-local-dev-{yyyymmddhhmmss}") | ||
cmd.Flags().StringVar(&cdn, "download-cdn-url", common.DownloadUrl, "CDN used for downloading checksums of dependencies and images") | ||
cmd.Flags().BoolVar(&ignoreMissingImages, "ignore-missing-images", true, "ignore missing images when downloading cheksums from CDN, only disable this if no new image is added, or the build may fail because the image is not uploaded to the CDN yet") | ||
cmd.Flags().BoolVarP(&extract, "extract", "e", true, "extract this release to --base-dir after build, this can be disabled if only the release file itself is needed") | ||
|
||
return cmd | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
package app | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"path/filepath" | ||
|
||
"bytetrade.io/web3os/installer/pkg/core/util" | ||
) | ||
|
||
type Manager struct { | ||
olaresRepoRoot string | ||
distPath string | ||
} | ||
|
||
func NewManager(olaresRepoRoot, distPath string) *Manager { | ||
return &Manager{ | ||
olaresRepoRoot: olaresRepoRoot, | ||
distPath: distPath, | ||
} | ||
} | ||
|
||
func (m *Manager) Package() error { | ||
modules := []string{"frameworks", "libs", "apps", "third-party"} | ||
buildTemplate := "build/installer" | ||
|
||
// Create dist directory if not exists | ||
if err := os.MkdirAll(m.distPath, 0755); err != nil { | ||
return err | ||
} | ||
|
||
// Copy template files | ||
if err := util.CopyDirectory(buildTemplate, m.distPath); err != nil { | ||
return err | ||
} | ||
|
||
// Package modules | ||
for _, mod := range modules { | ||
if err := m.packageModule(mod); err != nil { | ||
return err | ||
} | ||
} | ||
|
||
// Package launcher and GPU | ||
if err := m.packageLauncher(); err != nil { | ||
return err | ||
} | ||
|
||
if err := m.packageGPU(); err != nil { | ||
return err | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func (m *Manager) packageModule(mod string) error { | ||
modPath := filepath.Join(m.olaresRepoRoot, mod) | ||
entries, err := os.ReadDir(modPath) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
for _, entry := range entries { | ||
if !entry.IsDir() { | ||
continue | ||
} | ||
|
||
app := entry.Name() | ||
|
||
fmt.Printf("packaging %s ... \n", app) | ||
|
||
// Package user app charts | ||
chartPath := filepath.Join(modPath, app, "config/user/helm-charts") | ||
if err := util.CopyDirectoryIfExists(chartPath, filepath.Join(m.distPath, "wizard/config/apps")); err != nil { | ||
return err | ||
} | ||
|
||
// Package cluster CRDs | ||
crdPath := filepath.Join(modPath, app, "config/cluster/crds") | ||
if err := util.CopyDirectoryIfExists(crdPath, filepath.Join(m.distPath, "wizard/config/settings/templates/crds")); err != nil { | ||
return err | ||
} | ||
|
||
// Package cluster deployments | ||
deployPath := filepath.Join(modPath, app, "config/cluster/deploy") | ||
if err := util.CopyDirectoryIfExists(deployPath, filepath.Join(m.distPath, "wizard/config/system/templates/deploy")); err != nil { | ||
return err | ||
} | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func (m *Manager) packageLauncher() error { | ||
fmt.Println("packaging launcher ...") | ||
return util.CopyDirectory( | ||
filepath.Join(m.olaresRepoRoot, "frameworks/bfl/config/launcher"), | ||
filepath.Join(m.distPath, "wizard/config/launcher"), | ||
) | ||
} | ||
|
||
func (m *Manager) packageGPU() error { | ||
fmt.Println("packaging gpu ...") | ||
return util.CopyDirectory( | ||
filepath.Join(m.olaresRepoRoot, "frameworks/GPU/config/gpu"), | ||
filepath.Join(m.distPath, "wizard/config/gpu"), | ||
) | ||
} |
Oops, something went wrong.