arm64环境编译harbor

本文档详细介绍了如何在ARM64架构上安装docker-compose,配置环境,解决编译Harbor过程中遇到的Redis问题,以及编译打包Harbor的各个组件,包括registry、chartmuseum和clair。

1. 安装docker-compose

参考https://www.huaweicloud.com/kunpeng/software/dockercompose.html

最后,将docker-compose-Linux-aarch64拷贝到/usr/bin目录下

mv /usr/bin/docker-compose-Linux-aarch64 /usr/bin/docker-compose

2. 在/etc/profile中加入如下内容

export GOPATH="/home/xxx/go" 
export PATH=$PATH:/usr/local/go/bin

并执行:

wget https://dl.google.com/go/go1.13.1.linux-arm64.tar.gz
tar -C /usr/local -xzf go1.13.1.linux-arm64.tar.gz

进入/home/xxx/go/src/github.com/goharbor目录,执行:

mkdir $GOPATH/src/github.com/goharbor/ -p
cd $GOPATH/src/github.com/goharbor/ 
git clone https://github.com/goharbor/harbor.git
cd $GOPATH/src/github.com/goharbor/harbor/
git checkout v1.9.3
cd $GOPATH/src/github.com/goharbor/harbor/make/photon
sed -i "s/FROM photon:2.0/FROM photon:latest/g" `grep 'FROM photon' -rl ./`
sed -it "s/BUILDBIN=false/BUILDBIN=true/g" $GOPATH/src/github.com/goharbor/harbor/Makefile
sed -i 's/docker\/distribution\/bin/docker\/distribution\/bin\/registry/g' $GOPATH/src/github.com/goharbor/harbor/make/photon/registry/builder

3. 解决redis-photo镜像中报错“<jemalloc>: Unsupported system page size arm64”

下载redis源码,并编译

cd /tmp/
wget http://download.redis.io/releases/redis-5.0.7.tar.gz
tar zxvf redis-5.0.7.tar.gz
cd redis-5.0.7/deps/jemalloc
./configure 
make -j20
make install
cd ../../
make MALLOC=jemalloc -j20
make MALLOC=libc
cp  src/redis-server  $GOPATH/src/github.com/goharbor/harbor/make/photon/redis

之后,修改 /home/xxx/go/src/github.com/goharbor/harbor/make/photon/redis/Dockerfile

在RUN tdnf install -y redis sudo之后,加入

COPY ./make/photon/redis/redis-server /usr/bin/redis-server

修改$GOPATH/src/github.com/goharbor/harbor/make/photon/Makefile

加入:

REGISTRY_SRC_TAG=v2.7.1

REGISTRYVERSION=v2.7.1

4. 编译并打包docker镜像

cd $GOPATH/src/github.com/goharbor/harbor/
echo 'v1.9.3-c80751b8' > UIVERSION
make compile 
#如果是1.10以上版本,还要执行 注释掉Makefile文件中build_base_docker的: $(PUSHSCRIPTPATH)/$(PUSHSCRIPTNAME) goharbor/harbor-$$name-base:$(BASEIMAGETAG) $(REGISTRYUSER) $(REGISTRYPASSWORD) || exit 1 ; \
#之后执行:make build_base_docker
make build 
make prepare 
make start

如果在make build的过程中,在

docker cp $ID:/go/src/github.com/docker/distribution/bin/registry/registry binary

的位置报错,则修改

/home/xxx/go/src/github.com/goharbor/harbor/make/photon/registry/builder,找到这一行:

docker cp $ID:/go/src/github.com/docker/distribution/bin/registry/registry binary

将其修改为docker cp $ID:/go/src/github.com/docker/distribution/bin/registry binary

5. 打包chartmuseum-photon镜像

1) 下载chartmuseum代码:

git clone https://github.com/helm/chartmuseum.git
如果在arm64平台下编译,还需要修改代码,将Makefile中:

build-linux: export GOARCH=amd64

改为

build-linux: export GOARCH=arm64

之后,执行make build

编译完成后,在bin目录下,会生成chartmuseum文件

2) 拷贝chartmuseum文件到$GOPATH/src/github.com/goharbor/harbor/make/photon/chartserver/binary/,并重命名为chartm

3) 回退到$GOPATH/src/github.com/goharbor/harbor/目录,执行

docker build  -f ./make/photon/chartserver/Dockerfile  . --no-cache

6. 打包clair镜像

执行如下命令:

#其中v2.1.3由Makefile中CLAIRVERSION指定
cd $GOPATH/src/github.com/goharbor/harbor/make/photon/clair/
./builder  v2.1.3 

#如果编译中出现golang下不到包的情形,需要在$GOPATH/src/github.com/goharbor/harbor/make/photon/clair/Dockerfile.binary第三行以后加入:

RUN go env -w GO111MODULE=on
RUN go env -w GOPROXY=https://goproxy.io,direct

#如果是在arm64平台上打包,还应该将$GOPATH/src/github.com/goharbor/harbor/make/photon/clair/dumb-init替换为arm64的版本,可以通过find /var -name dumb-init,找到其他容器中的该文件,用其他文件替换

退回到$GOPATH/src/github.com/goharbor/harbor/目录,执行如下命令完成打包:

docker build --build-arg harbor_base_image_version=dev -f make/photon/clair/Dockerfile -t goharbor/clair-photon:1.10.3 .

6. 打包clair-adapter镜像

#其中v1.0.1由Makefile中CLAIRADAPTERVERSION指定
 cd $GOPATH/src/github.com/goharbor/harbor/make/photon/clair-adapter/
 ./builder  v1.0.1

退回到$GOPATH/src/github.com/goharbor/harbor/目录,执行如下命令完成打包:

docker build --build-arg harbor_base_image_version=dev -f  make/photon/clair-adapter/Dockerfile -t goharbor/clair-adapter-photon:1.10.3 . 


 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值