Skip to content

Commit eff4b64

Browse files
committed
Create repeatable local dev environment script for macOS
1 parent 9e99c3a commit eff4b64

5 files changed

Lines changed: 159 additions & 107 deletions

File tree

β€Ž.github/actions/setup-rust/action.ymlβ€Ž

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,6 @@ runs:
3939
uses: Swatinem/rust-cache@v2
4040
with:
4141
shared-key: ${{ inputs.cache-key }}
42+
# Cache ~/.cargo/bin so cargo-installed tools (cargo-audit, tarpaulin,
43+
# cargo-watch) are restored across runs without reinstalling.
44+
cache-all-crates: true

β€Ž.github/workflows/performance.ymlβ€Ž

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,21 @@ jobs:
7878
- name: Build operator binary
7979
run: cargo build --release --locked --bin stellar-operator
8080

81+
- name: Set up Docker Buildx
82+
uses: docker/setup-buildx-action@v3
83+
8184
- name: Build Docker image
82-
run: docker build -t "stellar-operator:${{ steps.version.outputs.version }}" .
85+
uses: docker/build-push-action@v6
86+
with:
87+
context: .
88+
target: runtime
89+
platforms: linux/amd64
90+
push: false
91+
load: true
92+
tags: stellar-operator:${{ steps.version.outputs.version }}
93+
cache-from: type=gha,scope=perf-docker
94+
cache-to: type=gha,mode=max,scope=perf-docker
95+
provenance: false
8396

8497
- name: Save Docker image
8598
run: |

β€ŽCargo.lockβ€Ž

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

β€ŽCargo.tomlβ€Ž

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,6 @@ http = "1"
5151
# Schema generation for CRDs
5252
schemars = { version = "0.8", features = ["chrono"] }
5353

54-
# Hyper for body operations
55-
hyper = "1"
56-
5754
# Error handling
5855
thiserror = "1"
5956
anyhow = "1"

β€Žscripts/setup-mac.shβ€Ž

Lines changed: 142 additions & 102 deletions
Original file line numberDiff line numberDiff line change
@@ -1,126 +1,166 @@
11
#!/bin/bash
2+
# Repeatable macOS dev environment bootstrap for Stellar-K8s.
3+
# Safe to run multiple times β€” skips steps already at the right version.
24
set -euo pipefail
35

4-
# Colors for output
5-
RED='\033[0;31m'
6-
GREEN='\033[0;32m'
7-
YELLOW='\033[1;33m'
8-
NC='\033[0m' # No Color
6+
# ── Pinned versions ───────────────────────────────────────────────────────────
7+
RUST_TOOLCHAIN="1.92" # keep in sync with ci.yml toolchain
8+
KIND_VERSION="0.24.0"
9+
KUBECTL_VERSION="1.30.0"
10+
HELM_VERSION="3.16.0"
11+
K6_VERSION="0.54.0"
912

10-
echo -e "${GREEN}=== Stellar-K8s macOS Development Setup ===${NC}\n"
13+
# ── Colours ───────────────────────────────────────────────────────────────────
14+
RED='\033[0;31m'; GREEN='\033[0;32m'; YELLOW='\033[1;33m'; NC='\033[0m'
15+
ok() { echo -e "${GREEN}βœ“ $*${NC}"; }
16+
warn() { echo -e "${YELLOW}⚠ $*${NC}"; }
17+
fail() { echo -e "${RED}βœ— $*${NC}"; exit 1; }
18+
step() { echo -e "\n${YELLOW}β†’ $*${NC}"; }
1119

12-
# Check if running on macOS
13-
if [[ "$OSTYPE" != "darwin"* ]]; then
14-
echo -e "${RED}Error: This script is for macOS only${NC}"
15-
exit 1
16-
fi
17-
18-
# Install Homebrew if not present
19-
if ! command -v brew &> /dev/null; then
20-
echo -e "${YELLOW}Installing Homebrew...${NC}"
21-
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
22-
else
23-
echo -e "${GREEN}βœ“ Homebrew already installed${NC}"
24-
fi
25-
26-
# Install Rust
27-
if ! command -v rustc &> /dev/null; then
28-
echo -e "${YELLOW}Installing Rust...${NC}"
29-
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
30-
source "$HOME/.cargo/env"
31-
else
32-
echo -e "${GREEN}βœ“ Rust already installed ($(rustc --version))${NC}"
33-
fi
20+
echo -e "${GREEN}=== Stellar-K8s macOS Dev Setup ===${NC}"
21+
echo " Rust ${RUST_TOOLCHAIN} | kind ${KIND_VERSION} | kubectl ${KUBECTL_VERSION} | helm ${HELM_VERSION}"
3422

35-
# Update Rust to latest stable
36-
echo -e "${YELLOW}Updating Rust to latest stable...${NC}"
37-
rustup update stable
38-
rustup component add rustfmt clippy
23+
[[ "$OSTYPE" == "darwin"* ]] || fail "This script is for macOS only."
3924

40-
# Install Docker
41-
if ! command -v docker &> /dev/null; then
42-
echo -e "${YELLOW}Installing Docker...${NC}"
43-
brew install --cask docker
44-
echo -e "${YELLOW}Please start Docker Desktop from Applications folder${NC}"
45-
else
46-
echo -e "${GREEN}βœ“ Docker already installed${NC}"
47-
fi
48-
49-
# Install kubectl
50-
if ! command -v kubectl &> /dev/null; then
51-
echo -e "${YELLOW}Installing kubectl...${NC}"
52-
brew install kubectl
53-
else
54-
echo -e "${GREEN}βœ“ kubectl already installed ($(kubectl version --client --short 2>/dev/null || echo 'version check failed'))${NC}"
55-
fi
56-
57-
# Install kind
58-
if ! command -v kind &> /dev/null; then
59-
echo -e "${YELLOW}Installing kind...${NC}"
60-
brew install kind
25+
# ── Homebrew ──────────────────────────────────────────────────────────────────
26+
step "Homebrew"
27+
if ! command -v brew &>/dev/null; then
28+
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
6129
else
62-
echo -e "${GREEN}βœ“ kind already installed${NC}"
30+
ok "Homebrew $(brew --version | head -1)"
6331
fi
6432

65-
# Install Helm
66-
if ! command -v helm &> /dev/null; then
67-
echo -e "${YELLOW}Installing Helm...${NC}"
68-
brew install helm
33+
# ── Rust / rustup ─────────────────────────────────────────────────────────────
34+
step "Rust toolchain (${RUST_TOOLCHAIN})"
35+
if ! command -v rustup &>/dev/null; then
36+
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- \
37+
-y --default-toolchain "${RUST_TOOLCHAIN}" --profile minimal
38+
# shellcheck source=/dev/null
39+
source "${HOME}/.cargo/env"
6940
else
70-
echo -e "${GREEN}βœ“ Helm already installed ($(helm version --short 2>/dev/null || echo 'version check failed'))${NC}"
41+
# Ensure the pinned toolchain is installed and set as default.
42+
rustup toolchain install "${RUST_TOOLCHAIN}" --profile minimal 2>/dev/null || true
43+
rustup default "${RUST_TOOLCHAIN}"
44+
ok "Rust $(rustc --version)"
7145
fi
72-
73-
# Install GitHub CLI
74-
if ! command -v gh &> /dev/null; then
75-
echo -e "${YELLOW}Installing GitHub CLI...${NC}"
76-
brew install gh
46+
rustup component add rustfmt clippy 2>/dev/null || true
47+
ok "rustfmt + clippy"
48+
49+
# ── Homebrew packages (idempotent: brew install is a no-op if present) ────────
50+
step "Homebrew packages"
51+
BREW_PKGS=(
52+
docker
53+
kind
54+
kubectl
55+
helm
56+
gh
57+
pre-commit
58+
shellcheck
59+
k6
60+
)
61+
for pkg in "${BREW_PKGS[@]}"; do
62+
if brew list --formula "$pkg" &>/dev/null || brew list --cask "$pkg" &>/dev/null; then
63+
ok "$pkg already installed"
64+
else
65+
echo " Installing $pkg …"
66+
brew install "$pkg" 2>/dev/null || brew install --cask "$pkg"
67+
ok "$pkg installed"
68+
fi
69+
done
70+
71+
# ── Version pins: warn if the installed version differs from pinned ────────────
72+
step "Version checks"
73+
_check_version() {
74+
local tool=$1 want=$2 got=$3
75+
if [[ "$got" == "$want"* ]]; then
76+
ok "${tool} ${got}"
77+
else
78+
warn "${tool}: installed ${got}, pinned ${want} β€” run: brew upgrade ${tool}"
79+
fi
80+
}
81+
82+
KIND_GOT=$(kind --version 2>/dev/null | awk '{print $3}' || echo "missing")
83+
_check_version "kind" "${KIND_VERSION}" "${KIND_GOT}"
84+
85+
KUBECTL_GOT=$(kubectl version --client -o json 2>/dev/null | \
86+
python3 -c "import sys,json; print(json.load(sys.stdin)['clientVersion']['gitVersion'].lstrip('v'))" \
87+
2>/dev/null || echo "missing")
88+
_check_version "kubectl" "${KUBECTL_VERSION}" "${KUBECTL_GOT}"
89+
90+
HELM_GOT=$(helm version --short 2>/dev/null | sed 's/v//' | cut -d'+' -f1 || echo "missing")
91+
_check_version "helm" "${HELM_VERSION}" "${HELM_GOT}"
92+
93+
K6_GOT=$(k6 version 2>/dev/null | awk '{print $2}' | sed 's/v//' || echo "missing")
94+
_check_version "k6" "${K6_VERSION}" "${K6_GOT}"
95+
96+
# ── Cargo tools ───────────────────────────────────────────────────────────────
97+
step "Cargo tools"
98+
for tool in cargo-audit cargo-watch; do
99+
if cargo "${tool#cargo-}" --version &>/dev/null 2>&1 || \
100+
"${HOME}/.cargo/bin/${tool}" --version &>/dev/null 2>&1; then
101+
ok "${tool} already installed"
102+
else
103+
echo " Installing ${tool} …"
104+
cargo install --locked "${tool}"
105+
ok "${tool} installed"
106+
fi
107+
done
108+
109+
# ── Pre-commit hooks ──────────────────────────────────────────────────────────
110+
step "Pre-commit hooks"
111+
REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
112+
if [[ -f "${REPO_ROOT}/.git/hooks/pre-commit" ]]; then
113+
ok "pre-commit hook already installed"
77114
else
78-
echo -e "${GREEN}βœ“ GitHub CLI already installed${NC}"
115+
(cd "${REPO_ROOT}" && pre-commit install && pre-commit install --hook-type pre-push)
116+
ok "pre-commit hooks installed"
79117
fi
80118

81-
# Install Make
82-
if ! command -v make &> /dev/null; then
83-
echo -e "${YELLOW}Installing Make...${NC}"
84-
brew install make
119+
# ── Docker Desktop check ──────────────────────────────────────────────────────
120+
step "Docker"
121+
if docker info &>/dev/null 2>&1; then
122+
ok "Docker daemon is running"
85123
else
86-
echo -e "${GREEN}βœ“ Make already installed${NC}"
124+
warn "Docker daemon is NOT running."
125+
warn "Start Docker Desktop from your Applications folder, then re-run this script."
87126
fi
88127

89-
# Install cargo-audit
90-
if ! cargo audit --version &> /dev/null; then
91-
echo -e "${YELLOW}Installing cargo-audit...${NC}"
92-
cargo install cargo-audit
128+
# ── Local kind cluster (optional, idempotent) ─────────────────────────────────
129+
step "Local kind cluster 'stellar-dev'"
130+
if kind get clusters 2>/dev/null | grep -q "^stellar-dev$"; then
131+
ok "kind cluster 'stellar-dev' already exists"
93132
else
94-
echo -e "${GREEN}βœ“ cargo-audit already installed${NC}"
133+
if docker info &>/dev/null 2>&1; then
134+
kind create cluster --name stellar-dev --wait 60s
135+
ok "kind cluster 'stellar-dev' created"
136+
kubectl apply -f "${REPO_ROOT}/config/crd/stellarnode-crd.yaml"
137+
ok "StellarNode CRD applied"
138+
else
139+
warn "Skipping cluster creation β€” Docker not running. Run 'make quickstart' later."
140+
fi
95141
fi
96142

97-
# Install pre-commit
98-
if ! command -v pre-commit &> /dev/null; then
99-
echo -e "${YELLOW}Installing pre-commit...${NC}"
100-
brew install pre-commit
143+
# ── GitHub CLI auth reminder ──────────────────────────────────────────────────
144+
step "GitHub CLI"
145+
if gh auth status &>/dev/null 2>&1; then
146+
ok "gh already authenticated ($(gh auth status 2>&1 | grep 'Logged in' | head -1 | xargs))"
101147
else
102-
echo -e "${GREEN}βœ“ pre-commit already installed${NC}"
148+
warn "Run: gh auth login"
103149
fi
104150

105-
echo -e "\n${GREEN}=== Installation Complete ===${NC}\n"
106-
107-
# Verification
108-
echo -e "${YELLOW}Verifying installations...${NC}"
109-
echo "Rust: $(rustc --version)"
110-
echo "Cargo: $(cargo --version)"
111-
echo "Docker: $(docker --version 2>/dev/null || echo 'Not running')"
112-
echo "kubectl: $(kubectl version --client --short 2>/dev/null || echo 'Not available')"
113-
echo "kind: $(kind --version)"
114-
echo "Helm: $(helm version --short 2>/dev/null || echo 'Not available')"
115-
echo "GitHub CLI: $(gh --version 2>/dev/null | head -1)"
116-
echo "Make: $(make --version | head -1)"
117-
echo "pre-commit: $(pre-commit --version)"
118-
119-
echo -e "\n${YELLOW}Manual Steps:${NC}"
120-
echo "1. Start Docker Desktop from Applications folder"
121-
echo "2. Configure GitHub CLI: gh auth login"
122-
echo "3. Clone the repository: git clone https://github.com/YOUR_USERNAME/stellar-k8s.git"
123-
echo "4. Setup development environment: cd stellar-k8s && make dev-setup"
124-
echo "5. Run tests: make test"
125-
126-
echo -e "\n${GREEN}Setup complete! Happy coding! πŸš€${NC}"
151+
# ── Summary ───────────────────────────────────────────────────────────────────
152+
echo ""
153+
echo -e "${GREEN}=== Setup complete ===${NC}"
154+
echo ""
155+
echo " Rust : $(rustc --version 2>/dev/null)"
156+
echo " Cargo : $(cargo --version 2>/dev/null)"
157+
echo " Docker : $(docker --version 2>/dev/null || echo 'not running')"
158+
echo " kubectl : $(kubectl version --client --short 2>/dev/null | head -1)"
159+
echo " kind : $(kind --version 2>/dev/null)"
160+
echo " Helm : $(helm version --short 2>/dev/null)"
161+
echo " k6 : $(k6 version 2>/dev/null | head -1)"
162+
echo " pre-commit: $(pre-commit --version 2>/dev/null)"
163+
echo ""
164+
echo "Next steps:"
165+
echo " make ci-local β€” fmt + lint + audit + test + build"
166+
echo " make quickstart β€” full kind cluster end-to-end"

0 commit comments

Comments
Β (0)