Files
mev-beta/orig/scripts/build.sh
Administrator c54c569f30 refactor: move all remaining files to orig/ directory
Completed clean root directory structure:
- Root now contains only: .git, .env, docs/, orig/
- Moved all remaining files and directories to orig/:
  - Config files (.claude, .dockerignore, .drone.yml, etc.)
  - All .env variants (except active .env)
  - Git config (.gitconfig, .github, .gitignore, etc.)
  - Tool configs (.golangci.yml, .revive.toml, etc.)
  - Documentation (*.md files, @prompts)
  - Build files (Dockerfiles, Makefile, go.mod, go.sum)
  - Docker compose files
  - All source directories (scripts, tests, tools, etc.)
  - Runtime directories (logs, monitoring, reports)
  - Dependency files (node_modules, lib, cache)
  - Special files (--delete)

- Removed empty runtime directories (bin/, data/)

V2 structure is now clean:
- docs/planning/ - V2 planning documents
- orig/ - Complete V1 codebase preserved
- .env - Active environment config (not in git)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-10 10:53:05 +01:00

104 lines
2.9 KiB
Bash
Executable File

#!/usr/bin/env bash
set -euo pipefail
# Reusable, agnostic build script
# Can be used in any Go project by adjusting configuration
# Configuration variables
BINARY_NAME="${BINARY_NAME:-$(basename "$PWD")}"
BINARY_DIR="${BINARY_DIR:-bin}"
MAIN_FILE="${MAIN_FILE:-cmd/mev-bot/main.go}"
BUILD_TAGS="${BUILD_TAGS:-}"
LDFLAGS="${LDFLAGS:-}"
OUTPUT="${OUTPUT:-$BINARY_DIR/$BINARY_NAME}"
GOOS="${GOOS:-$(go env GOOS)}"
GOARCH="${GOARCH:-$(go env GOARCH)}"
# Parse command line arguments
while [[ $# -gt 0 ]]; do
case $1 in
-n|--name)
BINARY_NAME="$2"
shift 2
;;
-o|--output)
OUTPUT="$2"
shift 2
;;
-m|--main)
MAIN_FILE="$2"
shift 2
;;
-t|--tags)
BUILD_TAGS="$2"
shift 2
;;
-l|--ldflags)
LDFLAGS="$2"
shift 2
;;
--goos)
GOOS="$2"
shift 2
;;
--goarch)
GOARCH="$2"
shift 2
;;
-h|--help)
echo "Usage: $0 [OPTIONS]"
echo "Build a Go application with configurable options"
echo ""
echo "Options:"
echo " -n, --name NAME Binary name (default: current directory name)"
echo " -o, --output PATH Output path (default: bin/BINARY_NAME)"
echo " -m, --main PATH Main package path (default: .)"
echo " -t, --tags TAGS Build tags"
echo " -l, --ldflags FLAGS Ldflags to pass to go build"
echo " --goos OS Target OS (default: $(go env GOOS))"
echo " --goarch ARCH Target architecture (default: $(go env GOARCH))"
echo " -h, --help Show this help"
exit 0
;;
*)
echo "Unknown option: $1"
exit 1
;;
esac
done
echo "Building $BINARY_NAME for $GOOS/$GOARCH..."
# Ensure local Go cache directories exist when not provided
PROJECT_ROOT="$(pwd)"
if [[ -z "${GOCACHE:-}" ]]; then
export GOCACHE="${PROJECT_ROOT}/.gocache"
fi
if [[ -z "${GOMODCACHE:-}" ]]; then
export GOMODCACHE="${PROJECT_ROOT}/.gomodcache"
fi
if [[ -z "${GOPATH:-}" ]]; then
export GOPATH="${PROJECT_ROOT}/.gopath"
fi
if [[ -z "${GOFLAGS:-}" && -d "${PROJECT_ROOT}/vendor" ]]; then
export GOFLAGS="-mod=vendor"
fi
mkdir -p "$GOCACHE" "$GOMODCACHE" "${GOPATH}/pkg/mod"
# Create binary directory
mkdir -p "$(dirname "$OUTPUT")"
# Set environment variables for cross-compilation
export GOOS="$GOOS"
export GOARCH="$GOARCH"
# Build the application
echo "Building $BINARY_NAME..."
[ -n "$BUILD_TAGS" ] && echo " Build tags: $BUILD_TAGS"
[ -n "$LDFLAGS" ] && echo " LDFLAGS: $LDFLAGS"
go build -o "$OUTPUT" ${BUILD_TAGS:+-tags "$BUILD_TAGS"} ${LDFLAGS:+-ldflags "$LDFLAGS"} "$MAIN_FILE"
echo "Build completed successfully!"
echo "Binary: $OUTPUT"