Merge pull request #581 from wayne-cheng/optimize-dockerfile

优化Dockerfile,支持真正的跨平台构建镜像
pull/307/head
陈精华 3 months ago committed by GitHub
commit 782509376c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -1,38 +1,31 @@
FROM ubuntu:20.04 FROM ubuntu:24.04
MAINTAINER chenjh "842761733@qq.com"
# 内置一些常用的中文字体,避免普遍性乱码 RUN sed -i 's@//.*archive.ubuntu.com@//mirrors.aliyun.com@g' /etc/apt/sources.list.d/ubuntu.sources &&\
COPY fonts/* /usr/share/fonts/chinese/ sed -i 's@//security.ubuntu.com@//mirrors.aliyun.com@g' /etc/apt/sources.list.d/ubuntu.sources &&\
RUN apt-get clean && apt-get update &&\ sed -i 's@//ports.ubuntu.com@//mirrors.aliyun.com@g' /etc/apt/sources.list.d/ubuntu.sources &&\
sed -i 's/http:\/\/archive.ubuntu.com/https:\/\/mirrors.aliyun.com/g' /etc/apt/sources.list &&\ apt-get update &&\
sed -i 's/# deb/deb/g' /etc/apt/sources.list &&\
apt-get install -y --reinstall ca-certificates &&\
apt-get clean && apt-get update &&\
apt-get install -y locales language-pack-zh-hans &&\
localedef -i zh_CN -c -f UTF-8 -A /usr/share/locale/locale.alias zh_CN.UTF-8 && locale-gen zh_CN.UTF-8 &&\
export DEBIAN_FRONTEND=noninteractive &&\ export DEBIAN_FRONTEND=noninteractive &&\
apt-get install -y tzdata && ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime &&\ apt-get install -y --no-install-recommends openjdk-8-jre tzdata locales xfonts-utils fontconfig libreoffice-nogui &&\
apt-get install -y fontconfig ttf-mscorefonts-installer ttf-wqy-microhei ttf-wqy-zenhei xfonts-wqy &&\ echo 'Asia/Shanghai' > /etc/timezone &&\
apt-get install -y wget &&\ ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime &&\
cd /tmp &&\ localedef -i zh_CN -c -f UTF-8 -A /usr/share/locale/locale.alias zh_CN.UTF-8 &&\
wget https://kkview.cn/resource/server-jre-8u251-linux-x64.tar.gz &&\ locale-gen zh_CN.UTF-8 &&\
tar -zxf /tmp/server-jre-8u251-linux-x64.tar.gz && mv /tmp/jdk1.8.0_251 /usr/local/ &&\ # 安装微软字体
# apt-get install -y --no-install-recommends ttf-mscorefonts-installer &&\
# 安装文泉驿字体
# apt-get install -y --no-install-recommends ttf-wqy-microhei ttf-wqy-zenhei xfonts-wqy &&\
# 清理临时文件
apt-get autoremove -y &&\
apt-get clean &&\
rm -rf /var/lib/apt/lists/*
# 安装 libreoffice # 内置一些常用的中文字体,避免普遍性乱码. 建议安装思源字体 https://zh-cn.libreoffice.org/download/fonts/
apt-get install -y libxrender1 libxinerama1 libxt6 libxext-dev libfreetype6-dev libcairo2 libcups2 libx11-xcb1 libnss3 &&\ ADD fonts/* /usr/share/fonts/chinese/
wget https://downloadarchive.documentfoundation.org/libreoffice/old/7.5.3.2/deb/x86_64/LibreOffice_7.5.3.2_Linux_x86-64_deb.tar.gz -cO libreoffice_deb.tar.gz &&\
tar -zxf /tmp/libreoffice_deb.tar.gz && cd /tmp/LibreOffice_7.5.3.2_Linux_x86-64_deb/DEBS &&\
dpkg -i *.deb &&\
# 清理临时文件 RUN cd /usr/share/fonts/chinese &&\
rm -rf /tmp/* && rm -rf /var/lib/apt/lists/* &&\ # 安装字体
cd /usr/share/fonts/chinese &&\
mkfontscale &&\ mkfontscale &&\
mkfontdir &&\ mkfontdir &&\
fc-cache -fv fc-cache -fv
ENV JAVA_HOME /usr/local/jdk1.8.0_251 ENV LANG=zh_CN.UTF-8 LC_ALL=zh_CN.UTF-8
ENV CLASSPATH $JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
ENV PATH $PATH:$JAVA_HOME/bin
ENV LANG zh_CN.UTF-8
ENV LC_ALL zh_CN.UTF-8
CMD ["/bin/bash"]

@ -1,77 +0,0 @@
FROM arm64v8/ubuntu:20.04
MAINTAINER chenjh "842761733@qq.com"
# 内置一些常用的中文字体,避免普遍性乱码
COPY fonts/* /usr/share/fonts/chinese/
RUN apt-get clean && apt-get update &&\
sed -i 's/http:\/\/archive.ubuntu.com/https:\/\/mirrors.aliyun.com/g' /etc/apt/sources.list &&\
sed -i 's/# deb/deb/g' /etc/apt/sources.list &&\
apt-get install -y --reinstall ca-certificates &&\
apt-get clean && apt-get update &&\
apt-get install -y locales language-pack-zh-hans &&\
localedef -i zh_CN -c -f UTF-8 -A /usr/share/locale/locale.alias zh_CN.UTF-8 && locale-gen zh_CN.UTF-8 &&\
export DEBIAN_FRONTEND=noninteractive &&\
apt-get install -y tzdata && ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime &&\
apt-get install -y fontconfig ttf-mscorefonts-installer ttf-wqy-microhei ttf-wqy-zenhei xfonts-wqy &&\
apt-get install -y wget
# 安装 arm64-jre8
RUN apt-get install -y openjdk-8-jre
# 编译 libreoffice
RUN apt-get install -y git build-essential zip ccache junit4 libkrb5-dev nasm graphviz python3 python3-dev qtbase5-dev libkf5coreaddons-dev libkf5i18n-dev libkf5config-dev libkf5windowsystem-dev libkf5kio-dev autoconf libcups2-dev libfontconfig1-dev gperf default-jdk doxygen libxslt1-dev xsltproc libxml2-utils libxrandr-dev libx11-dev bison flex libgtk-3-dev libgstreamer-plugins-base1.0-dev libgstreamer1.0-dev ant ant-optional libnss3-dev libavahi-client-dev libxt-dev &&\
# 安装 ccache重复编译时加快速度
apt-get install ccache &&\
ccache -M 10G &&\
# clone主代码
mkdir /opt/libreoffice
WORKDIR /opt/libreoffice
RUN git clone --depth=1 --branch libreoffice-7-5 git://go.suokunlong.cn/lo/core ./libreoffice-7-5
# 配置&抓取子模块
WORKDIR /opt/libreoffice/libreoffice-7-5
RUN git submodule init &&\
git config --unset-all submodule.dictionaries.active &&\
git config --unset-all submodule.dictionaries.url &&\
git config --unset-all submodule.helpcontent2.active &&\
git config --unset-all submodule.helpcontent2.url &&\
git submodule update --progress --depth=1 &&\
# 下载第三方依赖
mkdir -p /opt/libreoffice/ext &&\
wget --recursive --no-parent --no-check-certificate -P /opt/libreoffice/ext https://go.suokunlong.cn:88/dl/libreoffice/external_tarballs/
RUN mv /opt/libreoffice/ext/go.suokunlong.cn:88/dl/libreoffice/external_tarballs/* /opt/libreoffice/ext
# 配置编译选项
RUN cat << EOF > autogen.input \
&& echo "--without-help" >> autogen.input \
&& echo "--without-helppack-integration" >> autogen.input \
&& echo "--with-lang=zh-CN zh-TW" >> autogen.input \
&& echo "--disable-online-update" >> autogen.input \
&& echo "--disable-breakpad" >> autogen.input \
&& echo "--disable-odk" >> autogen.input \
&& echo "--without-doxygen" >> autogen.input \
&& echo "--with-external-tar=/opt/libreoffice/ext" >> autogen.input \
&& echo "--without-java" >> autogen.input \
&& echo "--enable-firebird-sdbc" >> autogen.input \
&& echo "--without-system-firebird" >> autogen.input \
&& echo "--enable-python=internal" >> autogen.input
# 预编译
RUN ./autogen.sh
# 因为libreoffice的安全策略不允许root用户执行编译操作可以改Makefile文件解决所以新建用户
RUN useradd libreoffice
# 切换用户
RUN su libreoffice
# 在普通用户下编译
RUN make || true
# !!!编译40分钟左右会报错此时需要执行以下操作重新编译
RUN cp ./workdir/UnpackedTarball/python3/build/lib.linux-aarch64-3.8/_sysconfigdata__linux_aarch64-linux-gnu.py ./workdir/UnpackedTarball/python3/build/lib.linux-aarch64-3.8/_sysconfigdata__linux_aarch64-unknown-linux-gnu.py
# 重新编译
RUN make &&\
make install
RUN ln -s /usr/local/lib/libreoffice/program/soffice /usr/bin/libreoffice
# 清理临时文件
RUN rm -rf /tmp/* && rm -rf /var/lib/apt/lists/* &&\
cd /usr/share/fonts/chinese &&\
mkfontscale &&\
mkfontdir &&\
fc-cache -fv
ENV LANG zh_CN.UTF-8
ENV LC_ALL zh_CN.UTF-8
CMD ["/bin/bash"]

@ -0,0 +1,50 @@
#
kkfileview kkfileview Docker
kkfileview kkfileview-jdk
使 kkfileview-jdk kkfileview docker
> tag 4.4.0 Dockerfile arm64 , arm64
```shell
docker build --tag keking/kkfileview-jdk:4.4.0 .
```
##
`docker buildx` 使
`docker buildx build` `--platform=linux/arm64` arm64 便arm64 arm64
> linux/amd64 linux/arm64
> buildx builder driver 使 `docker` , 使 `docker-container` , , [Docker Buildx | Docker Documentation](https://docs.docker.com/buildx/working-with-buildx/#build-multi-platform-images)
****
amd64 (x86_64) docker buildx Linux QEMU
> 使 WSL2 Windows DockerDesktop, ,
1. docker buildx
> docker >=19.03
, https://github.com/docker/buildx
2. QEMU , :
> Linux >=4.8
使 `tonistiigi/binfmt` :
```shell
docker run --privileged --rm tonistiigi/binfmt --install all
```
:
```shell
docker buildx build --platform=linux/amd64,linux/arm64 -t keking/kkfileview-jdk:4.4.0 --push .
```

@ -0,0 +1,53 @@
# Build Instructions
Since the base runtime environment for kkfileview rarely changes and takes a long time to build, while the kkfileview code itself is frequently updated, the process of building its Docker image is split into two steps:
First, create the base image for kkfileview (kkfileview-jdk).
Then, use kkfileview-jdk as the base image to build and speed up the kkfileview Docker image build and release process.
To build the base image, run the following command:
> In this example, the image tag is 4.4.0. The Dockerfile maintained in this project considers cross-platform compatibility. If you need an arm64 architecture image, run the same build command on an arm64 architecture machine.
```shell
docker build --tag keking/kkfileview-jdk:4.4.0 .
```
## Cross-Platform Build
`docker buildx` supports building images for multiple platform architectures on a single machine. It is recommended to use this capability for cross-platform image builds.
For example, adding the `--platform=linux/arm64` parameter when executing the `docker buildx build` command will allow you to build an arm64 architecture image. This is particularly convenient for users who want to build arm64 images but don't have an arm64 machine.
> Currently, this project only supports building images for the linux/amd64 and linux/arm64 architectures.
> The buildx builder driver can use the default `docker` type, but if you use the `docker-container` type, you can build multiple architectures in parallel. This README will not cover that in detail, you can learn more on your own. Refer to [Docker Buildx | Docker Documentation](https://docs.docker.com/buildx/working-with-buildx/#build-multi-platform-images)
**Prerequisites**
Assuming the current machine is amd64 (x86_64) architecture, you'll need to enable the docker buildx feature and enable Linux QEMU user mode:
> Windows users with WSL2 who have installed a recent version of Docker Desktop will already meet these prerequisites, so no additional setup is required.
1. Install the docker buildx client plugin:
> Docker version >=19.03 is required.
If it's already installed, you can skip this step. For more details, refer to https://github.com/docker/buildx.
2. Enable QEMU user mode and install emulators for other platforms:
> Linux kernel version >=4.8 is required.
You can quickly enable and install emulators using the tonistiigi/binfmt image by running the following command:
```shell
docker run --privileged --rm tonistiigi/binfmt --install all
```
Now you can enjoy the building. Heres an example build command:
```shell
docker buildx build --platform=linux/amd64,linux/arm64 -t keking/kkfileview-jdk:4.4.0 --push .
```

@ -1,5 +0,0 @@
# kkfileview docker
docker build --tag keking/kkfileview-jdk:4.3.0 .
# arm64
docker build -f Dockerfile_arm64 --tag keking/kkfileview-jdk:4.3.0 .
Loading…
Cancel
Save