Skip to content

Commit

Permalink
Merge pull request #225 from Szubie/bravefile-template
Browse files Browse the repository at this point in the history
Add `brave template` command
  • Loading branch information
idroz committed Dec 2, 2022
2 parents 90818a0 + 014c7be commit 15610d3
Show file tree
Hide file tree
Showing 27 changed files with 115 additions and 23 deletions.
1 change: 1 addition & 0 deletions commands/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ func init() {
BravetoolsCmd.AddCommand(braveVersion)
BravetoolsCmd.AddCommand(braveCompose)
BravetoolsCmd.AddCommand(remoteCmd)
BravetoolsCmd.AddCommand(braveTemplateCmd)

userHome, _ := os.UserHomeDir()
exists, err := shared.CheckPath(path.Join(userHome, shared.PlatformConfig))
Expand Down
34 changes: 34 additions & 0 deletions commands/template.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package commands

import (
"log"
"os"

"github.com/bravetools/bravetools/shared"
"github.com/spf13/cobra"
)

var braveTemplateCmd = &cobra.Command{
Use: "template",
Short: "Generate a template Bravefile",
Long: `Creates an empty template Bravefile in the current directory.`,
Run: generateTemplate,
}

func generateTemplate(cmd *cobra.Command, args []string) {
destPath := "./Bravefile"

if _, err := os.Stat(destPath); err == nil {
log.Fatal("Bravefile already exists in the current directory")
}

f, err := os.Create(destPath)
if err != nil {
log.Fatal(err)
}

_, err = f.Write([]byte(shared.BravefileTemplate))
if err != nil {
log.Fatal(err)
}
}
2 changes: 1 addition & 1 deletion docs/docs/cli/brave_base.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,4 @@ base:
-r, --remote string Name of the remote which will be used to build the base image. (default "local")
```

###### Auto generated by spf13/cobra on 15-Oct-2022
###### Auto generated by spf13/cobra on 2-Dec-2022
2 changes: 1 addition & 1 deletion docs/docs/cli/brave_build.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@ Build an image from a Bravefile
-r, --remote string Name of a Bravetools remote that will build the image. (default "local")
```

###### Auto generated by spf13/cobra on 15-Oct-2022
###### Auto generated by spf13/cobra on 2-Dec-2022
2 changes: 1 addition & 1 deletion docs/docs/cli/brave_compose.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ Compose a system from a set of images
-h, --help help for compose
```

###### Auto generated by spf13/cobra on 15-Oct-2022
###### Auto generated by spf13/cobra on 2-Dec-2022
2 changes: 1 addition & 1 deletion docs/docs/cli/brave_configure.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ Bravetools reads configuration specifications from ~/.bravetools/config.yml and
-h, --help help for configure
```

###### Auto generated by spf13/cobra on 15-Oct-2022
###### Auto generated by spf13/cobra on 2-Dec-2022
2 changes: 1 addition & 1 deletion docs/docs/cli/brave_deploy.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,4 @@ deployment options e.g. CPU and RAM should be configured through [Bravefile](../
--storage string Name of LXD storage pool to use for container
```

###### Auto generated by spf13/cobra on 15-Oct-2022
###### Auto generated by spf13/cobra on 2-Dec-2022
2 changes: 1 addition & 1 deletion docs/docs/cli/brave_images.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ List images
-h, --help help for images
```

###### Auto generated by spf13/cobra on 15-Oct-2022
###### Auto generated by spf13/cobra on 2-Dec-2022
2 changes: 1 addition & 1 deletion docs/docs/cli/brave_import.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ Import LXD image tarballs into local Bravetools image repository
-h, --help help for import
```

###### Auto generated by spf13/cobra on 15-Oct-2022
###### Auto generated by spf13/cobra on 2-Dec-2022
2 changes: 1 addition & 1 deletion docs/docs/cli/brave_info.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@ Display workspace information
--short Returns host IP address
```

###### Auto generated by spf13/cobra on 15-Oct-2022
###### Auto generated by spf13/cobra on 2-Dec-2022
2 changes: 1 addition & 1 deletion docs/docs/cli/brave_init.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,4 @@ These steps ensure that Bravetools establishes a connection with LXD server and
-s, --storage string Host storage size in GB[OPTIONAL]. default: 12 (default "12")
```

###### Auto generated by spf13/cobra on 15-Oct-2022
###### Auto generated by spf13/cobra on 2-Dec-2022
2 changes: 1 addition & 1 deletion docs/docs/cli/brave_mount.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,4 @@ Since Bravetools deploys unprivileged containers, the fact that all uids/gids in
-h, --help help for mount
```

###### Auto generated by spf13/cobra on 15-Oct-2022
###### Auto generated by spf13/cobra on 2-Dec-2022
2 changes: 1 addition & 1 deletion docs/docs/cli/brave_publish.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@ Published Units will be saved in the current working directory as *.tar.gz files
--image_name strings Image names to apply to exported units
```

###### Auto generated by spf13/cobra on 15-Oct-2022
###### Auto generated by spf13/cobra on 2-Dec-2022
2 changes: 1 addition & 1 deletion docs/docs/cli/brave_remote.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ Manage remotes
-h, --help help for remote
```

###### Auto generated by spf13/cobra on 15-Oct-2022
###### Auto generated by spf13/cobra on 2-Dec-2022
4 changes: 2 additions & 2 deletions docs/docs/cli/brave_remote_add.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ Example: brave remote add test https://localhost:8443
--profile string Name of LXD profile to use with this remote. (default "default")
--protocol string LXD server protocol to connect with (e.g. 'lxd', 'simplestreams') (default "lxd")
--public Publicly available server with no authentication
--storage string Name of LXD storage pool to use for container
--storage string Name of LXD storage pool to use for container (default "default")
```

###### Auto generated by spf13/cobra on 15-Oct-2022
###### Auto generated by spf13/cobra on 2-Dec-2022
2 changes: 1 addition & 1 deletion docs/docs/cli/brave_remote_get.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ Returns a JSON string listing configuration of selected remote
-h, --help help for get
```

###### Auto generated by spf13/cobra on 15-Oct-2022
###### Auto generated by spf13/cobra on 2-Dec-2022
2 changes: 1 addition & 1 deletion docs/docs/cli/brave_remote_list.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ List all remotes
-h, --help help for list
```

###### Auto generated by spf13/cobra on 15-Oct-2022
###### Auto generated by spf13/cobra on 2-Dec-2022
2 changes: 1 addition & 1 deletion docs/docs/cli/brave_remote_remove.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ Remove a remote
-h, --help help for remove
```

###### Auto generated by spf13/cobra on 15-Oct-2022
###### Auto generated by spf13/cobra on 2-Dec-2022
2 changes: 1 addition & 1 deletion docs/docs/cli/brave_remove.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@ Remove Units or Images
-i, --image Toggle to delete a local image
```

###### Auto generated by spf13/cobra on 15-Oct-2022
###### Auto generated by spf13/cobra on 2-Dec-2022
2 changes: 1 addition & 1 deletion docs/docs/cli/brave_start.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ Start Units
-h, --help help for start
```

###### Auto generated by spf13/cobra on 15-Oct-2022
###### Auto generated by spf13/cobra on 2-Dec-2022
2 changes: 1 addition & 1 deletion docs/docs/cli/brave_stop.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ Stop Units
-h, --help help for stop
```

###### Auto generated by spf13/cobra on 15-Oct-2022
###### Auto generated by spf13/cobra on 2-Dec-2022
27 changes: 27 additions & 0 deletions docs/docs/cli/brave_template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
---
layout: default
title: brave template
parent: CLI
grand_parent: Docs
nav_order: 1
---

# brave template

Generate a template Bravefile

```
brave template
```

## Description

Creates an empty template Bravefile in the current directory.

## Options

```
-h, --help help for template
```

###### Auto generated by spf13/cobra on 2-Dec-2022
2 changes: 1 addition & 1 deletion docs/docs/cli/brave_umount.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ Unmount <disk> from UNIT
-h, --help help for umount
```

###### Auto generated by spf13/cobra on 15-Oct-2022
###### Auto generated by spf13/cobra on 2-Dec-2022
2 changes: 1 addition & 1 deletion docs/docs/cli/brave_units.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ This function returns a list of all Units deployed on a remote Bravetools host
-h, --help help for units
```

###### Auto generated by spf13/cobra on 15-Oct-2022
###### Auto generated by spf13/cobra on 2-Dec-2022
2 changes: 1 addition & 1 deletion docs/docs/cli/brave_version.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ Show current bravetools version
-h, --help help for version
```

###### Auto generated by spf13/cobra on 15-Oct-2022
###### Auto generated by spf13/cobra on 2-Dec-2022
1 change: 1 addition & 0 deletions docs/docs/cli/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ Available Commands:
remove Remove Units or Images
start Start Units
stop Stop Units
template Generate a template Bravefile
umount Unmount <disk> from UNIT
units List Units
version Show current bravetools version
Expand Down
29 changes: 29 additions & 0 deletions shared/strings.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,34 @@
package shared

// Bravefile template
const BravefileTemplate = `image: example-image/v1.0
base:
image: alpine/3.16
packages:
manager: apk
system:
- curl
run:
- command: echo
args:
- hello world
copy:
- source: ./Bravefile
target: /root/
service:
name: example-container
ports:
- 8888:8888
resources:
ram: 2GB
cpu: 2
`

// REINIT ..
const REINIT = `
Bravetools home directory, settings, and images will be deleted.
Expand Down

0 comments on commit 15610d3

Please sign in to comment.