From b6f48111e339ebe8964aae0997cabed313fe162b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=90=B4=E5=B0=8F=E7=99=BD?= <296015668@qq.com> Date: Mon, 13 May 2024 18:21:51 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=9B=B4=E6=96=B0=20Dockerfile?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Dockerfile | 19 +++++++++++++++---- Dockerfile-ee | 19 +++++++++++++++---- 2 files changed, 30 insertions(+), 8 deletions(-) diff --git a/Dockerfile b/Dockerfile index 0ad36ffd7..f1a637230 100644 --- a/Dockerfile +++ b/Dockerfile @@ -41,7 +41,10 @@ ENV VERSION=$VERSION WORKDIR /opt/jumpserver ADD . . RUN echo > /opt/jumpserver/config.yml \ - && cd utils && bash -ixeu build.sh + && \ + if [ -n "${VERSION}" ]; then \ + sed -i "s@VERSION = .*@VERSION = '${VERSION}'@g" apps/jumpserver/const.py; \ + fi FROM python:3.11-slim-bullseye as stage-2 ARG TARGETARCH @@ -53,6 +56,7 @@ ARG BUILD_DEPENDENCIES=" \ ARG DEPENDENCIES=" \ freetds-dev \ + gettext \ libffi-dev \ libjpeg-dev \ libkrb5-dev \ @@ -104,6 +108,14 @@ RUN --mount=type=cache,target=/root/.cache,sharing=locked \ && . /opt/py3/bin/activate \ && poetry install --only=main +COPY --from=stage-1 /opt/jumpserver /opt/jumpserver + +RUN set -ex \ + && export SECRET_KEY=$(head -c100 < /dev/urandom | base64 | tr -dc A-Za-z0-9 | head -c 48) \ + && . /opt/py3/bin/activate \ + && cd apps \ + && python manage.py compilemessages + FROM python:3.11-slim-bullseye ARG TARGETARCH ENV LANG=en_US.UTF-8 \ @@ -138,10 +150,9 @@ RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \ && sed -i "s@# export @export @g" ~/.bashrc \ && sed -i "s@# alias @alias @g" ~/.bashrc -COPY --from=stage-2 /opt/py3 /opt/py3 +COPY --from=stage-2 /opt /opt COPY --from=stage-1 /usr/local/bin /usr/local/bin -COPY --from=stage-1 /opt/jumpserver/release/jumpserver /opt/jumpserver -COPY --from=stage-1 /opt/jumpserver/release/jumpserver/apps/libs/ansible/ansible.cfg /etc/ansible/ +COPY --from=stage-1 /opt/jumpserver/apps/libs/ansible/ansible.cfg /etc/ansible/ WORKDIR /opt/jumpserver diff --git a/Dockerfile-ee b/Dockerfile-ee index 0c5aec4d4..cb6958062 100644 --- a/Dockerfile-ee +++ b/Dockerfile-ee @@ -46,7 +46,10 @@ ADD . . COPY --from=build-xpack /opt/xpack /opt/jumpserver/apps/xpack RUN echo > /opt/jumpserver/config.yml \ - && cd utils && bash -ixeu build.sh + && \ + if [ -n "${VERSION}" ]; then \ + sed -i "s@VERSION = .*@VERSION = '${VERSION}'@g" apps/jumpserver/const.py; \ + fi FROM python:3.11-slim-bullseye as stage-2 ARG TARGETARCH @@ -58,6 +61,7 @@ ARG BUILD_DEPENDENCIES=" \ ARG DEPENDENCIES=" \ freetds-dev \ + gettext \ libffi-dev \ libjpeg-dev \ libkrb5-dev \ @@ -109,6 +113,14 @@ RUN --mount=type=cache,target=/root/.cache,sharing=locked \ && . /opt/py3/bin/activate \ && poetry install +COPY --from=stage-1 /opt/jumpserver /opt/jumpserver + +RUN set -ex \ + && export SECRET_KEY=$(head -c100 < /dev/urandom | base64 | tr -dc A-Za-z0-9 | head -c 48) \ + && . /opt/py3/bin/activate \ + && cd apps \ + && python manage.py compilemessages + FROM python:3.11-slim-bullseye ARG TARGETARCH ENV LANG=zh_CN.UTF-8 \ @@ -154,10 +166,9 @@ RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \ && sed -i "s@# export @export @g" ~/.bashrc \ && sed -i "s@# alias @alias @g" ~/.bashrc -COPY --from=stage-2 /opt/py3 /opt/py3 +COPY --from=stage-2 /opt /opt COPY --from=stage-1 /usr/local/bin /usr/local/bin -COPY --from=stage-1 /opt/jumpserver/release/jumpserver /opt/jumpserver -COPY --from=stage-1 /opt/jumpserver/release/jumpserver/apps/libs/ansible/ansible.cfg /etc/ansible/ +COPY --from=stage-1 /opt/jumpserver/apps/libs/ansible/ansible.cfg /etc/ansible/ WORKDIR /opt/jumpserver