Skip to content
Open
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
19 changes: 16 additions & 3 deletions claude-code/shared/skills/devops/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,12 @@ If you encounter this error, advise the user to run the above command. Other per

**Cluster management:**

The `dev-k8s.sh` orchestration script lives in **smartem-devtools** (it used to live in smartem-decisions). It needs a sibling checkout of `smartem-decisions` to build the backend image from `Dockerfile.dev`; override `SMARTEM_DECISIONS_PATH` if your layout differs.

```bash
cd repos/DiamondLightSource/smartem-decisions
cd repos/DiamondLightSource/smartem-devtools

# Start local k3s cluster with all services
# Start local k3s cluster with all services (backend, postgres, rabbitmq, mongo, es, keycloak mock, FE)
./scripts/k8s/dev-k8s.sh up

# Stop and cleanup
Expand All @@ -53,6 +55,12 @@ kubectl get pods -n smartem-decisions
kubectl get services -n smartem-decisions
```

**Keycloak in the dev stack:**

The in-cluster Keycloak mock (`keycloak-mock/keycloak.yaml`, pulled in via the development kustomization) is the primary local auth provider. It is brought up automatically by `dev-k8s.sh up` and reachable at `http://localhost:30090`.

The `keycloak-mock/docker-compose.yml` in the same directory is a **fallback for FE-only development** — use it when working inside `smartem-frontend` in isolation without the rest of the k3s stack. Do not run both at once or the NodePort/host-port mapping will collide.

### Services (smartem-decisions namespace)

| Service | Port | NodePort | Purpose |
Expand All @@ -77,7 +85,10 @@ k8s/
```bash
cd repos/DiamondLightSource/smartem-decisions

# Build backend image
# Build local dev backend image (matches what dev-k8s.sh expects)
docker build -f Dockerfile.dev -t smartem-decisions:latest .

# Build production image
docker build -t smartem-backend:dev .

# Build with specific Python version (from Dockerfile)
Expand All @@ -87,6 +98,8 @@ docker build --build-arg PYTHON_VERSION=3.12 -t smartem-backend:dev .
docker build --target production -t smartem-backend:prod .
```

`dev-k8s.sh up` will build `smartem-decisions:latest` automatically if it is missing, loading it into k3s containerd. Pre-build it manually only if you want to iterate without re-running `up`.

### Push to Registry

```bash
Expand Down
9 changes: 9 additions & 0 deletions docs/operations/kubernetes.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,15 @@ Once the environment is running, you can access:

> **Note**: The script automatically handles GitHub Container Registry authentication and waits for all pods to be ready.

### Pointing the SmartEM frontend dev server at this stack

The Vite dev server in `smartem-frontend` proxies `/api` to `http://localhost:8000` by default — the conventional port for a standalone backend (`uvicorn` directly, or a `kubectl port-forward`). When the backend is in the dev k3s stack, two options:

- **No port-forward** (simplest) — set `VITE_API_PROXY_TARGET=http://localhost:30080` in `apps/smartem/.env.local`. Vite proxies straight to the NodePort.
- **Port-forward to 8000** — `kubectl port-forward -n smartem-decisions svc/smartem-http-api-service 8000:80` keeps the default proxy target working. Useful if you also want CLI tools that hit `http://localhost:8000` to keep working unchanged.

Keycloak is reachable on `http://localhost:30090` regardless; see [Local Keycloak](../development/local-keycloak.md) for the SPA's runtime auth config.

## Kubernetes Structure

```
Expand Down
14 changes: 12 additions & 2 deletions scripts/k8s/dev-k8s.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ NAMESPACE="smartem-decisions"
K8S_ENV_PATH="k8s/environments/development"
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PROJECT_ROOT="$(cd "$SCRIPT_DIR/../.." && pwd)"
# smartem-decisions repo holds Dockerfile.dev for the local backend image build.
# Override SMARTEM_DECISIONS_PATH if your checkout layout is not the conventional sibling.
SMARTEM_DECISIONS_PATH="${SMARTEM_DECISIONS_PATH:-$PROJECT_ROOT/../smartem-decisions}"
DEPLOY_ENV="${DEPLOY_ENV:-development}"

# Colors for output
Expand Down Expand Up @@ -380,9 +383,16 @@ ensure_local_image() {

# Check if image exists in Docker
if ! docker image inspect "$image_name" &> /dev/null; then
log_info "Building SmartEM image..."
cd "$PROJECT_ROOT"
if [[ ! -f "$SMARTEM_DECISIONS_PATH/Dockerfile.dev" ]]; then
log_error "Dockerfile.dev not found at: $SMARTEM_DECISIONS_PATH/Dockerfile.dev"
log_error "Set SMARTEM_DECISIONS_PATH to the smartem-decisions repo checkout, or"
log_error "clone it as a sibling of smartem-devtools."
exit 1
fi
log_info "Building SmartEM image from $SMARTEM_DECISIONS_PATH..."
cd "$SMARTEM_DECISIONS_PATH"
docker build -f Dockerfile.dev -t "$image_name" .
cd "$PROJECT_ROOT"
else
log_info "SmartEM image already exists in Docker"
fi
Expand Down
1 change: 1 addition & 0 deletions webui/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ export default defineConfig({
{
theme: 'github-dark',
keepBackground: true,
defaultLang: 'text',
},
],
],
Expand Down
Loading