89 lines
3.8 KiB
Bash
89 lines
3.8 KiB
Bash
#!/usr/bin/env bash
|
|
set -euo pipefail
|
|
|
|
# ── helpers ──────────────────────────────────────────────────────────
|
|
RED='\033[0;31m'; GREEN='\033[0;32m'; YELLOW='\033[1;33m'; NC='\033[0m'
|
|
log() { echo -e "${GREEN}[OK]${NC} $*"; }
|
|
warn() { echo -e "${YELLOW}[WARN]${NC} $*"; }
|
|
err() { echo -e "${RED}[ERR]${NC} $*"; exit 1; }
|
|
|
|
command_exists() { command -v "$1" &>/dev/null; }
|
|
|
|
# ── 1. Rust ─────────────────────────────────────────────────────────
|
|
if command_exists rustc; then
|
|
log "Rust $(rustc --version)"
|
|
else
|
|
warn "Rust not found, installing via rustup..."
|
|
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
|
|
# shellcheck disable=SC1091
|
|
source "$HOME/.cargo/env"
|
|
log "Rust installed: $(rustc --version)"
|
|
fi
|
|
|
|
# ── 2. Node.js ──────────────────────────────────────────────────────
|
|
if command_exists node; then
|
|
log "Node.js $(node --version)"
|
|
else
|
|
warn "Node.js not found, installing via nvm..."
|
|
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.1/install.sh | bash
|
|
# shellcheck disable=SC1090
|
|
export NVM_DIR="${HOME}/.nvm"
|
|
[ -s "$NVM_DIR/nvm.sh" ] && source "$NVM_DIR/nvm.sh"
|
|
nvm install --lts
|
|
log "Node.js installed: $(node --version)"
|
|
fi
|
|
|
|
# ── 2b. Bun ─────────────────────────────────────────────────────────
|
|
if command_exists bun; then
|
|
log "Bun $(bun --version)"
|
|
else
|
|
warn "Bun not found, installing..."
|
|
curl -fsSL https://bun.sh/install | bash
|
|
# shellcheck disable=SC1091
|
|
[ -s "$HOME/.bun/_bun" ] && export PATH="$HOME/.bun/bin:$PATH"
|
|
log "Bun installed: $(bun --version)"
|
|
fi
|
|
|
|
# ── 3. Docker ───────────────────────────────────────────────────────
|
|
if command_exists docker; then
|
|
log "Docker $(docker --version)"
|
|
else
|
|
warn "Docker not found, installing..."
|
|
curl -fsSL https://get.docker.com | sh
|
|
log "Docker installed: $(docker --version)"
|
|
fi
|
|
|
|
# ── 4. Frontend build ───────────────────────────────────────────────
|
|
log "Running bun install..."
|
|
bun install
|
|
|
|
log "Running bun run build..."
|
|
bun run build
|
|
|
|
# ── 5. Rust build ───────────────────────────────────────────────────
|
|
log "Running cargo build --release --workspace..."
|
|
cargo build --release --workspace
|
|
|
|
# ── 6. Docker images ────────────────────────────────────────────────
|
|
TAG=$(git rev-parse --short HEAD)
|
|
log "Building Docker images with tag: $TAG"
|
|
|
|
IMAGES=(
|
|
"docker/app.Dockerfile app:$TAG"
|
|
"docker/email.Dockerfile email-worker:$TAG"
|
|
"docker/githook.Dockerfile git-hook:$TAG"
|
|
"docker/gitserver.Dockerfile gitserver:$TAG"
|
|
"docker/metrics.Dockerfile metrics-aggregator:$TAG"
|
|
"docker/static.Dockerfile static-server:$TAG"
|
|
"docker/gingress.Dockerfile gingress:$TAG"
|
|
)
|
|
|
|
for entry in "${IMAGES[@]}"; do
|
|
read -r dockerfile tag <<< "$entry"
|
|
log "Building $tag..."
|
|
docker build -f "$dockerfile" -t "$tag" .
|
|
done
|
|
|
|
log "All images built successfully."
|
|
docker images | grep -E "app|email-worker|git-hook|gitserver|metrics-aggregator|static-server|gingress" | grep "$TAG" || true
|