From edc0797f6b458771c3a8e865b50468b67e20f530 Mon Sep 17 00:00:00 2001 From: Vitalij Zadneprovskij Date: Thu, 23 Dec 2021 20:19:53 +0100 Subject: [PATCH 1/2] Multi-stage docker build + updated Rust image version --- Dockerfile | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/Dockerfile b/Dockerfile index baf62dd..a6ce10c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,19 +1,25 @@ -FROM rust:1.26.2-slim-stretch +ARG APP_HOME=/opt/whitebox -ENV APP_HOME /opt/whitebox +# Build stage +FROM rust:1.57.0-slim-buster as builder +ARG APP_HOME RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get -y --no-install-recommends install \ python3 \ python3-pip \ git && \ - rm -rf /var/lib/apt/lists/* && \ - useradd -ms /bin/bash -r -d ${APP_HOME} gis - + rm -rf /var/lib/apt/lists/* + RUN git clone https://github.com/jblindsay/whitebox-tools.git ${APP_HOME}/whitebox && \ cd ${APP_HOME}/whitebox && \ - cargo build --release && \ - mv target/release/whitebox_tools /usr/local/bin + cargo build --release -ENV PYTHONPATH "$PYTHONPATH:/opt/whitebox" +# Prod stage +FROM debian:buster-slim +ARG APP_HOME +COPY --from=builder ${APP_HOME}/whitebox/target/release/whitebox_tools /usr/local/bin +COPY --from=builder ${APP_HOME}/whitebox/whitebox_tools.py ${APP_HOME}/whitebox/whitebox_tools.py +RUN useradd -ms /bin/bash -r -d ${APP_HOME} gis +ENV PYTHONPATH "$PYTHONPATH:${APP_HOME}" USER gis WORKDIR ${APP_HOME} CMD ["whitebox_tools"] From 4befc49ba123221693586be2252e2841481547ed Mon Sep 17 00:00:00 2001 From: Vitalij Zadneprovskij Date: Thu, 23 Dec 2021 20:34:45 +0100 Subject: [PATCH 2/2] Fixed the Python path --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index a6ce10c..3b3b45f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -19,7 +19,7 @@ ARG APP_HOME COPY --from=builder ${APP_HOME}/whitebox/target/release/whitebox_tools /usr/local/bin COPY --from=builder ${APP_HOME}/whitebox/whitebox_tools.py ${APP_HOME}/whitebox/whitebox_tools.py RUN useradd -ms /bin/bash -r -d ${APP_HOME} gis -ENV PYTHONPATH "$PYTHONPATH:${APP_HOME}" +ENV PYTHONPATH "$PYTHONPATH:${APP_HOME}/whitebox" USER gis WORKDIR ${APP_HOME} CMD ["whitebox_tools"]