Skip to content

Commit c8450d4

Browse files
authored
Merge pull request #43 from yakumioto/main
support arm64 compilation based on docker-build
2 parents 4532a2e + 0fab879 commit c8450d4

File tree

11 files changed

+158
-11
lines changed

11 files changed

+158
-11
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,5 @@
55
/native-build/.env
66
/native-build/cos.yaml
77
*.log
8+
9+
cache

docker-build/README.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ FATE_DIR=/root/FATE bash build.sh all
9999
| `Build_GPU` | Build images that supports GPU | 0 |
100100
| `Build_LLM` | Build images that supports FATE-LLM | 0 |
101101
| `Build_LLM_VERSION` | FATE-LLM version | v1.2.0 |
102+
| `Platform` | Architecture types | amd64 |
102103

103104
The command creates the base images and then the component images. After the command finishes, all images of FATE should be created. Use `docker images` to check the newly generated images:
104105

@@ -139,7 +140,18 @@ The above are all images that can be built using FATE-Builder, if you want to bu
139140

140141
```sh
141142
FATE_DIR=/root/FATE TAG=1.11.2-release Build_Basic=1 Build_NN=1 Build_FUM=1 Build_Spark=1 Build_OP=1 Build_IPCL=1 Build_GPU=1 Build_LLM=1 Build_LLM_VERSION=v1.2.0 IPCL_PKG_DIR=/root/pailliercryptolib_python/ IPCL_VERSION=v1.1.3 bash docker-build/build.sh all
142-
``
143+
```
144+
145+
### Cross-compilation function (optional)
146+
The "Platform" field can be used to specify the processor architecture types that the built image can support, currently supporting arm64 and amd64. If this field is not specified, amd64 will be defaulted.
147+
148+
This function supports building images that support either arm64 or amd64 architecture under the amd64 architecture, and it also supports building images that support either arm64 or amd64 architectures under the arm64 architecture.
149+
150+
For example, if you want to build an arm64 image, you can use the following command.For example, if you want to build an arm64 image, you can use the following command. (The current version only supports building basic images when building images that support the arm64 architecture, that is, Build_Basic=1)
151+
152+
```sh
153+
Platform=arm64 FATE_DIR=/root/FATE TAG=1.11.2-release Build_Basic=1 Build_NN=0 Build_FUM=0 Build_Spark=0 Build_OP=0 Build_IPCL=0 Build_GPU=0 Build_LLM=0 Build_LLM_VERSION=v1.2.0 IPCL_PKG_DIR=/root/pailliercryptolib_python/ IPCL_VERSION=v1.1.3 bash docker-build/build.sh all
154+
```
143155

144156
### Pushing images to a registry (optional)
145157

docker-build/README_zh.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ FATE_DIR=/root/FATE bash build.sh all
100100
| `Build_GPU` | 构建支持GPU的镜像 | 0 |
101101
| `Build_LLM` | 构建支持FATE-LLM的镜像 | 0 |
102102
| `Build_LLM_VERSION` | 构建支持Build_LLM_VERSION镜像的版本 | v1.2.0 |
103+
| `Platform` | 构建的镜像支持的架构类型 | amd64 |
103104

104105
所有用于构建镜像的“ Dockerfile”文件都存储在“docker/“子目录下。在脚本运行完之后,用户可以通过以下命令来检查构建好的镜像:
105106

@@ -149,6 +150,17 @@ federatedai/base-image <TAG>
149150
FATE_DIR=/root/FATE TAG=1.11.2-release Build_Basic=1 Build_NN=1 Build_FUM=1 Build_Spark=1 Build_OP=1 Build_IPCL=1 Build_GPU=1 Build_LLM=1 Build_LLM_VERSION=v1.2.0 IPCL_PKG_DIR=/root/pailliercryptolib_python/ IPCL_VERSION=v1.1.3 bash docker-build/build.sh all
150151
```
151152

153+
### 交叉编译功能(可选)
154+
可通过Platform字段指定构建的镜像支持的处理器架构类型,当前支持arm64和amd64。不指定该字段,则默认amd64。
155+
156+
本功能支持在amd64架构下构建支持arm64或amd64架构的镜像,且支持在arm64架构下构建支持arm64或amd64架构的镜像。
157+
158+
例如,如果想要构建arm64的镜像可以使用下面的命令。(当前版本在构建支持arm64架构的镜像时只支持构建基本的镜像,即Build_Basic=1)
159+
160+
```sh
161+
Platform=arm64 FATE_DIR=/root/FATE TAG=1.11.2-release Build_Basic=1 Build_NN=0 Build_FUM=0 Build_Spark=0 Build_OP=0 Build_IPCL=0 Build_GPU=0 Build_LLM=0 Build_LLM_VERSION=v1.2.0 IPCL_PKG_DIR=/root/pailliercryptolib_python/ IPCL_VERSION=v1.1.3 bash docker-build/build.sh all
162+
```
163+
152164
### 把镜像推送到镜像仓库(可选)
153165

154166
如果用户需要把构建出来的镜像推送到镜像仓库如DockerHub去的话,需要先通过以下命令登录相应的用户:

docker-build/base/basic/Dockerfile renamed to docker-build/base/basic/Dockerfile.amd64

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,4 @@ RUN python3 -m venv $VIRTUAL_ENV
3333
ENV PATH="$VIRTUAL_ENV/bin:$PATH"
3434

3535
RUN pip install --upgrade pip && \
36-
pip install --no-cache-dir -r requirements.txt
36+
pip install --no-cache-dir -r requirements.txt
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
FROM ubuntu:bionic-20220913
2+
3+
ARG version
4+
5+
USER root
6+
WORKDIR /data/projects/python/
7+
ENV VIRTUAL_ENV /data/projects/python/venv
8+
9+
RUN apt-get update && \
10+
apt-get install -y curl gcc g++ make openssl supervisor libgmp-dev \
11+
libmpfr-dev libmpc-dev libaio1 libaio-dev numactl autoconf automake \
12+
libtool libffi-dev libssl-dev liblz4-1 liblz4-dev liblz4-tool zlib1g \
13+
zlib1g-dev xz-utils libopenblas-dev liblapack-dev libsm-dev pkg-config \
14+
libblas-dev libatlas-base-dev libtinfo-dev gfortran libbz2-dev liblzma-dev \
15+
libsnappy-dev && \
16+
apt-get autoremove && \
17+
apt-get clean && \
18+
rm -rf /var/lib/apt/lists/*
19+
20+
RUN curl -o Python-3.8.13.tar.xz https://www.python.org/ftp/python/3.8.13/Python-3.8.13.tar.xz && \
21+
tar -xvf Python-3.8.13.tar.xz && \
22+
cd Python-3.8.13 && \
23+
./configure --prefix=/opt/python3 && \
24+
make altinstall && \
25+
ln -s /opt/python3/bin/python3.8 /usr/local/bin/python3.8 && \
26+
ln -s /usr/local/bin/python3.8 /usr/local/bin/python3 && \
27+
ln -s /usr/local/bin/python3 /usr/local/bin/python && \
28+
ln -s /opt/python3/bin/pip3.8 /usr/bin/pip3.8 && \
29+
ln -s /usr/bin/pip3.8 /usr/bin/pip3 && \
30+
ln -s /usr/bin/pip3 /usr/bin/pip && \
31+
cd .. && \
32+
rm Python-3.8.13.tar.xz && \
33+
rm -rf Python-3.8.13
34+
35+
RUN curl -L https://github.com/llvm/llvm-project/releases/download/llvmorg-9.0.1/clang+llvm-9.0.1-aarch64-linux-gnu.tar.xz \
36+
-o /root/clang+llvm-9.0.1-aarch64-linux-gnu.tar.xz && \
37+
tar xJvf /root/clang+llvm-9.0.1-aarch64-linux-gnu.tar.xz -C /root/ && \
38+
mv /root/clang+llvm-9.0.1-aarch64-linux-gnu /root/clang-llvm-9.0.1 \
39+
&& rm -f /root/clang+llvm-9.0.1-aarch64-linux-gnu.tar.xz
40+
41+
RUN python3 -m venv $VIRTUAL_ENV
42+
ENV PATH="$VIRTUAL_ENV/bin:/root/clang-llvm-9.0.1/bin:$PATH"
43+
COPY requirements*.txt /data/projects/python/
44+
45+
RUN pip install --upgrade pip && \
46+
sed -i 's/tensorflow-cpu==2.11.1/tensorflow-aarch64==2.11.1/g' requirements.txt && \
47+
sed -i 's/torch==1.13.1+cpu/torch==1.13.1/g' requirements.txt && \
48+
sed -i 's/torchvision==0.14.1+cpu/torchvision==0.14.1/g' requirements.txt && \
49+
sed -i 's/ipcl-python==2.0.0/#ipcl-python==2.0.0/g' requirements.txt && \
50+
pip install --no-cache-dir -r requirements.txt
51+
52+
ENV LD_PRELOAD=/data/projects/python/venv/lib/python3.8/site-packages/scikit_learn.libs/libgomp-d22c30c5.so.1.0.0

docker-build/build.sh

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ set -euxo pipefail
3030
: "${Build_GPU:=0}"
3131
: "${Build_LLM:=0}"
3232
: "${Build_LLM_VERSION:=v1.2.0}"
33+
: "${Platform:=amd64}"
3334

3435
BASE_DIR=$(dirname "$0")
3536
cd $BASE_DIR
@@ -75,11 +76,22 @@ check_fate_dir() {
7576
# echo "Built fate"
7677
# }
7778

79+
# bootstrapDockerBuildx(){
80+
# echo "BOOTSTRAP DOCKER BUILDX TOOLKIT"
81+
# echo "LOGIN IN YOUR DOCKER HUB ACCOUNT: ${PREFIX}"
82+
# docker login -u ${PREFIX}
83+
# docker buildx create --driver docker-container --platform "linux/amd64,linux/arm64" --name cross --node cross --use --bootstrap
84+
# echo "FINSH BOOTSTRAP DOCKER BUILDX TOOLKIT"
85+
# }
86+
7887
buildBase() {
88+
# bootstrapDockerBuildx
7989
echo "START BUILDING BASE IMAGE"
8090
#cd ${WORKING_DIR}
81-
docker build --build-arg version=${version} -f ${WORKING_DIR}/base/basic/Dockerfile \
91+
docker build --platform linux/${Platform} --build-arg version=${version} -f ${WORKING_DIR}/base/basic/Dockerfile.${Platform} \
8292
-t ${PREFIX}/base-image:${BASE_TAG} ${PACKAGE_DIR_CACHE}
93+
# docker build --build-arg version=${version} -f ${WORKING_DIR}/base/basic/Dockerfile \
94+
# -t ${PREFIX}/base-image:${BASE_TAG} ${PACKAGE_DIR_CACHE}
8395
echo "FINISH BUILDING BASE IMAGE"
8496
}
8597

@@ -89,19 +101,19 @@ buildEggrollBasicCPU() {
89101
echo "START BUILDING Eggroll Module IMAGE"
90102

91103
echo "### START BUILDING fateflow ###"
92-
docker build --build-arg PREFIX=${PREFIX} --build-arg BASE_IMAGE=base-image --build-arg BASE_TAG=${BASE_TAG} ${Docker_Options} -t ${PREFIX}/fateflow:${TAG} \
104+
docker build --platform linux/${Platform} --build-arg PREFIX=${PREFIX} --build-arg BASE_IMAGE=base-image --build-arg BASE_TAG=${BASE_TAG} ${Docker_Options} -t ${PREFIX}/fateflow:${TAG} \
93105
-f ${WORKING_DIR}/modules/fateflow/Dockerfile ${PACKAGE_DIR_CACHE}
94106
echo "### FINISH BUILDING fateflow ###"
95107
echo ""
96108
echo "### START BUILDING fateboard ###"
97-
docker build --build-arg PREFIX=${PREFIX} --build-arg BASE_TAG=${BASE_TAG} ${Docker_Options} -t ${PREFIX}/fateboard:${TAG} \
98-
-f ${WORKING_DIR}/modules/fateboard/Dockerfile ${PACKAGE_DIR_CACHE}
109+
docker build --platform linux/${Platform} --build-arg PREFIX=${PREFIX} --build-arg BASE_TAG=${BASE_TAG} ${Docker_Options} -t ${PREFIX}/fateboard:${TAG} \
110+
-f ${WORKING_DIR}/modules/fateboard/Dockerfile.${Platform} ${PACKAGE_DIR_CACHE}
99111
echo "### FINISH BUILDING fateboard ###"
100112
echo ""
101113

102114
echo "### START BUILDING eggroll ###"
103-
docker build --build-arg PREFIX=${PREFIX} --build-arg BASE_IMAGE=base-image --build-arg BASE_TAG=${BASE_TAG} ${Docker_Options} -t ${PREFIX}/eggroll:${TAG} \
104-
-f ${WORKING_DIR}/modules/eggroll/Dockerfile ${PACKAGE_DIR_CACHE}
115+
docker build --platform linux/${Platform} --build-arg PREFIX=${PREFIX} --build-arg BASE_IMAGE=base-image --build-arg BASE_TAG=${BASE_TAG} ${Docker_Options} -t ${PREFIX}/eggroll:${TAG} \
116+
-f ${WORKING_DIR}/modules/eggroll/Dockerfile.${Platform} ${PACKAGE_DIR_CACHE}
105117
echo "### FINISH BUILDING eggroll ###"
106118
echo ""
107119

@@ -111,7 +123,6 @@ buildEggrollBasicCPU() {
111123
buildSparkBasicCPU(){
112124
echo "START BUILDING Spark Module IMAGE"
113125

114-
115126
echo "### START BUILDING fateflow-spark ###"
116127
docker build --build-arg PREFIX=${PREFIX} --build-arg BASE_IMAGE=fateflow --build-arg BASE_TAG=${BASE_TAG} ${Docker_Options} -t ${PREFIX}/fateflow-spark:${TAG} -f ${WORKING_DIR}/modules/fateflow-spark/Dockerfile ${WORKING_DIR}/modules/fateflow-spark/
117128
echo "### FINISH BUILDING fateflow-spark ###"

docker-build/build_docker.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ packaging_fateboard() {
108108
fateboard_version=$(grep -E -m 1 -o "<version>(.*)</version>" ./pom.xml | tr -d '[\\-a-z<>//]' | awk -F "version" '{print $2}')
109109
echo "[INFO] fateboard version "${fateboard_version}
110110

111-
docker run --rm -u $(id -u):$(id -g) -v ${source_dir}/fateboard:/data/projects/fate/fateboard --entrypoint="" maven:3.8-jdk-8 /bin/bash -c "cd /data/projects/fate/fateboard && mvn clean package -DskipTests"
111+
docker run --rm --platform linux/amd64 -v ${source_dir}/fateboard:/data/projects/fate/fateboard --entrypoint="" maven:3.8-jdk-8 /bin/bash -c "cd /data/projects/fate/fateboard && mvn clean package -DskipTests"
112112
mkdir -p ${package_dir}/fateboard/conf
113113
mkdir -p ${package_dir}/fateboard/ssh
114114
cp ./target/fateboard-${fateboard_version}.jar ${package_dir}/fateboard/
@@ -125,7 +125,7 @@ packaging_eggroll() {
125125
pull_eggroll
126126
cd ./eggroll
127127
cd ./deploy
128-
docker run --rm -u $(id -u):$(id -g) -v ${source_dir}/eggroll:/data/projects/fate/eggroll --entrypoint="" maven:3.8-jdk-8 /bin/bash -c "cd /data/projects/fate/eggroll/deploy && bash auto-packaging.sh"
128+
docker run --rm --platform linux/amd64 -v ${source_dir}/eggroll:/data/projects/fate/eggroll --entrypoint="" maven:3.8-jdk-8 /bin/bash -c "cd /data/projects/fate/eggroll/deploy && bash auto-packaging.sh"
129129
mkdir -p ${package_dir}/eggroll
130130
mv ${source_dir}/eggroll/eggroll.tar.gz ${package_dir}/eggroll/
131131
cd ${package_dir}/eggroll/
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
ARG PREFIX=prefix
2+
ARG BASE_TAG=tag
3+
ARG BASE_IMAGE=image
4+
FROM ${PREFIX}/${BASE_IMAGE}:${BASE_TAG} as builder
5+
WORKDIR /data/projects/fate/
6+
COPY eggroll.tar.gz .
7+
COPY fate.tar.gz .
8+
COPY conf.tar.gz .
9+
COPY fateflow.tar.gz .
10+
COPY fate.env .
11+
RUN tar -xzf eggroll.tar.gz; \
12+
tar -xzf fate.tar.gz; \
13+
tar -xzf conf.tar.gz; \
14+
tar -xzf fateflow.tar.gz;
15+
16+
RUN ls -l
17+
18+
FROM ${PREFIX}/${BASE_IMAGE}:${BASE_TAG}
19+
20+
RUN apt-get update && \
21+
apt-get install -y openjdk-8-jdk && \
22+
apt-get clean && \
23+
rm -rf /var/lib/apt/lists/*
24+
25+
WORKDIR /data/projects/fate/eggroll/
26+
27+
COPY --from=builder /data/projects/fate/eggroll /data/projects/fate/eggroll
28+
COPY --from=builder /data/projects/fate/fate /data/projects/fate/fate
29+
COPY --from=builder /data/projects/fate/fateflow /data/projects/fate/fateflow
30+
COPY --from=builder /data/projects/fate/conf /data/projects/fate/conf
31+
COPY --from=builder /data/projects/fate/fate.env /data/projects/fate/
32+
33+
ENV PYTHONPATH=/data/projects/fate/fate/python:/data/projects/fate/eggroll/python:/data/projects/fate/fateflow/python
34+
ENV EGGROLL_HOME=/data/projects/fate/eggroll/
35+
36+
ENV TINI_VERSION v0.18.0
37+
ADD https://github.com/krallin/tini/releases/download/${TINI_VERSION}/tini-arm64 /tini
38+
RUN chmod +x /tini
39+
ENTRYPOINT ["/tini", "--"]

0 commit comments

Comments
 (0)