Switch to multi-staged build

Fixes #9
This commit is contained in:
Alexander Hofbauer 2021-02-15 21:23:46 +01:00
parent a6e7e5dc2a
commit 4418f05958
No known key found for this signature in database
GPG key ID: 6421CE3D34E74BA1

View file

@ -1,47 +1,66 @@
## Build stage
ARG product_version=6.1.0 ARG product_version=6.1.0
ARG build_number=83 ARG build_number=83
ARG oo_root='/var/www/onlyoffice/documentserver'
FROM onlyoffice/documentserver:${product_version}.${build_number} FROM onlyoffice/documentserver:${product_version}.${build_number} as build-stage
ARG product_version ARG product_version
ARG build_number ARG build_number
ARG oo_root
ENV PRODUCT_VERSION=${product_version}
ENV BUILD_NUMBER=${build_number}
# Mobile apps patching
ARG me_search='isSupportEditFeature:function(){return!1}'
ARG me_patch='s/isSupportEditFeature:function(){return!1}/isSupportEditFeature:function(){return true}/g'
RUN grep -q "${me_search}" ${oo_root}/web-apps/apps/documenteditor/mobile/app.js \
&& sed -si "${me_patch}" ${oo_root}/web-apps/apps/documenteditor/mobile/app.js
RUN grep -q "${me_search}" ${oo_root}/web-apps/apps/presentationeditor/mobile/app.js \
&& sed -si "${me_patch}" ${oo_root}/web-apps/apps/presentationeditor/mobile/app.js
RUN grep -q "${me_search}" ${oo_root}/web-apps/apps/spreadsheeteditor/mobile/app.js \
&& sed -si "${me_patch}" ${oo_root}/web-apps/apps/spreadsheeteditor/mobile/app.js
RUN sed -si \ # Rebuild with license checks replaced
's/isSupportEditFeature:function(){return!1}/isSupportEditFeature:function(){return true}/g' \
/var/www/onlyoffice/documentserver/web-apps/apps/documenteditor/mobile/app.js \
/var/www/onlyoffice/documentserver/web-apps/apps/presentationeditor/mobile/app.js \
/var/www/onlyoffice/documentserver/web-apps/apps/spreadsheeteditor/mobile/app.js
ARG build_deps="git make g++ nodejs npm" ARG build_deps="git make g++ nodejs npm"
RUN apt-get update && apt-get install -y ${build_deps} RUN apt-get update && apt-get install -y ${build_deps}
ARG tag=v${product_version}.${build_number} ARG tag=v${product_version}.${build_number}
RUN mkdir /build \ RUN mkdir /build \
&& git clone --quiet --branch $tag --depth 1 https://github.com/ONLYOFFICE/build_tools.git /build/build_tools \ && git clone --quiet --branch $tag --depth 1 https://github.com/ONLYOFFICE/build_tools.git /build/build_tools \
&& git clone --quiet --branch $tag --depth 1 https://github.com/ONLYOFFICE/server.git /build/server && git clone --quiet --branch $tag --depth 1 https://github.com/ONLYOFFICE/server.git /build/server
COPY license.patch /build/
WORKDIR /build/server WORKDIR /build/server
ENV PRODUCT_VERSION=${product_version} RUN npm install -g pkg grunt grunt-cli
ENV BUILD_NUMBER=${build_number}
RUN npm install -g pkg grunt grunt-cli \ COPY license.patch /build/
&& git apply /build/license.patch \ RUN git apply /build/license.patch
&& make \
RUN make \
&& pkg /build/build_tools/out/linux_64/onlyoffice/documentserver/server/FileConverter --targets=node10-linux -o /build/converter \ && pkg /build/build_tools/out/linux_64/onlyoffice/documentserver/server/FileConverter --targets=node10-linux -o /build/converter \
&& pkg /build/build_tools/out/linux_64/onlyoffice/documentserver/server/DocService --targets=node10-linux --options max_old_space_size=4096 -o /build/docservice \ && pkg /build/build_tools/out/linux_64/onlyoffice/documentserver/server/DocService --targets=node10-linux --options max_old_space_size=4096 -o /build/docservice \
&& cp /build/converter /var/www/onlyoffice/documentserver/server/FileConverter/converter \ && cp /build/converter ${oo_root}/server/FileConverter/converter \
&& cp /build/docservice /var/www/onlyoffice/documentserver/server/DocService/docservice && cp /build/docservice ${oo_root}/server/DocService/docservice
WORKDIR /
RUN npm uninstall -g pkg grunt grunt-cli \ ## Prod image
&& apt-get purge -y --autoremove ${build_deps} \ FROM onlyoffice/documentserver:${product_version}.${build_number}
&& apt-get clean \ ARG oo_root
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* \
&& rm -rf /root/.cache /root/.config/ /root/.npm/ /root/.pkg-cache \ COPY --from=build-stage ${oo_root}/web-apps/apps/documenteditor/mobile/app.js \
&& rm -rf /build ${oo_root}/web-apps/apps/documenteditor/mobile/app.js
COPY --from=build-stage ${oo_root}/web-apps/apps/presentationeditor/mobile/app.js \
${oo_root}/web-apps/apps/presentationeditor/mobile/app.js
COPY --from=build-stage ${oo_root}/web-apps/apps/spreadsheeteditor/mobile/app.js \
${oo_root}/web-apps/apps/spreadsheeteditor/mobile/app.js
COPY --from=build-stage ${oo_root}/server/FileConverter/converter \
${oo_root}/server/FileConverter/converter
COPY --from=build-stage ${oo_root}/server/DocService/docservice \
${oo_root}/server/DocService/docservice