mgmt/compile-nomad-armv7.sh

96 lines
1.9 KiB
Bash
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/bin/bash
# Nomad ARMv7 自动编译脚本
# 适用于 onecloud1 节点
set -e
echo "🚀 开始编译 Nomad ARMv7 版本..."
# 检查系统架构
ARCH=$(uname -m)
echo "📋 当前系统架构: $ARCH"
# 设置Go环境变量
export GOOS=linux
export GOARCH=arm
export GOARM=7
export CGO_ENABLED=0
echo "🔧 设置编译环境:"
echo " GOOS=$GOOS"
echo " GOARCH=$GOARCH"
echo " GOARM=$GOARM"
echo " CGO_ENABLED=$CGO_ENABLED"
# 检查Go版本
if ! command -v go &> /dev/null; then
echo "❌ Go未安装正在安装..."
# 安装Go (假设是Ubuntu/Debian系统)
sudo apt update
sudo apt install -y golang-go
fi
GO_VERSION=$(go version)
echo "✅ Go版本: $GO_VERSION"
# 创建编译目录
BUILD_DIR="/tmp/nomad-build"
mkdir -p $BUILD_DIR
cd $BUILD_DIR
echo "📥 克隆 Nomad 源码..."
if [ -d "nomad" ]; then
echo "🔄 更新现有仓库..."
cd nomad
git pull
else
git clone https://github.com/hashicorp/nomad.git
cd nomad
fi
# 切换到最新稳定版本
echo "🏷️ 切换到最新稳定版本..."
git checkout $(git describe --tags --abbrev=0)
# 编译
echo "🔨 开始编译..."
make dev
# 检查编译结果
if [ -f "bin/nomad" ]; then
echo "✅ 编译成功!"
# 显示文件信息
file bin/nomad
ls -lh bin/nomad
# 备份现有Nomad
if [ -f "/usr/bin/nomad" ]; then
echo "💾 备份现有Nomad..."
sudo cp /usr/bin/nomad /usr/bin/nomad.backup.$(date +%Y%m%d-%H%M%S)
fi
# 安装新版本
echo "📦 安装新版本..."
sudo cp bin/nomad /usr/bin/nomad
sudo chmod +x /usr/bin/nomad
# 验证安装
echo "🔍 验证安装..."
/usr/bin/nomad version
echo "🎉 Nomad ARMv7 版本安装完成!"
else
echo "❌ 编译失败!"
exit 1
fi
# 清理
echo "🧹 清理编译文件..."
cd /
rm -rf $BUILD_DIR
echo "✨ 完成!"