Skip to content

Commit c247989

Browse files
barckcodeclaude
andcommitted
Initial commit: CodeRun CLI application
- Complete Go CLI application built with Cobra framework - Container-as-a-Service interface for Kubernetes deployments - Commands: login, deploy, list, status, delete, logs - HTTP API client with authentication support - Configuration management with secure token storage - Environment variable parsing and resource validation - Comprehensive .gitignore to exclude sensitive files - Translated all Spanish comments to English - Safe example.env without actual API key patterns 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 587241e commit c247989

File tree

21 files changed

+1584
-0
lines changed

21 files changed

+1584
-0
lines changed

.gitignore

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# Binaries
2+
coderun
3+
*.exe
4+
*.exe~
5+
*.dll
6+
*.so
7+
*.dylib
8+
9+
# Test binary, built with `go test -c`
10+
*.test
11+
12+
# Output of the go coverage tool
13+
*.out
14+
15+
# Go workspace file
16+
go.work
17+
go.work.sum
18+
19+
# IDE files
20+
.vscode/
21+
.idea/
22+
*.swp
23+
*.swo
24+
*~
25+
26+
# OS generated files
27+
.DS_Store
28+
.DS_Store?
29+
._*
30+
.Spotlight-V100
31+
.Trashes
32+
ehthumbs.db
33+
Thumbs.db
34+
35+
# Configuration files with credentials
36+
config.json
37+
.env
38+
*.env
39+
!example.env
40+
41+
# User config directory
42+
.coderun/
43+
44+
# Logs
45+
*.log

CLAUDE.md

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# CLAUDE.md
2+
3+
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
4+
5+
## Development Commands
6+
7+
### Build
8+
```bash
9+
go build -o coderun .
10+
```
11+
12+
### Run Tests
13+
```bash
14+
go test ./...
15+
```
16+
17+
### Install Binary (Optional)
18+
```bash
19+
sudo mv coderun /usr/local/bin/
20+
```
21+
22+
## Project Architecture
23+
24+
This is a Go CLI application built with Cobra that provides a Container-as-a-Service interface for deploying Docker containers to Kubernetes. The application consists of:
25+
26+
### Core Structure
27+
- **`main.go`**: Entry point that calls `cmd.Execute()`
28+
- **`cmd/`**: Contains all CLI commands using Cobra framework
29+
- `root.go`: Base command definition and configuration
30+
- `login.go`, `deploy.go`, `list.go`, `status.go`, `delete.go`, `logs.go`: Individual command implementations
31+
- **`internal/client/`**: HTTP API client implementation
32+
- `client.go`: Core HTTP client with authentication
33+
- `auth.go`, `deployments.go`: API endpoint implementations
34+
- `types.go`: Request/response type definitions
35+
- **`internal/utils/`**: Utility functions
36+
- `config.go`: Configuration file management (~/.coderun/config.json)
37+
- `env.go`: Environment file parsing and resource validation
38+
39+
### Key Design Patterns
40+
- Uses Cobra for CLI structure with subcommands
41+
- HTTP client with bearer token authentication
42+
- Configuration stored in `~/.coderun/config.json` with access tokens
43+
- Environment variables loaded from files using `KEY=VALUE` format
44+
- Resource validation for CPU (e.g., `100m`, `0.5`) and memory (e.g., `128Mi`, `1Gi`)
45+
- Long timeout (10 minutes) for deployment operations
46+
47+
### API Integration
48+
- Communicates with CodeRun API (default: `http://localhost:8000`)
49+
- Supports custom API URL via `--api-url` flag or `CODERUN_API_URL` environment variable
50+
- Handles deployment creation, listing, status checking, and deletion
51+
- Supports container resource limits, replicas, HTTP port exposure, and environment variables
52+
53+
### Commands Available
54+
- `coderun login`: Authenticate and store access token
55+
- `coderun deploy IMAGE`: Deploy containers with optional flags for replicas, resources, ports, env files
56+
- `coderun list`: List all deployments in table format
57+
- `coderun status APP_NAME`: Get detailed deployment status
58+
- `coderun delete DEPLOYMENT_ID`: Remove deployments
59+
- `coderun logs DEPLOYMENT_ID`: View container logs
60+
61+
The CLI is designed to be the primary interface for the CodeRun platform, abstracting Kubernetes complexity while providing essential container deployment and management capabilities.

README.md

Lines changed: 274 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,274 @@
1+
# CodeRun CLI
2+
3+
CodeRun CLI is a command-line tool for deploying and managing Docker containers on the CodeRun platform.
4+
5+
## Installation
6+
7+
### Build from source code
8+
9+
```bash
10+
git clone <repository-url>
11+
cd cli
12+
go build -o coderun .
13+
```
14+
15+
### Move binary to your PATH (optional)
16+
17+
```bash
18+
sudo mv coderun /usr/local/bin/
19+
```
20+
21+
## Configuration
22+
23+
### 1. Login
24+
25+
First you need to authenticate with your CodeRun account:
26+
27+
```bash
28+
coderun login
29+
```
30+
31+
You will be prompted for your email and password. The access token will be saved in `~/.coderun/config.json`.
32+
33+
### 2. Configure API URL (optional)
34+
35+
By default, the CLI uses `https://api.coderun.dev`. To use a local instance:
36+
37+
```bash
38+
coderun --api-url http://localhost:8000 login
39+
```
40+
41+
Or you can configure the environment variable:
42+
43+
```bash
44+
export CODERUN_API_URL="http://localhost:8000"
45+
```
46+
47+
## Available Commands
48+
49+
### `coderun login`
50+
51+
Authenticate with the CodeRun platform.
52+
53+
```bash
54+
coderun login
55+
```
56+
57+
### `coderun deploy`
58+
59+
Deploy a Docker container.
60+
61+
#### Basic options:
62+
63+
```bash
64+
# Simple deployment
65+
coderun deploy nginx:latest
66+
67+
# With specific replicas
68+
coderun deploy nginx:latest --replicas=3
69+
70+
# With resource limits
71+
coderun deploy myapp:v1.0 --cpu=500m --memory=1Gi
72+
73+
# With exposed HTTP port
74+
coderun deploy myapp:v1.0 --http-port=8080
75+
```
76+
77+
#### Using environment files:
78+
79+
```bash
80+
# Load environment variables from file
81+
coderun deploy myapp:v1.0 --env-file=production.env
82+
83+
# Complete example
84+
coderun deploy myapp:v1.0 \
85+
--replicas=2 \
86+
--cpu=200m \
87+
--memory=512Mi \
88+
--http-port=3000 \
89+
--env-file=.env \
90+
--name=my-production-app
91+
```
92+
93+
#### Parameters:
94+
95+
- `--replicas`: Number of replicas (default: 1)
96+
- `--cpu`: CPU limit (example: `100m`, `0.5`, `1`)
97+
- `--memory`: Memory limit (example: `128Mi`, `1Gi`, `512Ki`)
98+
- `--http-port`: HTTP port to expose
99+
- `--env-file`: Path to environment variables file
100+
- `--name`: Application name (optional, auto-generated)
101+
102+
### `coderun list`
103+
104+
List all deployments.
105+
106+
```bash
107+
coderun list
108+
```
109+
110+
Example output:
111+
```
112+
Found 3 deployment(s):
113+
114+
ID App Name Image Replicas Status Created
115+
---------- -------------------- ------------------------------ -------- ---------- ----------------
116+
abc12345.. my-nginx nginx:latest 2 Running 2024-01-15 14:30
117+
def67890.. my-api mycompany/api:v2.1 1 Running 2024-01-15 13:45
118+
ghi24680.. my-worker mycompany/worker:latest 3 Pending 2024-01-15 14:25
119+
```
120+
121+
### `coderun status`
122+
123+
Get detailed status of a deployment by application name.
124+
125+
```bash
126+
coderun status my-nginx
127+
```
128+
129+
### `coderun delete`
130+
131+
Delete a deployment by ID.
132+
133+
```bash
134+
# Delete by specific ID
135+
coderun delete abc12345def67890
136+
137+
# Using command combination
138+
coderun delete $(coderun list | grep my-old-app | awk '{print $1}')
139+
```
140+
141+
## Environment file format
142+
143+
The environment file must follow the `KEY=VALUE` format:
144+
145+
```bash
146+
# example.env
147+
DATABASE_URL=postgresql://user:pass@localhost:5432/db
148+
API_KEY="secret-key-with-special-chars"
149+
DEBUG=true
150+
PORT=8080
151+
```
152+
153+
### Rules:
154+
155+
- One variable per line
156+
- Format: `KEY=VALUE`
157+
- Comments start with `#`
158+
- Empty lines are ignored
159+
- Values can be quoted (`"` or `'`)
160+
- No spaces around the `=`
161+
162+
## Usage examples
163+
164+
### Deploy a simple web application
165+
166+
```bash
167+
# 1. Login
168+
coderun login
169+
170+
# 2. Deploy nginx
171+
coderun deploy nginx:latest --replicas=2 --http-port=80
172+
173+
# 3. Check status
174+
coderun list
175+
coderun status nginx
176+
```
177+
178+
### Deploy an application with database
179+
180+
```bash
181+
# 1. Create environment file
182+
cat > production.env << EOF
183+
DATABASE_URL=postgresql://user:pass@db:5432/myapp
184+
REDIS_URL=redis://redis:6379
185+
API_KEY=your-secret-key
186+
APP_ENV=production
187+
EOF
188+
189+
# 2. Deploy the application
190+
coderun deploy mycompany/webapp:v2.0 \
191+
--replicas=3 \
192+
--cpu=500m \
193+
--memory=1Gi \
194+
--http-port=8080 \
195+
--env-file=production.env \
196+
--name=webapp-prod
197+
198+
# 3. Verify deployment
199+
coderun status webapp-prod
200+
```
201+
202+
### Deployment management
203+
204+
```bash
205+
# List all deployments
206+
coderun list
207+
208+
# View details of specific deployment
209+
coderun status my-app
210+
211+
# Delete old deployment
212+
coderun delete abc12345def67890
213+
```
214+
215+
## Troubleshooting
216+
217+
### Authentication error
218+
219+
```bash
220+
Error: Authentication failed
221+
```
222+
223+
**Solution**: Run `coderun login` to authenticate again.
224+
225+
### Connection error
226+
227+
```bash
228+
Error: Failed to connect to API
229+
```
230+
231+
**Solution**: Verify API URL with `--api-url` or the `CODERUN_API_URL` environment variable.
232+
233+
### Resource format error
234+
235+
```bash
236+
Error: Invalid CPU format '1core' (examples: 100m, 0.5, 1)
237+
```
238+
239+
**Solution**: Use valid formats:
240+
- CPU: `100m`, `0.5`, `1`, `2`
241+
- Memory: `128Mi`, `1Gi`, `512Ki`
242+
243+
### Environment file error
244+
245+
```bash
246+
Error: Invalid format at line 5: INVALID LINE (expected KEY=VALUE)
247+
```
248+
249+
**Solution**: Verify each line follows the `KEY=VALUE` format.
250+
251+
## Configuration files
252+
253+
- **Config**: `~/.coderun/config.json`
254+
- **Token**: Stored in configuration file
255+
256+
## Development
257+
258+
### Build
259+
260+
```bash
261+
go build -o coderun .
262+
```
263+
264+
### Run tests
265+
266+
```bash
267+
go test ./...
268+
```
269+
270+
### Add new commands
271+
272+
1. Create file in `cmd/`
273+
2. Implement command with Cobra
274+
3. Register in `cmd/root.go`

0 commit comments

Comments
 (0)