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
236 changes: 147 additions & 89 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,176 +1,234 @@
# codewise-cli
# Codewise CLI

<div align="center">
<img src="/logo/logo_pic.png" alt="Codewise Logo" width="220"/>
<img src="logo/logo_pic.png" alt="Codewise Logo" width="220"/>
</div>

Codewise is a powerful CLI tool that simplifies common DevOps tasks such as:
<br/>

* Encoding/decoding files
* JSON/YAML conversions
* Dockerfile generation
* Kubernetes manifest scaffolding
* Rendering templates with Go's `text/template` engine

-----
Codewise is a DevOps-oriented command-line utility for scaffolding, packaging, and deploying containerized applications using a consistent workflow. It enables developers and platform engineers to move from source code to running workloads using Docker, Kubernetes, and Helm without switching tools or remembering boilerplate syntax.

## Getting Started:
---

### Clone the Repository
## Features

Codewise provides automation for:

- Dockerfile scaffolding and image builds
- Kubernetes manifest generation and deployment
- Helm chart scaffolding
- Namespace, context, and dry-run support for Kubernetes operations
- Configuration bootstrapping for defaults (image, namespace, repo)
- File encoding utilities (Base64, YAML ⇄ JSON, ENV parsing)
- Templating & project bootstrap helpers

---

## Installation

Clone the repository:

```bash
git clone https://github.com/aryansharma9917/codewise-cli.git
cd codewise-cli
```
````

### Build the Binary
Build from source:

```bash
go build -o codewise main.go
```

### (Optional) Install Globally
(Optional) install globally:

```bash
sudo mv codewise /usr/local/bin/
```

-----
---

## Usage

General syntax:

```bash
codewise <command> [subcommand] [flags]
```

---

## Configuration

Initialize a personal configuration:

```bash
codewise <command> [flags]
codewise config init
```

This creates:

```
~/.codewise/config.yaml
```

-----
example:

## Commands & Examples
```yaml
defaults:
app_name: myapp
image: codewise:latest
namespace: default
context: ""
```

### `encode` — Format Conversion & Encoding
Configuration values can be overridden with CLI flags.

| Conversion Type | Description | Example |
| :-------------- | :-------------------- | :-------------------------------------------------------------------------- |
| `JTY` | JSON to YAML | `codewise encode --input input.json --output output.yaml --type JTY` |
| `YTJ` | YAML to JSON | `codewise encode --input input.yaml --output output.json --type YTJ` |
| `KVTJ` | .env to JSON | `codewise encode --input .env --output env.json --type KVTJ` |
| `B64E` | Base64 Encode | `codewise encode --input input.txt --output encoded.txt --type B64E` |
| `B64D` | Base64 Decode | `codewise encode --input encoded.txt --output decoded.txt --type B64D` |
---

### `generate` — Starter File Generators
## Docker Workflow

Generate a Dockerfile:
Initialize a Dockerfile:

```bash
codewise generate dockerfile --output Dockerfile
codewise docker init
```

Generate a Kubernetes manifest:
Validate Dockerfile structure:

```bash
codewise generate k8s --output deployment.yaml
codewise docker validate
```

### `template` — Render Templated YAMLs

Use Go `.tpl` template and `.yaml` values file to generate output YAML:
Build container image:

```bash
codewise template --template template.tpl --values values.yaml --output rendered.yaml
codewise docker build
```

-----
---

## Kubernetes Workflow

## 🐳 Docker Usage
Initialize manifests:

### 🔨 Build Docker Image
```bash
codewise k8s init
```

Apply manifests to a cluster:

```bash
docker build -t aryansharma04/codewise-cli:latest .
codewise k8s apply --namespace dev --context minikube
```

### Run Using Docker
Dry-run mode (no cluster required):

```bash
docker run --rm -v $(pwd):/app aryansharma04/codewise-cli:latest <command>
codewise k8s apply --dry-run
```

Example:
Delete deployment:

```bash
docker run --rm -v $(pwd):/app aryansharma04/codewise-cli:latest encode --input /app/input.json --output /app/output.yaml --type JTY
codewise k8s delete --namespace dev
```

-----
---

## ✅ Running Tests
## Helm Workflow

Make sure Go is installed:
Scaffold a Helm chart:

```bash
go test ./... -v
codewise helm init
```

Test coverage includes:
This creates:

```
helm/chart/
├── Chart.yaml
├── values.yaml
└── templates/
├── deployment.yaml
└── service.yaml
```

* ✅ JSON to YAML
* ✅ YAML to JSON
* ✅ ENV to JSON
* ✅ Base64 encode/decode
* ✅ Template rendering
---

-----
## Encoding & Conversion Utilities

## 📁 Project Structure
Usage:

```bash
.
├── cmd/ # CLI command handlers
├── pkg/
│ ├── encoder/ # Encoding & conversion logic
│ ├── generator/ # Project scaffolding logic
│ └── validator/ # Future: Schema & config validation
├── templates/ # Go template files
├── tests/ # Unit tests
├── testdata/ # Sample input files for testing
├── Dockerfile
├── Makefile
├── go.mod
├── main.go
└── README.md
codewise encode --input file --output out --type <mode>
```

-----
Supported modes:

| mode | description |
| ------ | ------------- |
| `JTY` | JSON → YAML |
| `YTJ` | YAML → JSON |
| `KVTJ` | .env → JSON |
| `B64E` | Base64 encode |
| `B64D` | Base64 decode |

## 🤝 Contributing
---

## Example End-to-End Workflow

```bash
# Fork and clone the repo
git clone https://github.com/<your-username>/codewise-cli.git
cd codewise-cli
codewise config init
codewise docker init
codewise docker build
codewise k8s init
codewise k8s apply --namespace dev --context minikube
codewise helm init
```

# Create a feature branch
git checkout -b my-feature
---

# Make changes and push
git add .
git commit -m "Add awesome feature"
git push origin my-feature
## Project Structure

```
.
├── cmd/ # CLI commands
├── pkg/ # Core logic (docker, k8s, helm, config, encode)
├── helm/ # Generated Helm charts
├── k8s/ # Generated Kubernetes manifests
├── config/ # Configuration helpers
├── Dockerfile
├── go.mod
└── main.go
```

Then open a Pull Request 🚀
---

## Roadmap

Planned enhancements include:

-----
* Helm install/upgrade operations
* Helm push to OCI registries
* GitOps integration (ArgoCD / Flux)
* CI/CD pipeline generation (GitHub Actions)
* Image scanning (Trivy/Syft plugins)
* Terraform infrastructure modules
* Local cluster provisioning (kind/k3d/minikube)
* Plugin system for custom extensions
* Global binary installation via Homebrew/Scoop

## 🛡 License
---

Licensed under the MIT License. See `LICENSE` for more.
## Contributing

-----
Contributions are welcome. The project follows a logical commit layering:

## 📚 Blog Post
* Logic changes under `pkg/`
* CLI wiring under `cmd/`
* Scaffold output under `k8s/` and `helm/`

Check out the behind-the-scenes story and development journey in Aryan's detailed blog post:
Fork, branch, commit, and open a PR.

> **📖 [I Built a DevOps CLI Tool in Go – Meet codewise-cli](https://dev.to/aryansharma9917/i-built-a-devops-cli-tool-in-go-meet-codewise-cli-5149)**
> Dive into how this tool was built from scratch, its motivations, challenges, features, and future roadmap.
12 changes: 12 additions & 0 deletions cmd/helm.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package cmd

import "github.com/spf13/cobra"

var helmCmd = &cobra.Command{
Use: "helm",
Short: "Helm chart tooling",
}

func init() {
rootCmd.AddCommand(helmCmd)
}
49 changes: 49 additions & 0 deletions cmd/helm_init.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package cmd

import (
"fmt"

"github.com/aryansharma9917/codewise-cli/pkg/config"
"github.com/aryansharma9917/codewise-cli/pkg/helm"
"github.com/spf13/cobra"
)

var (
helmAppName string
helmImage string
)

var helmInitCmd = &cobra.Command{
Use: "init",
Short: "Initialize a Helm chart from Codewise configuration",
Run: func(cmd *cobra.Command, args []string) {
cfg, err := config.ReadConfig()
if err != nil {
fmt.Println("info: config not found, run `codewise config init` first")
return
}

app := helmAppName
if app == "" {
app = cfg.Defaults.AppName
}

image := helmImage
if image == "" {
image = cfg.Defaults.Image
}

if err := helm.InitChart(app, image); err != nil {
fmt.Println("info:", err.Error())
return
}

fmt.Printf("helm chart created at helm/chart\n")
},
}

func init() {
helmInitCmd.Flags().StringVar(&helmAppName, "app", "", "Application name for chart")
helmInitCmd.Flags().StringVar(&helmImage, "image", "", "Container image for chart")
helmCmd.AddCommand(helmInitCmd)
}
Loading