Rancher arm64环境编译
一、go开发环境安装
- 下载golang安装包、并解压
wget https://studygolang.com/dl/golang/go1.13.3.linux-arm64.tar.gz
tar -C /usr/local -xzf go1.13.3.linux-arm64.tar.gz
- 配置环境变量
echo "export GOROOT=/usr/local/go" >> /etc/profile
echo "export PATH=$PATH:$GOROOT/bin" >> /etc/profile
- 设置 GOPATH 编译目录,需要编译的项目都应该放到该目录
mkdir -p /test
echo "export GOPATH=/test" >> /etc/profile
4.生效环境配置
source /etc/profile
5.验证go环境是否生效
go version
go env
二、Rancher编译
- 获取代码
#以防万一重新设置一次gopath路径
export GOPATH=/test
mkdir -p $GOPATH/src/github.com/rancher/
cd $GOPATH/src/github.com/rancher/
git clone https://github.com/rancher/rancher
cd rancher
- 做适当修改
#检出最新的tag版本
git checkout v2.3.1
修改对应 version
vim scripts/version
#!/bin/bash
shopt -s extglob
if [ -n "$(git status --porcelain --untracked-files=no)" ]; then
DIRTY="-dirty"
fi
COMMIT=$(git rev-parse --short HEAD)
COMMIT_DATE=$(git --no-pager log -1 --format='%ct')
COMMIT_BRANCH=$(git rev-parse --abbrev-ref HEAD | sed -E 's/[^a-zA-Z0-9]+/-/g')
GIT_TAG=${DRONE_TAG:-$(git tag -l --contains HEAD | head -n 1)}
LAST_TAG=${GIT_TAG:-'v0.0.0'}
if [[ -z "$DIRTY" && -n "$GIT_TAG" ]]; then
VERSION=$GIT_TAG
else
VERSION=$GIT_TAG
fi
# Chart tag.
if [[ -z "${DIRTY}" && -n "${GIT_TAG}" ]]; then
CHART_VERSION="${GIT_TAG}"
elif [[ "$DIRTY" ]]; then
CHART_VERSION="${GIT_TAG}"
else
CHART_VERSION="${GIT_TAG}"
fi
# Drop the v prefix for Chart Version to follow existing pattern.
CHART_VERSION="$(echo ${CHART_VERSION} | sed -E 's/^v//' | sed -e 's/^\(.\{55\}\).*/\1/')"
# Chart Repo - Target Repo for releases.
case $CHART_VERSION in
*-alpha*) # All alpha tags
CHART_REPO="alpha" ;;
*-rc*) # All rc tags
CHART_REPO="latest" ;;
+([0-9]).+([0-9]).+([0-9])) # All release tags
CHART_REPO="latest" ;;
*) # Anything else - Future use
CHART_REPO="dev" ;;
esac
if [ -z "$ARCH" ]; then
ARCH=arm64
fi
echo "ARCH: $ARCH"
echo "CHART_REPO: $CHART_REPO"
echo "CHART_VERSION: $CHART_VERSION"
echo "VERSION: $VERSION"
- 编译
./scripts/build
- 验证二进制包
ls bin/
bin/rancher -h
bin/agent -h
- 打包
打包需要为镜像Dockerfile做一些必要的修改
mkdir dist
由于不可描述的网络问题,因此加入必要的http和https的proxy。
sed -i '1a ARG https_proxy=http://xxx.xxx.xxx.xxx:xxxxx' package/Dockerfile
sed -i '1a ARG http_proxy=http://xxx.xxx.xxx.xxx:xxxxx' package/Dockerfile
sed -i '1a ARG https_proxy=http://xxx.xxx.xxx.xxx:xxxxx' package/Dockerfile.agent
sed -i '1a ARG http_proxy=http://xxx.xxx.xxx.xxx:xxxxx' package/Dockerfile.agent
#开始执行
./scripts/package
- 查看docker镜像
docker ps
- 运行rancher
docker run -d \
--restart=unless-stopped \
--name rancherdev \
-p 10080:80 -p 10443:443 \
-v /rancherdev:/var/lib/rancher/ \
-e AUDIT_LEVEL=3 \
rancher/rancher:v2.3.1_arm64