Skip to content

Commit d795a27

Browse files
Anmol1696claude
andcommitted
add setup-dev.sh to install k8s dev dependencies
Auto-detects OS (macOS/Linux) and arch (amd64/arm64), installs kubectl and skaffold from official sources. Supports --check mode to report tool status. Adds make setup-dev and make setup-check targets. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent ac16631 commit d795a27

3 files changed

Lines changed: 201 additions & 0 deletions

File tree

DEVELOPMENT.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,18 @@ Local development setup for running functions against real infrastructure (Postg
88
- pnpm >= 10
99
- Docker Desktop
1010

11+
Check what's installed and what's missing:
12+
13+
```bash
14+
make setup-check
15+
```
16+
17+
Install all missing tools (kubectl, skaffold, pnpm):
18+
19+
```bash
20+
make setup-dev
21+
```
22+
1123
## Quick Start
1224

1325
```bash

Makefile

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,13 @@ dev-down:
3232
dev-logs:
3333
docker compose logs -f
3434

35+
# --- Setup ---
36+
setup-dev:
37+
./scripts/setup-dev.sh
38+
39+
setup-check:
40+
./scripts/setup-dev.sh --check
41+
3542
# --- Skaffold k8s development ---
3643
# Plain k8s (Deployments + Services, no Knative operators needed)
3744
skaffold-dev:

scripts/setup-dev.sh

Lines changed: 182 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,182 @@
1+
#!/usr/bin/env bash
2+
#
3+
# setup-dev.sh — install local k8s development dependencies
4+
#
5+
# Installs: kubectl, skaffold, pnpm (if missing)
6+
# Supports: macOS (amd64/arm64), Linux (amd64/arm64)
7+
#
8+
# Usage:
9+
# ./scripts/setup-dev.sh # install all missing tools
10+
# ./scripts/setup-dev.sh --check # just report what's installed/missing
11+
12+
set -euo pipefail
13+
14+
# --- Detect OS and architecture ---
15+
16+
detect_platform() {
17+
local os arch
18+
19+
case "$(uname -s)" in
20+
Darwin) os="darwin" ;;
21+
Linux) os="linux" ;;
22+
*) echo "Unsupported OS: $(uname -s)" >&2; exit 1 ;;
23+
esac
24+
25+
case "$(uname -m)" in
26+
x86_64|amd64) arch="amd64" ;;
27+
arm64|aarch64) arch="arm64" ;;
28+
*) echo "Unsupported architecture: $(uname -m)" >&2; exit 1 ;;
29+
esac
30+
31+
OS="$os"
32+
ARCH="$arch"
33+
}
34+
35+
# --- Helpers ---
36+
37+
info() { echo "==> $*"; }
38+
ok() { echo " [ok] $*"; }
39+
skip() { echo " [skip] $* (already installed)"; }
40+
fail() { echo " [error] $*" >&2; }
41+
42+
command_exists() { command -v "$1" &>/dev/null; }
43+
44+
# Returns 0 if we can write to /usr/local/bin without sudo
45+
can_write_local_bin() { [ -w /usr/local/bin ]; }
46+
47+
install_binary() {
48+
local name="$1" url="$2"
49+
local tmp
50+
tmp="$(mktemp)"
51+
52+
info "Installing $name..."
53+
curl -fsSL -o "$tmp" "$url"
54+
chmod +x "$tmp"
55+
56+
if can_write_local_bin; then
57+
mv "$tmp" /usr/local/bin/"$name"
58+
else
59+
sudo install "$tmp" /usr/local/bin/"$name"
60+
rm -f "$tmp"
61+
fi
62+
63+
ok "$name $(command -v "$name")"
64+
}
65+
66+
# --- Tool installers ---
67+
68+
install_kubectl() {
69+
if command_exists kubectl; then
70+
skip "kubectl $(kubectl version --client -o json 2>/dev/null | grep gitVersion | head -1 | tr -d ' ",' | cut -d: -f2)"
71+
return
72+
fi
73+
74+
local url="https://dl.k8s.io/release/$(curl -fsSL https://dl.k8s.io/release/stable.txt)/bin/${OS}/${ARCH}/kubectl"
75+
install_binary kubectl "$url"
76+
}
77+
78+
install_skaffold() {
79+
if command_exists skaffold; then
80+
skip "skaffold $(skaffold version 2>/dev/null || echo 'unknown')"
81+
return
82+
fi
83+
84+
local url="https://storage.googleapis.com/skaffold/releases/latest/skaffold-${OS}-${ARCH}"
85+
install_binary skaffold "$url"
86+
}
87+
88+
install_pnpm() {
89+
if command_exists pnpm; then
90+
skip "pnpm $(pnpm --version 2>/dev/null)"
91+
return
92+
fi
93+
94+
info "Installing pnpm..."
95+
curl -fsSL https://get.pnpm.io/install.sh | sh -
96+
ok "pnpm"
97+
}
98+
99+
install_node() {
100+
if command_exists node; then
101+
local ver
102+
ver="$(node --version 2>/dev/null)"
103+
local major="${ver#v}"
104+
major="${major%%.*}"
105+
if [ "$major" -ge 18 ] 2>/dev/null; then
106+
skip "node $ver"
107+
return
108+
else
109+
fail "node $ver found but >= 18 required"
110+
return 1
111+
fi
112+
fi
113+
114+
fail "node not found — install Node.js >= 18 (https://nodejs.org)"
115+
return 1
116+
}
117+
118+
# --- Check mode ---
119+
120+
check_tool() {
121+
local name="$1"
122+
if command_exists "$name"; then
123+
local ver
124+
case "$name" in
125+
node) ver="$(node --version 2>/dev/null)" ;;
126+
pnpm) ver="$(pnpm --version 2>/dev/null)" ;;
127+
kubectl) ver="$(kubectl version --client -o json 2>/dev/null | grep gitVersion | head -1 | tr -d ' ",' | cut -d: -f2)" ;;
128+
skaffold) ver="$(skaffold version 2>/dev/null)" ;;
129+
docker) ver="$(docker --version 2>/dev/null)" ;;
130+
*) ver="installed" ;;
131+
esac
132+
printf " %-12s %s\n" "$name" "$ver"
133+
else
134+
printf " %-12s %s\n" "$name" "(missing)"
135+
fi
136+
}
137+
138+
run_check() {
139+
echo ""
140+
echo "Development tool status (${OS}/${ARCH}):"
141+
echo ""
142+
check_tool node
143+
check_tool pnpm
144+
check_tool docker
145+
check_tool kubectl
146+
check_tool skaffold
147+
echo ""
148+
149+
if ! command_exists docker; then
150+
echo "Note: Docker Desktop provides both docker and kubectl."
151+
echo " Install from https://www.docker.com/products/docker-desktop/"
152+
echo " Then enable Kubernetes in Docker Desktop settings."
153+
fi
154+
echo ""
155+
}
156+
157+
# --- Main ---
158+
159+
detect_platform
160+
161+
if [ "${1:-}" = "--check" ]; then
162+
run_check
163+
exit 0
164+
fi
165+
166+
echo ""
167+
echo "Setting up local k8s development tools (${OS}/${ARCH})"
168+
echo ""
169+
170+
install_node
171+
install_pnpm
172+
install_kubectl
173+
install_skaffold
174+
175+
echo ""
176+
echo "Done. Verify with: ./scripts/setup-dev.sh --check"
177+
echo ""
178+
echo "Next steps:"
179+
echo " 1. Enable Kubernetes in Docker Desktop settings"
180+
echo " 2. pnpm generate && pnpm install && pnpm build"
181+
echo " 3. make skaffold-dev"
182+
echo ""

0 commit comments

Comments
 (0)