-
Notifications
You must be signed in to change notification settings - Fork 0
feat: add script to build from source and support binary path with install.sh #58
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
tnsardesai
merged 3 commits into
main
from
tanmay/kernel-791-add-cicd-for-hypeman-deployment-staging-production
Jan 16, 2026
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,87 @@ | ||
| #!/bin/bash | ||
| # | ||
| # Hypeman Build from Source Script | ||
| # | ||
| # Usage: | ||
| # ./scripts/build-from-source.sh | ||
| # | ||
| # Options (via environment variables): | ||
| # OUTPUT_DIR - Full path of directory to place built binaries (optional, default: repo's root bin directory) | ||
| # | ||
|
|
||
| set -euo pipefail | ||
|
|
||
| # Default values | ||
| BINARY_NAME="hypeman-api" | ||
|
|
||
| # Colors for output (true color) | ||
| RED='\033[38;2;255;110;110m' | ||
| GREEN='\033[38;2;92;190;83m' | ||
| YELLOW='\033[0;33m' | ||
| PURPLE='\033[38;2;172;134;249m' | ||
| NC='\033[0m' # No Color | ||
|
|
||
| info() { echo -e "${GREEN}[INFO]${NC} $1"; } | ||
| warn() { echo -e "${YELLOW}[WARN]${NC} $1"; } | ||
| error() { echo -e "${RED}[ERROR]${NC} $1"; exit 1; } | ||
|
|
||
| # ============================================================================= | ||
| # Pre-flight checks - verify all requirements before doing anything | ||
| # ============================================================================= | ||
|
|
||
| # Check for required commands | ||
| command -v go >/dev/null 2>&1 || error "go is required but not installed" | ||
| command -v make >/dev/null 2>&1 || error "make is required but not installed" | ||
|
|
||
| # ============================================================================= | ||
| # Setup directories | ||
| # ============================================================================= | ||
|
|
||
| # Get the directory where this script is located | ||
| SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" | ||
| SOURCE_DIR="$(cd "${SCRIPT_DIR}/.." && pwd)" | ||
|
|
||
| : "${OUTPUT_DIR:=${SOURCE_DIR}/bin}" | ||
|
|
||
| # Validate OUTPUT_DIR is an absolute path | ||
| if [[ "$OUTPUT_DIR" != /* ]]; then | ||
| error "OUTPUT_DIR must be an absolute path (got: ${OUTPUT_DIR})" | ||
| fi | ||
|
|
||
| # Create output directory if it doesn't exist | ||
| mkdir -p "$OUTPUT_DIR" | ||
|
|
||
| BUILD_LOG="${OUTPUT_DIR}/build.log" | ||
| : > "$BUILD_LOG" | ||
|
|
||
| # ============================================================================= | ||
| # Build from source | ||
| # ============================================================================= | ||
|
|
||
| info "Building from source (${SOURCE_DIR})..." | ||
|
|
||
| info "Building binaries (this may take a few minutes)..." | ||
| cd "${SOURCE_DIR}" | ||
cursor[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| # Build main binary (includes dependencies) - capture output, show on error | ||
| if ! make build >> "$BUILD_LOG" 2>&1; then | ||
| echo "" | ||
| echo -e "${RED}Build failed. Full build log:${NC}" | ||
| cat "$BUILD_LOG" | ||
| error "Build failed" | ||
| fi | ||
| cp "bin/hypeman" "${OUTPUT_DIR}/${BINARY_NAME}" | ||
|
|
||
| # Build hypeman-token (not included in make build) | ||
| if ! go build -o "${OUTPUT_DIR}/hypeman-token" ./cmd/gen-jwt >> "$BUILD_LOG" 2>&1; then | ||
| echo "" | ||
| echo -e "${RED}Build failed. Full build log:${NC}" | ||
| cat "$BUILD_LOG" | ||
| error "Failed to build hypeman-token" | ||
| fi | ||
|
|
||
| # Copy .env.example for config template | ||
| cp ".env.example" "${OUTPUT_DIR}/.env.example" | ||
|
|
||
| info "Build complete" | ||
| info "Binaries are available in: ${OUTPUT_DIR}" | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,6 +9,7 @@ | |
| # VERSION - Install specific API version (default: latest) | ||
| # CLI_VERSION - Install specific CLI version (default: latest) | ||
| # BRANCH - Build from source using this branch (for development/testing) | ||
| # BINARY_DIR - Use binaries from this directory instead of building/downloading | ||
| # INSTALL_DIR - Binary installation directory (default: /opt/hypeman/bin) | ||
| # DATA_DIR - Data directory (default: /var/lib/hypeman) | ||
| # CONFIG_DIR - Config directory (default: /etc/hypeman) | ||
|
|
@@ -99,13 +100,30 @@ command -v systemctl >/dev/null 2>&1 || error "systemctl is required but not ins | |
| command -v setcap >/dev/null 2>&1 || error "setcap is required but not installed (install libcap2-bin)" | ||
| command -v openssl >/dev/null 2>&1 || error "openssl is required but not installed" | ||
|
|
||
| # Count how many of BRANCH, VERSION, BINARY_DIR are set | ||
| count=0 | ||
| [ -n "$BRANCH" ] && ((count++)) || true | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. heads up: if you adopt the bot's suggestion for |
||
| [ -n "$VERSION" ] && ((count++)) || true | ||
| [ -n "$BINARY_DIR" ] && ((count++)) || true | ||
|
|
||
| if [ "$count" -gt 1 ]; then | ||
| error "BRANCH, VERSION, and BINARY_DIR are mutually exclusive" | ||
| fi | ||
|
|
||
| # Additional checks for build-from-source mode | ||
| if [ -n "$BRANCH" ]; then | ||
| command -v git >/dev/null 2>&1 || error "git is required for BRANCH mode but not installed" | ||
| command -v go >/dev/null 2>&1 || error "go is required for BRANCH mode but not installed" | ||
| command -v make >/dev/null 2>&1 || error "make is required for BRANCH mode but not installed" | ||
| fi | ||
|
|
||
| # Additional checks for BINARY_DIR mode | ||
| if [ -n "$BINARY_DIR" ]; then | ||
| if [ ! -d "$BINARY_DIR" ]; then | ||
| error "BINARY_DIR does not exist: ${BINARY_DIR}. Are you sure you provided the correct path?" | ||
| fi | ||
| fi | ||
|
|
||
| # Detect OS | ||
| OS=$(uname -s | tr '[:upper:]' '[:lower:]') | ||
| if [ "$OS" != "linux" ]; then | ||
|
|
@@ -184,10 +202,30 @@ TMP_DIR=$(mktemp -d) | |
| trap "rm -rf $TMP_DIR" EXIT | ||
|
|
||
| # ============================================================================= | ||
| # Get binaries (either download release or build from source) | ||
| # Get binaries (either use BINARY_DIR, download release, or build from source) | ||
| # ============================================================================= | ||
|
|
||
| if [ -n "$BRANCH" ]; then | ||
| if [ -n "$BINARY_DIR" ]; then | ||
| # Use binaries from specified directory | ||
| info "Using binaries from ${BINARY_DIR}..." | ||
|
|
||
| # Copy binaries to TMP_DIR | ||
| info "Copying binaries from ${BINARY_DIR}..." | ||
|
|
||
| for f in "${BINARY_NAME}" "hypeman-token" ".env.example"; do | ||
| [ -f "${BINARY_DIR}/${f}" ] || error "File ${f} not found in ${BINARY_DIR}" | ||
| done | ||
|
|
||
| cp "${BINARY_DIR}/${BINARY_NAME}" "${TMP_DIR}/${BINARY_NAME}" | ||
| cp "${BINARY_DIR}/hypeman-token" "${TMP_DIR}/hypeman-token" | ||
| cp "${BINARY_DIR}/.env.example" "${TMP_DIR}/.env.example" | ||
|
|
||
| # Make binaries executable | ||
| chmod +x "${TMP_DIR}/${BINARY_NAME}" | ||
| chmod +x "${TMP_DIR}/hypeman-token" | ||
|
|
||
| VERSION="custom (from binary)" | ||
| elif [ -n "$BRANCH" ]; then | ||
| # Build from source mode | ||
| info "Building from source (branch: $BRANCH)..." | ||
|
|
||
|
|
@@ -405,7 +443,7 @@ $SUDO systemctl start "$SERVICE_NAME" | |
|
|
||
| CLI_REPO="kernel/hypeman-cli" | ||
|
|
||
| if [ -z "$CLI_VERSION" ]; then | ||
| if [ -z "$CLI_VERSION" ] || [ "$CLI_VERSION" == "latest" ]; then | ||
| info "Fetching latest CLI version with available artifacts..." | ||
| CLI_VERSION=$(find_release_with_artifact "$CLI_REPO" "hypeman" "$OS" "$ARCH") | ||
| if [ -z "$CLI_VERSION" ]; then | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor:
>> "$BUILD_LOG"appends across runs, which can make failures confusing. Truncating once at the start keeps the log scoped to the current build.