Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
184 changes: 87 additions & 97 deletions cli/README.md
Original file line number Diff line number Diff line change
@@ -1,121 +1,111 @@
# HomeCloud CLI
Got it — let’s clean up the S3 section to match the brief style of `compute`:

This folder contains the implementation of the HomeCloud CLI tool. The CLI interacts with HomeCloud services and manages various aspects of the system, with an enhanced focus on compute resources using Docker containers.
---

## Folder Structure
# HomeCloud CLI

This folder contains the implementation of the HomeCloud CLI tool. The CLI interacts with HomeCloud services and manages various aspects of the system, including compute resources (Docker containers) and S3-compatible storage.

---

## 📁 Folder Structure

```plaintext
cli/
├── cmd/
│ ├── root.go # Root command of the CLI
│ ├── compute/ # Component specifc folder
├── compute.go # Subcommand for managing compute resources (Docker-based)
│ ├── config.go # Subcommand for managing CLI configurations
│ ├── compute/ # Compute management commands
├── s3/ # S3 storage management commands
│ ├── config.go # Configuration management commands
├── main.go # Entry point for the CLI application
├── go.mod # Go module file
```

## Commands Overview

### Root Command
- The base command for the CLI, defined in `cmd/root.go`.
- Provides help and global options for the CLI.

### `compute` Command
- **Purpose**: Manages compute resources using Docker containers.
- **Operations**:
- **create**: Create a new Docker container and register it as a compute instance.
- **list**: List all compute instances (Docker containers).
- **start**: Start a stopped Docker container and update its status.
- **enter**: Enter a Docker container interactively.
- **stop**: Stop a running Docker container and update its status.
- **delete**: Delete a Docker container and remove its registration.

Implemented in `cmd/compute.go`.

### `config` Command
- **Purpose**: Manages configuration for the CLI.
- Includes:
- `set`: Updates configuration values (e.g., API endpoint).
- `get`: Retrieves configuration values.

Implemented in `cmd/config.go`.

## Configuration
- Configurations are stored in a JSON file located at `~/.homecloud_config.json`.
- Example keys:
- `api_endpoint`: Specifies the API endpoint for HomeCloud.

## Getting Started
1. Navigate to the `cli` folder.
2. Run the CLI:
```bash
go run main.go
```
3. Explore the available commands:
```bash
go run main.go --help
```
---

## `compute` Command Detailed Usage

### `compute create`
- **Description**: Create a new compute instance (Docker container).
- **Flags**:
- `--name` or `-n` (required): Name of the container/instance.
- `--cpu` or `-c` (default: 1): Number of CPU cores.
- `--ram` or `-r` (default: 512MB): Amount of RAM in MB.
- `--storage` or `-s` (default: 10GB): Storage size in GB.
- `--image` or `-i` (default: "python:3.10-alpine"): Base image for the container.

- **Example**:
```bash
go run main.go compute create --name my_instance --cpu 2 --ram 1024 --storage 20 --image python:3.10-alpine
```
## 🔧 Commands Overview

### `compute list`
- **Description**: List all compute instances (Docker containers).
- **Example**:
```bash
go run main.go compute list
```
### 🌟 Root Command
- The base command for the CLI, defined in `cmd/root.go`.
- Provides help and global options for the CLI.

### `compute start [ID]`
- **Description**: Start a stopped compute instance (Docker container).
- **Example**:
```bash
go run main.go compute start my_instance_id
```
---

### 🖥️ `compute` Command
- **Purpose**: Manages compute resources using Docker containers.
- **Operations**:
- **create**: Create a new Docker container and register it as a compute instance.
- **list**: List all compute instances.
- **start**: Start a stopped compute instance.
- **enter**: Enter a running instance interactively.
- **stop**: Stop a running instance.
- **delete**: Delete a compute instance.

Example:
```bash
go run main.go compute create --name my_instance --cpu 2 --ram 1024 --storage 20 --image python:3.10-alpine
```

### `compute enter [ID]`
- **Description**: Enter a compute instance (Docker container) interactively.
- **Example**:
---

### ☁️ `s3` Command
- **Purpose**: Manages S3-compatible storage (e.g., MinIO).
- **Operations**:

#### `s3 bucket`
- **create**: Create a new S3 bucket.
- **list**: List all buckets.
- **delete**: Delete a bucket.

Example:
```bash
go run main.go s3 bucket create --name my_bucket
```

#### `s3 object`
- **upload**: Upload a file to a bucket.
- **list**: List objects in a bucket.
- **download**: Download a file from a bucket.
- **delete**: Delete a file from a bucket.

Example:
```bash
go run main.go s3 object upload --bucket my_bucket --file file.txt
```

---

## ⚙️ Configuration

Configurations are stored in `~/.homecloud_config.json`.

Example keys:
```json
{
"api_endpoint": "http://localhost:8080",
"s3_endpoint": "http://localhost:9000",
"s3_access_key": "your_access_key",
"s3_secret_key": "your_secret_key"
}
```

---

## 🚀 Getting Started

1. **Navigate to the CLI folder**
```bash
go run main.go compute enter my_instance_id
cd cli
```

### `compute stop [ID]`
- **Description**: Stop a running compute instance (Docker container).
- **Example**:
2. **Run the CLI**
```bash
go run main.go compute stop my_instance_id
go run main.go
```

### `compute delete [ID]`
- **Description**: Delete a compute instance (Docker container) and remove its registration.
- **Example**:
3. **Explore commands**
```bash
go run main.go compute delete my_instance_id
go run main.go --help
```

## Instance Storage
- The state of instances is saved in a local JSON file named `compute.json`.
- This file tracks the following details for each instance:
- `ID`: Unique container ID
- `Name`: The name of the container/instance
- `CPU`: The allocated number of CPU cores
- `RAM`: The allocated amount of RAM
- `Storage`: The allocated storage space
- `BaseImage`: The base Docker image used for the container
- `Status`: The current status of the instance (running, stopped)

---
26 changes: 14 additions & 12 deletions cli/cmd/root.go
Original file line number Diff line number Diff line change
@@ -1,31 +1,33 @@
package cmd

import (
"fmt"
"fmt"

"github.com/spf13/cobra"
"github.com/homecloudhq/homecloud/cli/cmd/compute"
"github.com/homecloudhq/homecloud/cli/cmd/s3"
"github.com/spf13/cobra"
)

// RootCmd is the base command for the CLI, exported for use in other modules.
var RootCmd = &cobra.Command{
Use: "homecloud",
Short: "HomeCloud CLI for managing self-hosted cloud services",
Long: `HomeCloud CLI provides tools to deploy, manage, and monitor
Use: "homecloud",
Short: "HomeCloud CLI for managing self-hosted cloud services",
Long: `HomeCloud CLI provides tools to deploy, manage, and monitor
self-hosted cloud infrastructure.`,
Run: func(cmd *cobra.Command, args []string) {
fmt.Println("Welcome to HomeCloud CLI!")
},
Run: func(cmd *cobra.Command, args []string) {
fmt.Println("Welcome to HomeCloud CLI!")
},
}

// Execute runs the root command, entry point for the CLI.
func Execute() {
if err := RootCmd.Execute(); err != nil {
fmt.Println(err)
}
if err := RootCmd.Execute(); err != nil {
fmt.Println(err)
}
}

// Register all individual comments here.
func init() {
RootCmd.AddCommand(compute.ComputeCmd)
}
RootCmd.AddCommand(s3.S3Cmd)
}
Loading