|
| 1 | +# Kosli CLI DevContainer |
| 2 | + |
| 3 | +This devcontainer provides a complete development environment for the Kosli CLI project. |
| 4 | + |
| 5 | +## What's Included |
| 6 | + |
| 7 | +### Languages & Runtimes |
| 8 | + |
| 9 | +- **Go 1.25** - Primary development language |
| 10 | +- **Node.js LTS** - For npm package management and release |
| 11 | + |
| 12 | +### Development Tools |
| 13 | + |
| 14 | +- **golangci-lint** - Go linting and static analysis |
| 15 | +- **goreleaser** - Release automation |
| 16 | +- **gotestsum** - Enhanced Go test runner |
| 17 | +- **Hugo Extended** - Documentation site generation |
| 18 | +- **GitHub CLI (gh)** - GitHub integration |
| 19 | + |
| 20 | +### Infrastructure |
| 21 | + |
| 22 | +- **Docker-in-Docker** - For integration tests (runs Kosli server) |
| 23 | +- **Make** - Build automation |
| 24 | +- **Git** - Version control |
| 25 | + |
| 26 | +## Getting Started |
| 27 | + |
| 28 | +1. **Open in VS Code** |
| 29 | + - Install the "Dev Containers" extension |
| 30 | + - Open this repository in VS Code |
| 31 | + - Click "Reopen in Container" when prompted (or use Command Palette: "Dev Containers: Reopen in Container") |
| 32 | + |
| 33 | +2. **Wait for Setup** |
| 34 | + - The container will build (first time takes a few minutes) |
| 35 | + - Post-create commands will run automatically (`go mod download`, etc.) |
| 36 | + |
| 37 | +3. **Start Developing** |
| 38 | + |
| 39 | + ```bash |
| 40 | + # Build the CLI |
| 41 | + make build |
| 42 | + |
| 43 | + # Run tests |
| 44 | + make test_integration |
| 45 | + |
| 46 | + # Run linting |
| 47 | + make lint |
| 48 | + |
| 49 | + # Build documentation |
| 50 | + make hugo-local |
| 51 | + ``` |
| 52 | + |
| 53 | +## Container Features |
| 54 | + |
| 55 | +### Forwarded Ports |
| 56 | + |
| 57 | +- **1515** - Hugo documentation server |
| 58 | +- **8001** - Local Kosli server (for integration tests) |
| 59 | + |
| 60 | +### Volume Mounts |
| 61 | + |
| 62 | +- Go module cache is persisted in a Docker volume for faster builds |
| 63 | +- Docker socket is mounted for Docker-in-Docker functionality |
| 64 | + |
| 65 | +### VS Code Extensions |
| 66 | + |
| 67 | +The following extensions are automatically installed: |
| 68 | + |
| 69 | +- **Go** - Go language support |
| 70 | +- **Docker** - Docker file and container management |
| 71 | +- **GitLens** - Enhanced Git capabilities |
| 72 | + |
| 73 | +### VS Code Settings |
| 74 | + |
| 75 | +Pre-configured with: |
| 76 | + |
| 77 | +- Go formatting on save |
| 78 | +- Automatic import organization |
| 79 | +- golangci-lint integration |
| 80 | +- Go language server (gopls) |
| 81 | + |
| 82 | +## Common Tasks |
| 83 | + |
| 84 | +### Building the CLI |
| 85 | + |
| 86 | +```bash |
| 87 | +make build |
| 88 | +./kosli version |
| 89 | +``` |
| 90 | + |
| 91 | +### Running Tests |
| 92 | + |
| 93 | +```bash |
| 94 | +# Integration tests (requires Docker) |
| 95 | +make test_integration |
| 96 | + |
| 97 | +# Run all tests including slow ones |
| 98 | +make test_integration_full |
| 99 | + |
| 100 | +# Run specific test suite |
| 101 | +make test_integration_single TARGET=TestAttestJunitCommandTestSuite |
| 102 | +``` |
| 103 | + |
| 104 | +### Working with NPM Package |
| 105 | + |
| 106 | +```bash |
| 107 | +# Test npm package installation locally |
| 108 | +npm install |
| 109 | +npm test |
| 110 | + |
| 111 | +# Pack for distribution |
| 112 | +npm pack |
| 113 | + |
| 114 | +# Test the packed version |
| 115 | +mkdir /tmp/npm-test && cd /tmp/npm-test |
| 116 | +npm install /workspace/*.tgz |
| 117 | +npx kosli version |
| 118 | +``` |
| 119 | + |
| 120 | +### Documentation |
| 121 | + |
| 122 | +```bash |
| 123 | +# Generate CLI documentation |
| 124 | +make cli-docs |
| 125 | + |
| 126 | +# Start Hugo documentation server (accessible at localhost:1515) |
| 127 | +make hugo-local |
| 128 | +``` |
| 129 | + |
| 130 | +### Linting |
| 131 | + |
| 132 | +```bash |
| 133 | +make lint |
| 134 | +``` |
| 135 | + |
| 136 | +## Environment Variables |
| 137 | + |
| 138 | +The following environment variables are pre-configured: |
| 139 | + |
| 140 | +- `CGO_ENABLED=0` - Disable CGO for static binaries |
| 141 | +- `GO111MODULE=on` - Use Go modules |
| 142 | +- `GOPATH=/go` - Go workspace location |
| 143 | + |
| 144 | +### Required for Testing |
| 145 | + |
| 146 | +You need to set `KOSLI_API_TOKEN_PROD` for integration tests: |
| 147 | + |
| 148 | +```bash |
| 149 | +export KOSLI_API_TOKEN_PROD="your-token-here" |
| 150 | +``` |
| 151 | + |
| 152 | +## Docker Integration |
| 153 | + |
| 154 | +The devcontainer uses Docker-in-Docker to run integration tests. The Kosli server runs in a container alongside your tests. |
| 155 | + |
| 156 | +### Managing Test Containers |
| 157 | + |
| 158 | +```bash |
| 159 | +# View server logs |
| 160 | +make logs_integration_test_server |
| 161 | + |
| 162 | +# Follow server logs |
| 163 | +make follow_integration_test_server |
| 164 | + |
| 165 | +# Enter server container |
| 166 | +make enter_integration_test_server |
| 167 | +``` |
| 168 | + |
| 169 | +## Troubleshooting |
| 170 | + |
| 171 | +### Container won't start |
| 172 | + |
| 173 | +- Ensure Docker Desktop is running |
| 174 | +- Check Docker has enough resources (4GB+ RAM recommended) |
| 175 | +- Try rebuilding: Command Palette → "Dev Containers: Rebuild Container" |
| 176 | + |
| 177 | +### Tests failing |
| 178 | + |
| 179 | +- Ensure `KOSLI_API_TOKEN_PROD` is set |
| 180 | +- Check Docker is working: `docker ps` |
| 181 | +- Verify network: `docker network ls` (should see `cli_net`) |
| 182 | + |
| 183 | +### Go modules issues |
| 184 | + |
| 185 | +```bash |
| 186 | +go clean -modcache |
| 187 | +go mod download |
| 188 | +go mod tidy |
| 189 | +``` |
| 190 | + |
| 191 | +### NPM installation issues |
| 192 | + |
| 193 | +```bash |
| 194 | +rm -rf node_modules package-lock.json |
| 195 | +npm install |
| 196 | +``` |
| 197 | + |
| 198 | +## Customization |
| 199 | + |
| 200 | +### Adding VS Code Extensions |
| 201 | + |
| 202 | +Edit [.devcontainer/devcontainer.json](.devcontainer/devcontainer.json): |
| 203 | + |
| 204 | +```json |
| 205 | +"extensions": [ |
| 206 | + "golang.go", |
| 207 | + "your-extension-id" |
| 208 | +] |
| 209 | +``` |
| 210 | + |
| 211 | +### Installing Additional Tools |
| 212 | + |
| 213 | +Edit [.devcontainer/Dockerfile](.devcontainer/Dockerfile) and rebuild the container. |
| 214 | + |
| 215 | +### Changing Environment Variables |
| 216 | + |
| 217 | +Edit the `remoteEnv` section in [.devcontainer/devcontainer.json](.devcontainer/devcontainer.json). |
| 218 | + |
| 219 | +## Non-Root User |
| 220 | + |
| 221 | +The container runs as the `vscode` user (non-root) for security. Use `sudo` if you need root access: |
| 222 | + |
| 223 | +```bash |
| 224 | +sudo apt-get install some-package |
| 225 | +``` |
| 226 | + |
| 227 | +## References |
| 228 | + |
| 229 | +- [Dev Containers Documentation](https://code.visualstudio.com/docs/devcontainers/containers) |
| 230 | +- [Kosli Documentation](https://docs.kosli.com/) |
| 231 | +- [Project Development Guide](../dev-guide.md) |
0 commit comments