Skip to content

Commit

Permalink
Merge pull request #16 from bravetools/release-1.54
Browse files Browse the repository at this point in the history
Release 1.54
  • Loading branch information
Aleks Drozdov committed Oct 4, 2020
2 parents 087a3e5 + bef1f18 commit b1a0305
Show file tree
Hide file tree
Showing 41 changed files with 874 additions and 381 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Expand Up @@ -14,4 +14,7 @@ vagrant/.vagrant
vagrant/*.log

install/darwin/brave
install/ubuntu/brave
install/ubuntu/brave

db/bravetoolsdb/*.db
db/bravetoolsdb/bravetoolsdb
23 changes: 17 additions & 6 deletions README.md
Expand Up @@ -19,7 +19,17 @@ To get started using Bravetools, download a platform-specific binary and add it

To learn more about using Bravetools, please refer to our [Bravetools Documentation](https://bravetools.github.io/bravetools/).

## Install from Source
## Installation

Ensure that your user is part of the `lxd group`:
```bash
sudo usermod --append --groups lxd USER
```

You may also need to install `zfsutils`:
```bash
sudo apt install zfsutils-linux
```

### Ubuntu

Expand All @@ -30,17 +40,16 @@ To learn more about using Bravetools, please refer to our [Bravetools Documentat
* 4GB of Memory
* Software
* [Go](https://golang.org/)
* [LXD 4.3](https://linuxcontainers.org/lxd/getting-started-cli/)

> **NOTE**: LXD up to 3.0.x were published as non-snap versions. Bravetools will not work with these distributions. The user is encouraged to use snap-LXD before continuing with installation.
* [LXD >3.0.3](https://linuxcontainers.org/lxd/getting-started-cli/)

```bash
git clone https://github.com/bravetools/bravetools
cd bravetools
make ubuntu
brave init
```

If this is your first time setting up Bravetools, run `brave init` to initialise the required profile, storage pool, and LXD bridge.

### Mac OS

**Minimum Requirements**
Expand All @@ -56,9 +65,11 @@ brave init
git clone https://github.com/bravetools/bravetools
cd bravetools
make darwin
brave init
```

If this is your first time setting up Bravetools, run `brave init` to initialise the required profile, storage pool, and LXD bridge.


### Windows

**Minimum Requirements**
Expand Down
2 changes: 1 addition & 1 deletion VERSION
@@ -1 +1 @@
release-1.53
release-1.54
18 changes: 17 additions & 1 deletion commands/base.go
@@ -1,6 +1,7 @@
package commands

import (
"errors"
"fmt"
"log"
"os"
Expand Down Expand Up @@ -41,7 +42,22 @@ func buildBase(cmd *cobra.Command, args []string) {
}
}

fmt.Println("Building base unit: ", bravefile.PlatformService.Name)
// Resource checks
info, err := backend.Info()

usedDiskSize, err := shared.SizeCountToInt(info.Disk[0])
if err != nil {
log.Fatal(err)
}
totalDiskSize, err := shared.SizeCountToInt(info.Disk[1])
if err != nil {
log.Fatal(err)
}

if (totalDiskSize - usedDiskSize) < 5000000000 {
err = errors.New("Not enough free storage on disk")
log.Fatal(err)
}

err = host.BuildUnit(bravefile)
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions commands/commands.go
Expand Up @@ -77,7 +77,7 @@ func setBackend(host platform.BraveHost) error {
return nil
}

func createLocalDirectories(userHome string) error {
func createBraveHome(userHome string) error {
err := shared.CreateDirectory(path.Join(userHome, ".bravetools"))
err = shared.CreateDirectory(path.Join(userHome, ".bravetools", "certs"))
err = shared.CreateDirectory(path.Join(userHome, ".bravetools", "images"))
Expand All @@ -88,7 +88,7 @@ func createLocalDirectories(userHome string) error {
return nil
}

func deleteLocalDirectories(userHome string) error {
func deleteBraveHome(userHome string) error {
exists, err := shared.CheckPath(path.Join(userHome, shared.PlatformConfig))
if err != nil {
return err
Expand Down
147 changes: 100 additions & 47 deletions commands/init.go
@@ -1,12 +1,13 @@
package commands

import (
"errors"
"bufio"
"fmt"
"log"
"os"
"path"
"runtime"
"strings"

"github.com/bravetools/bravetools/platform"
"github.com/bravetools/bravetools/shared"
Expand Down Expand Up @@ -36,31 +37,24 @@ func includeInitFlags(cmd *cobra.Command) {

func serverInit(cmd *cobra.Command, args []string) {
userHome, _ := os.UserHomeDir()

params := make(map[string]string)

braveHome := false
if _, err := os.Stat(path.Join(userHome, ".bravetools")); !os.IsNotExist(err) {
msg := errors.New("Bravetools is already initialised. Run \"brave configure\" if you'd like to tweak configuration")
log.Fatal(msg.Error())
braveHome = true
}

err := createLocalDirectories(userHome)
braveProfile := true
remote := host.Remote
_, err := platform.GetBraveProfile(remote)
if err != nil {
log.Fatal(err.Error())
}

if storage == "" {
storage = "12"
//fmt.Println("Brave profile: ", err)
braveProfile = false
}
params["storage"] = storage
if ram == "" {
ram = "4GB"
if err == nil {
braveProfile = true
}
params["ram"] = ram
if network == "" {
network = "10.0.0.1"
}
params["network"] = network

if backendType == "" {
hostOs := runtime.GOOS
switch hostOs {
Expand All @@ -71,53 +65,112 @@ func serverInit(cmd *cobra.Command, args []string) {
case "windows":
backendType = "multipass"
default:
err := deleteLocalDirectories(userHome)
err := deleteBraveHome(userHome)
if err != nil {
log.Fatal(err.Error())
}
fmt.Println(runtime.GOOS)
fmt.Println("Unsupported OS")
}
}
params["backend"] = backendType

if hostConfigPath != "" {
// TODO: validate configuration. Now assume that path ends with config.yml
err = shared.CopyFile(hostConfigPath, path.Join(userHome, ".bravetools", "config.yml"))
if braveHome == false && braveProfile == false {
err = createBraveHome(userHome)
if err != nil {
log.Fatal(err)
log.Fatal(err.Error())
}
} else {
userHome, _ := os.UserHomeDir()
platform.SetupHostConfiguration(params, userHome)
loadConfig()
}

loadConfig()
err = backend.BraveBackendInit()
if err != nil {
log.Fatal(err)
}
if storage == "" {
storage = "12"
}
params["storage"] = storage
if ram == "" {
ram = "4GB"
}
params["ram"] = ram
if network == "" {
network = "10.0.0.1"
}
params["network"] = network
params["backend"] = backendType

loadConfig()
if backendType == "multipass" {
info, err := backend.Info()
if err != nil {
log.Fatal(err)
if hostConfigPath != "" {
// TODO: validate configuration. Now assume that path ends with config.yml
err = shared.CopyFile(hostConfigPath, path.Join(userHome, ".bravetools", "config.yml"))
if err != nil {
log.Fatal(err)
}
loadConfig()
} else {
userHome, _ := os.UserHomeDir()
platform.SetupHostConfiguration(params, userHome)
loadConfig()
}
settings := host.Settings

settings.BackendSettings.Resources.IP = info.IPv4
err = platform.UpdateBraveSettings(settings)
err = backend.BraveBackendInit()
if err != nil {
log.Fatal(err)
fmt.Println("Error initializing Bravetools backend: ", err)
//log.Fatal(shared.REMOVELIN)
}

loadConfig()
}

err = host.AddRemote()
if err != nil {
log.Fatal(err)
if backendType == "multipass" {
info, err := backend.Info()

if err != nil {
log.Fatal(err)
}

settings := host.Settings
settings.BackendSettings.Resources.IP = info.IPv4
err = platform.UpdateBraveSettings(settings)

if err != nil {
log.Fatal(err)
}

loadConfig()
}

err = host.AddRemote()
if err != nil {
log.Fatal(err)
}
} else {
scanner := bufio.NewScanner(os.Stdin)
for {
fmt.Println(shared.REINIT)
scanner.Scan()
in := scanner.Text()
in = strings.ToLower(in)
if in == "yes" || in == "y" {
if backendType == "multipass" {
log.Fatal(shared.REMOVEMP)
} else {
p := path.Join(userHome, ".bravetools/")

if braveHome == false {
log.Fatal(shared.REMOVELIN)
} else {

err1 := os.RemoveAll(p)
err2 := platform.DeleteProfile(host.Settings.Profile, remote)
err3 := platform.DeleteStoragePool(host.Settings.StoragePool.Name, remote)
err4 := platform.DeleteNetwork("bravebr0", remote)

if err1 != nil || err2 != nil || err3 != nil || err4 != nil {
log.Fatal(shared.REMOVELIN)
}
}
}

break
} else if in == "no" || in == "n" {
break
} else {
continue
}
}
}
}
4 changes: 2 additions & 2 deletions commands/mount.go
Expand Up @@ -12,7 +12,7 @@ import (
var mountDir = &cobra.Command{
Use: "mount [UNIT:]<source> UNIT:<target>",
Short: "Mount a directory to a Unit",
Long: `mount supports local directories as well as shared directories between Units.`,
Long: `mount local directories as well as shared volumes between Units.`,
Run: mount,
}

Expand All @@ -28,7 +28,7 @@ func mount(cmd *cobra.Command, args []string) {
log.Fatal("Target directory should be specified as UNIT:<target>")
}

err := host.MountDirectory(remote[0], args[0], remote[1])
err := host.MountShare(args[0], remote[0], remote[1])
if err != nil {
log.Fatal(err)
}
Expand Down
2 changes: 1 addition & 1 deletion commands/umount.go
Expand Up @@ -28,7 +28,7 @@ func umount(cmd *cobra.Command, args []string) {
log.Fatal("Target directory should be specified as UNIT:<disk>")
}

err := host.UmountDirectory(remote[0], remote[1])
err := host.UmountShare(remote[0], remote[1])
if err != nil {
log.Fatal(err)
}
Expand Down
Binary file modified db/bravetoolsdb/bravetoolsdb
Binary file not shown.
12 changes: 6 additions & 6 deletions db/db_operations.go
Expand Up @@ -13,7 +13,7 @@ import (

// OpenDB opens database
func OpenDB(filepath string) *sql.DB {
log.Println("Initialising SQlite database " + filepath)
//log.Println("Initialising SQlite database " + filepath)
db, err := sql.Open("sqlite3", filepath)
if err != nil {
log.Fatal(err)
Expand All @@ -29,7 +29,7 @@ func OpenDB(filepath string) *sql.DB {
func InitDB(filepath string) error {

//os.Remove(filepath)
log.Println("Creating database. ", filepath)
//log.Println("Creating database. ", filepath)
file, err := os.Create(filepath)
if err != nil {
log.Fatal(err)
Expand Down Expand Up @@ -73,7 +73,7 @@ func InsertUnitDB(db *sql.DB, unit BraveUnit) (int64, error) {
return 0, errors.New("Unit already exists")
}

log.Println("Inserting unit ..")
//log.Println("Inserting unit ..")
insertUnit := `INSERT INTO units(uid,
name,
date,
Expand All @@ -92,7 +92,7 @@ func InsertUnitDB(db *sql.DB, unit BraveUnit) (int64, error) {
return 0, errors.New("Failed to execute SQL statement " + err.Error())
}

log.Printf("Unit inserted. Unit name: %v", unit.Name)
//log.Printf("Unit inserted. Unit name: %v", unit.Name)

id, _ := r.LastInsertId()

Expand All @@ -102,7 +102,7 @@ func InsertUnitDB(db *sql.DB, unit BraveUnit) (int64, error) {
// DeleteUnitDB deletes a unit from database
func DeleteUnitDB(db *sql.DB, name string) error {
defer db.Close()
log.Println("Deleting unit ...")
//log.Println("Deleting unit ...")
var sql = `DELETE FROM units WHERE name=?;`
statement, err := db.Prepare(sql)
if err != nil {
Expand All @@ -118,7 +118,7 @@ func DeleteUnitDB(db *sql.DB, name string) error {
return errors.New("No records to delete")
}

log.Println("Unit deleted: ", name)
//log.Println("Unit deleted: ", name)
return nil
}

Expand Down

0 comments on commit b1a0305

Please sign in to comment.