diff options
Diffstat (limited to 'modes')
| -rwxr-xr-x | modes/base.sh | 53 | ||||
| -rwxr-xr-x | modes/build.sh | 29 | ||||
| -rwxr-xr-x | modes/db.sh | 24 | ||||
| -rwxr-xr-x | modes/logs.sh | 26 | ||||
| -rwxr-xr-x | modes/reset.sh | 30 |
5 files changed, 162 insertions, 0 deletions
diff --git a/modes/base.sh b/modes/base.sh new file mode 100755 index 0000000..e914d96 --- /dev/null +++ b/modes/base.sh @@ -0,0 +1,53 @@ +#!/usr/bin/env bash +# base.sh — sourced by all modes. Sets shared environment. Never executed directly. +# +# Customize this file for your specific project and toolchain. +# Do not add mode-specific logic here. + +# ── Project root ────────────────────────────────────────────────────────────── +# Resolves to the repo root regardless of where ms is invoked from. +export PROJECT_ROOT +PROJECT_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" + +# ── Secrets ─────────────────────────────────────────────────────────────────── +# Load secrets from 1Password CLI if available, otherwise fall back to .env. +# Never commit .env. Never hardcode credentials here. +# +# Option A: 1Password CLI (preferred) +# export OP_ACCOUNT="my.1password.com" +# eval "$(op signin)" +# +# Option B: doppler +# eval "$(doppler secrets download --no-file --format env)" +# +# Option C: local .env (dev only, never commit) +if [[ -f "$PROJECT_ROOT/.env" ]]; then + # shellcheck source=/dev/null + set -a + source "$PROJECT_ROOT/.env" + set +a +fi + +# ── Database ────────────────────────────────────────────────────────────────── +# Set these via secrets above; stubs provided for clarity. +export DB_HOST="${DB_HOST:-localhost}" +export DB_PORT="${DB_PORT:-5432}" +export DB_NAME="${DB_NAME:-}" +export DB_USER="${DB_USER:-}" +export DB_PASS="${DB_PASS:-}" + +# ── Runtime ─────────────────────────────────────────────────────────────────── +# Configure the runtime environment your project uses. +# Examples — uncomment and adjust as needed: +# +# Docker Compose: +# export COMPOSE_FILE="$PROJECT_ROOT/docker-compose.yml" +# +# nix: +# # (handled by nix develop — base.sh runs inside the devshell) +# +# Tool versions (if using mise/asdf): +# export MISE_TOML="$PROJECT_ROOT/.mise.toml" + +# ── Path additions ──────────────────────────────────────────────────────────── +export PATH="$PROJECT_ROOT/bin:$PATH" diff --git a/modes/build.sh b/modes/build.sh new file mode 100755 index 0000000..1b75a05 --- /dev/null +++ b/modes/build.sh @@ -0,0 +1,29 @@ +#!/usr/bin/env bash +# build — run the project build pipeline +set -euo pipefail + +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +# shellcheck source=base.sh +source "$SCRIPT_DIR/base.sh" + +cd "$PROJECT_ROOT" + +# ── TODO: uncomment and configure for your build tool ──────────────────────── + +# just +# exec just build + +# make +# exec make build + +# go +# exec go build ./... + +# npm / yarn / pnpm +# exec npm run build + +# cargo +# exec cargo build --release + +echo "error: no build command configured in modes/build.sh" >&2 +exit 1 diff --git a/modes/db.sh b/modes/db.sh new file mode 100755 index 0000000..75c4833 --- /dev/null +++ b/modes/db.sh @@ -0,0 +1,24 @@ +#!/usr/bin/env bash +# db — open an interactive database shell with project credentials +set -euo pipefail + +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +# shellcheck source=base.sh +source "$SCRIPT_DIR/base.sh" + +# ── TODO: uncomment and configure for your database ────────────────────────── + +# PostgreSQL +# exec psql "postgresql://$DB_USER:$DB_PASS@$DB_HOST:$DB_PORT/$DB_NAME" + +# MySQL / MariaDB +# exec mysql -h "$DB_HOST" -P "$DB_PORT" -u "$DB_USER" -p"$DB_PASS" "$DB_NAME" + +# SQLite +# exec sqlite3 "$PROJECT_ROOT/db.sqlite3" + +# Redis +# exec redis-cli -h "$DB_HOST" + +echo "error: no database configured in modes/db.sh" >&2 +exit 1 diff --git a/modes/logs.sh b/modes/logs.sh new file mode 100755 index 0000000..ae396bc --- /dev/null +++ b/modes/logs.sh @@ -0,0 +1,26 @@ +#!/usr/bin/env bash +# logs — stream runtime logs for the project +set -euo pipefail + +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +# shellcheck source=base.sh +source "$SCRIPT_DIR/base.sh" + +cd "$PROJECT_ROOT" + +# ── TODO: uncomment and configure for your runtime ─────────────────────────── + +# Docker Compose (all services) +# exec docker compose logs -f + +# Docker Compose (specific service) +# exec docker compose logs -f app + +# journald +# exec journalctl -fu your-service-name + +# Log file +# exec tail -f "$PROJECT_ROOT/logs/app.log" + +echo "error: no log source configured in modes/logs.sh" >&2 +exit 1 diff --git a/modes/reset.sh b/modes/reset.sh new file mode 100755 index 0000000..4a8a3fc --- /dev/null +++ b/modes/reset.sh @@ -0,0 +1,30 @@ +#!/usr/bin/env bash +# reset — destroy and rebuild the environment from scratch (DESTRUCTIVE) +set -euo pipefail + +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +# shellcheck source=base.sh +source "$SCRIPT_DIR/base.sh" + +cd "$PROJECT_ROOT" + +echo "WARNING: This will destroy and rebuild the environment." +echo "All local state will be lost." +echo "" +read -rp "Continue? [y/N] " confirm +[[ "$confirm" =~ ^[Yy]$ ]] || { echo "Aborted."; exit 1; } + +# ── TODO: implement your teardown and rebuild steps ─────────────────────────── + +# Example: Docker Compose teardown + rebuild +# docker compose down --volumes --remove-orphans +# docker compose build --no-cache +# docker compose up -d +# docker compose exec app <your-migration-command> + +# Example: nix / devenv +# nix flake update +# direnv reload + +echo "error: no reset steps configured in modes/reset.sh" >&2 +exit 1 |
