with one click
containdb
Development rules and patterns for ContainDB CLI tool
Install with Codex or Claude Copy this prompt, paste it into Codex, Claude, or another assistant, and let it review the skill page and install it for you.
Menu
Development rules and patterns for ContainDB CLI tool
Install with Codex or Claude Copy this prompt, paste it into Codex, Claude, or another assistant, and let it review the skill page and install it for you.
Based on SOC occupation classification
| name | containdb |
| description | Development rules and patterns for ContainDB CLI tool |
| version | 1.0.0 |
| tags | ["golang","docker","cli","cross-platform","containers"] |
| author | ContainDB Team |
ContainDB - Database Container Management Made Simple
go build -o containdb src/Core/main.go
go test ./...
go fmt ./...
go vet ./...
A task is NOT complete until ALL are true:
go build passesgo test ./... passesgo vet ./... passesCLI Entry Point (src/Core/main.go)
↓
Base Operations (src/base/)
├── Create.go - Database creation
├── Remove.go - Resource cleanup
├── Export.go - docker-compose export
└── Import.go - docker-compose import
↓
Docker Abstraction (src/Docker/)
├── Container.go - Container operations
├── Volume.go - Volume management
└── Network.go - Network operations
↓
Docker Engine
src/
├── Core/ # main.go - CLI entry point
├── base/ # Business logic
├── Docker/ # Docker SDK wrapper
└── tools/ # Management tools (phpMyAdmin, etc.)
Scripts/
├── BinBuilder.sh # Multi-platform builder
├── PackageBuilder.sh # Debian package builder
└── installer.sh # Linux installer
// ✅ REQUIRED
if err != nil {
return fmt.Errorf("failed to create container '%s': %w", name, err)
}
// ❌ FORBIDDEN
if err != nil {
return err // Too generic!
}
// ✅ GOOD - Clear options struct
type ContainerOptions struct {
Name string
Image string
Port int
RestartPolicy string
Volumes map[string]string
Environment map[string]string
}
func CreateContainer(opts ContainerOptions) error { }
// ❌ BAD - Too many parameters
func CreateContainer(name, image string, port int, restart string, vols map[string]string, env map[string]string) error { }
// ✅ GOOD - Clear package boundaries
package docker
import (
"github.com/docker/docker/client"
)
func CreateContainer(opts ContainerOptions) error { }
// ❌ BAD - Mixed concerns in main
package main
func CreateContainer() error { }
func RemoveContainer() error { }
func ParseConfig() error { }
func CreateDatabase(opts Options) error {
// Track all created resources
created := []string{}
// Cleanup on any error
defer func() {
if err != nil {
log.Println("Error occurred, rolling back...")
for _, resourceID := range created {
if err := cleanup(resourceID); err != nil {
log.Printf("Failed to cleanup %s: %v", resourceID, err)
}
}
}
}()
// Create container
container, err := CreateContainer(opts)
if err != nil {
return fmt.Errorf("container creation failed: %w", err)
}
created = append(created, container.ID)
// Create volume
volume, err := CreateVolume(opts.VolumeName)
if err != nil {
return fmt.Errorf("volume creation failed: %w", err)
}
created = append(created, volume.Name)
return nil
}
// ✅ ALWAYS prompt for passwords
import "github.com/manifoldco/promptui"
prompt := promptui.Prompt{
Label: "Enter database password",
Mask: '*',
}
password, err := prompt.Run()
// ❌ NEVER hardcode or use defaults
password := "password123" // FORBIDDEN
// ✅ REQUIRED - Use official Docker SDK
import (
"github.com/docker/docker/client"
"github.com/docker/docker/api/types/container"
)
cli, err := client.NewClientWithOpts(client.FromEnv, client.WithAPIVersionNegotiation())
if err != nil {
return fmt.Errorf("failed to create Docker client: %w", err)
}
resp, err := cli.ContainerCreate(ctx, &container.Config{
Image: "mysql:8.0",
}, nil, nil, nil, "my-mysql")
// ❌ FORBIDDEN - Don't execute docker commands
cmd := exec.Command("docker", "run", "-d", "--name", "mysql", "mysql:8.0")
// ✅ GOOD - Use filepath package
import "path/filepath"
configPath := filepath.Join(homeDir, ".containdb", "config.yaml")
// ❌ BAD - Hardcoded separators
configPath := homeDir + "/.containdb/config.yaml" // Fails on Windows
// ✅ NEVER log passwords
log.Printf("Creating database with user: %s", username) // OK
log.Printf("Creating database with password: %s", password) // FORBIDDEN
// ✅ Prompt for sensitive data
password := promptSecure("Enter password:")
// ❌ No hardcoded secrets
const DefaultPassword = "admin123" // FORBIDDEN
// ✅ Validate all user inputs
func ValidatePort(port int) error {
if port < 1024 || port > 65535 {
return fmt.Errorf("port must be between 1024 and 65535")
}
return nil
}
func ValidateContainerName(name string) error {
if !regexp.MustCompile(`^[a-zA-Z0-9_-]+$`).MatchString(name) {
return fmt.Errorf("name must contain only alphanumeric, dash, or underscore")
}
return nil
}
// ✅ Warn users about root requirements
if os.Geteuid() != 0 {
log.Println("WARNING: ContainDB requires root/sudo privileges for Docker operations")
log.Println("Please run: sudo containdb")
os.Exit(1)
}
README.md
DESIGN.md
INSTALLATION.md
CHANGELOG.md
Code Comments
// CreateDatabase creates a new containerized database instance.
//
// It performs the following steps:
// 1. Creates a Docker network (if not exists)
// 2. Creates a volume for data persistence
// 3. Starts the database container
// 4. Auto-rollback on any failure
//
// Parameters:
// - opts: Configuration options for the database
//
// Returns:
// - error: nil on success, descriptive error on failure
func CreateDatabase(opts DatabaseOptions) error
func TestCreateContainer(t *testing.T) {
tests := []struct {
name string
opts ContainerOptions
wantErr bool
}{
{"valid MySQL", ContainerOptions{Name: "mysql", Image: "mysql:8.0"}, false},
{"invalid name", ContainerOptions{Name: "my sql", Image: "mysql:8.0"}, true},
{"missing image", ContainerOptions{Name: "mysql"}, true},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
err := CreateContainer(tt.opts)
if (err != nil) != tt.wantErr {
t.Errorf("CreateContainer() error = %v, wantErr %v", err, tt.wantErr)
}
})
}
}
# Build for all platforms
./Scripts/BinBuilder.sh
# Output:
# bin/containdb-linux-amd64
# bin/containdb-darwin-amd64
# bin/containdb-darwin-arm64
# bin/containdb-windows-amd64.exe
# Build .deb package
./Scripts/PackageBuilder.sh
# Output: Packages/containDB_<version>.deb
cd npm/
npm run build
npm publish
❌ Platform-specific code without fallbacks ❌ Hardcoded credentials or secrets ❌ Direct docker command execution (use SDK) ❌ Breaking changes to CLI interface ❌ Missing error handling ❌ Incomplete auto-rollback ❌ Skipping cross-platform testing ❌ Generic error messages ❌ Missing documentation updates ❌ Logging sensitive data
DESIGN.md architecture sectionsrc/base/Create.goEvery task must meet ALL:
go build)go test ./...)go vet ./..., go fmt ./...)