do multi-stage build

This commit is contained in:
Syping 2024-02-27 09:20:23 +01:00
parent 0c3e973a09
commit 1aedf12cfe

View file

@ -1,22 +1,22 @@
FROM almalinux:9 FROM almalinux:9 AS build
ARG DPP_COMMIT=9ccd5db6171862f85c481974a6b3acd6d3ae6741 ARG DPP_COMMIT=9ccd5db6171862f85c481974a6b3acd6d3ae6741
ARG DTB_COMMIT=7dcb64f7cf0244dac75b56d8e36dcceb1d683fde ARG DTB_COMMIT=912ac1eced6ae7762fdae0298137e69ff1566151
RUN dnf install -y python3 python3-requests && \ # Install build dependencies
dnf clean all RUN dnf install -y yum-utils && \
RUN dnf install -y python3-pip && \ dnf config-manager --set-enabled crb
dnf clean all && \ RUN dnf install -y cmake clang git ninja-build openssl-devel openssl-libs python3-pip zlib zlib-devel yum-utils
mkdir -p /opt/libretranslate && \
# Install LibreTranslate in virtual environment
RUN mkdir -p /opt/libretranslate && \
python3 -m venv /opt/libretranslate && \ python3 -m venv /opt/libretranslate && \
source /opt/libretranslate/bin/activate && \ source /opt/libretranslate/bin/activate && \
pip3 install libretranslate==1.5.5 \ pip3 install libretranslate==1.5.5 \
--extra-index-url https://download.pytorch.org/whl/cpu && \ --extra-index-url https://download.pytorch.org/whl/cpu
dnf remove -y python3-pip
RUN dnf install -y yum-utils && \ # Build libdpp and dtranslatebot
dnf config-manager --set-enabled crb && \ RUN mkdir -p /root/src && \
dnf install -y cmake clang git ninja-build openssl-devel openssl-libs zlib zlib-devel && \
mkdir -p /root/src && \
cd /root/src && \ cd /root/src && \
git clone https://github.com/brainboxdotcc/DPP.git dpp && \ git clone https://github.com/brainboxdotcc/DPP.git dpp && \
cd dpp && \ cd dpp && \
@ -40,14 +40,20 @@ RUN dnf install -y yum-utils && \
-DCMAKE_INSTALL_RPATH=/usr/local/lib64 \ -DCMAKE_INSTALL_RPATH=/usr/local/lib64 \
-GNinja && \ -GNinja && \
cmake --build dtranslatebot-build && \ cmake --build dtranslatebot-build && \
cmake --install dtranslatebot-build && \ cmake --install dtranslatebot-build
cd /root && \
rm -rf \ # Copy built files and dtranslatebot-ltd
/root/src \ RUN mkdir -p /root/destdir/opt && \
/usr/local/include \ mkdir -p /root/destdir/usr/local/bin && \
/usr/local/lib64/cmake \ mkdir -p /root/destdir/usr/local/lib64 && \
/usr/local/lib64/pkgconfig && \ cp -R /opt/libretranslate /root/destdir/opt/ && \
dnf remove -y cmake clang git openssl-devel yum-utils zlib-devel && \ cp /usr/local/bin/dtranslatebot /root/destdir/usr/local/bin/ && \
cp /usr/local/lib64/libdpp.so* /root/destdir/usr/local/lib64/
COPY dtranslatebot-ltd.py /root/destdir/usr/local/bin/dtranslatebot-ltd
# Build the image
FROM almalinux:9
RUN dnf install -y openssl-libs python3-requests zlib && \
dnf clean all dnf clean all
COPY dtranslatebot-ltd.py /usr/local/bin/dtranslatebot-ltd COPY --from=build /root/destdir/ /
ENTRYPOINT ["/usr/local/bin/dtranslatebot-ltd"] ENTRYPOINT ["/usr/local/bin/dtranslatebot-ltd"]