下载源码
git clone -b v3.2.6 https://ghproxy.com/https://github.com/openark/orchestrator orchestrator-v3.2.6.git
修改go build参数-extldflags "-static",采用静态编译(script/build)
go build -i -o "$bindir/orchestrator" -ldflags "-extldflags "-static" -X main.AppVersion=${version} -X main.BuildDescribe=${describe}" ./go/cmd/orchestrator/main.go
启动golang编译环境
docker run --rm -it -v $(pwd)/orchestrator-v3.2.6.git:/orchestrator golang:1.16.15-buster /bin/bash
容器内执行
cat << EOF > /etc/apt/sources.list
deb http://mirrors.163.com/debian/ buster main non-free contrib
deb http://mirrors.163.com/debian/ buster-updates main non-free contrib
deb http://mirrors.163.com/debian/ buster-backports main non-free contrib
deb http://mirrors.163.com/debian-security/ buster/updates main non-free contrib
deb-src http://mirrors.163.com/debian/ buster main non-free contrib
deb-src http://mirrors.163.com/debian/ buster-updates main non-free contrib
deb-src http://mirrors.163.com/debian/ buster-backports main non-free contrib
deb-src http://mirrors.163.com/debian-security/ buster/updates main non-free contrib
EOF
apt update
apt install -y ruby-dev build-essential rsync
gem install fpm
修改编译脚本,改为静态编译
启动编译
go env -w GO111MODULE=auto
cd /orchestrator
bash script/build
退出容器,查看编译成果
# file orchestrator-v3.2.6.git/bin/orchestrator
orchestrator-v3.2.6.git/bin/orchestrator: ELF 64-bit LSB executable, ARM aarch64, version 1 (GNU/Linux), statically linked, for GNU/Linux 3.7.0, BuildID[sha1]=9f00013390904f708d54ea7f59727409d1b9a5a1, not stripped
# ./orchestrator-v3.2.6.git/bin/orchestrator --version
c846d43668239cad384dc31b9255a3ade3a35001
|