Skip to content

Commit 84976e9

Browse files
authored
feat(dockerfile): add build argument to toggle R support in computing unit images (#3929)
## Summary - Add `WITH_R_SUPPORT` build argument to both `computing-unit-master.dockerfile` and `computing-unit-worker.dockerfile` - Conditionally install R dependencies based on the build flag - Defaults to `false` to reduce image size and build time when R support is not needed ## Related Issue Closes #3928 ## Changes - Added `ARG WITH_R_SUPPORT=false` (default: false for backward compatibility) - Conditionally install R-related system packages (gfortran, libreadline, libxml2, etc.) - Conditionally compile and install R 4.3.3 - Conditionally install R packages (coro, dplyr, arrow) ## Impact **Without R support (default):** - Significantly smaller image size (~500MB+ reduction) - Faster build time (avoids 10+ minute R compilation) - Suitable for deployments that don't use R operators **With R support:** ```bash docker build --build-arg WITH_R_SUPPORT=true -f bin/computing-unit-master.dockerfile . ```
1 parent 2e03207 commit 84976e9

File tree

2 files changed

+100
-37
lines changed

2 files changed

+100
-37
lines changed

bin/computing-unit-master.dockerfile

Lines changed: 41 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -43,19 +43,24 @@ RUN unzip amber/target/universal/amber-*.zip -d amber/target/
4343

4444
FROM eclipse-temurin:11-jdk-jammy AS runtime
4545

46+
# Build argument to enable/disable R support (default: true for backward compatibility)
47+
ARG WITH_R_SUPPORT=false
48+
4649
WORKDIR /texera/amber
4750

4851
COPY --from=build /texera/amber/r-requirements.txt /tmp/r-requirements.txt
4952
COPY --from=build /texera/amber/requirements.txt /tmp/requirements.txt
5053
COPY --from=build /texera/amber/operator-requirements.txt /tmp/operator-requirements.txt
5154

52-
# Install Python & R runtime dependencies
55+
# Install Python runtime dependencies (always) and R runtime dependencies (conditional)
5356
RUN apt-get update && apt-get install -y \
5457
python3-pip \
5558
python3-dev \
5659
libpq-dev \
57-
gfortran \
5860
curl \
61+
unzip \
62+
$(if [ "$WITH_R_SUPPORT" = "true" ]; then echo "\
63+
gfortran \
5964
build-essential \
6065
libreadline-dev \
6166
libncurses-dev \
@@ -66,36 +71,43 @@ RUN apt-get update && apt-get install -y \
6671
liblzma-dev \
6772
libpcre++-dev \
6873
libpango1.0-dev \
69-
libcurl4-openssl-dev \
70-
unzip \
74+
libcurl4-openssl-dev"; fi) \
7175
&& apt-get clean
7276

73-
# Install R and needed libraries
77+
# Install R and needed libraries (conditional)
7478
ENV R_VERSION=4.3.3
75-
RUN curl -O https://cran.r-project.org/src/base/R-4/R-${R_VERSION}.tar.gz && \
76-
tar -xf R-${R_VERSION}.tar.gz && \
77-
cd R-${R_VERSION} && \
78-
./configure --prefix=/usr/local \
79-
--enable-R-shlib \
80-
--with-blas \
81-
--with-lapack && \
82-
make -j 4 && \
83-
make install && \
84-
cd .. && \
85-
rm -rf R-${R_VERSION}* && R --version && pip3 install --upgrade pip setuptools wheel && \
86-
pip3 install -r /tmp/requirements.txt && \
87-
pip3 install -r /tmp/operator-requirements.txt && \
88-
pip3 install -r /tmp/r-requirements.txt
89-
# Install R packages, pinning arrow to 14.0.2.1 explicitly
90-
RUN Rscript -e "options(repos = c(CRAN = 'https://cran.r-project.org')); \
91-
install.packages(c('coro', 'dplyr'), \
92-
Ncpus = parallel::detectCores())" && \
93-
Rscript -e "options(repos = c(CRAN = 'https://cran.r-project.org')); \
94-
if (!requireNamespace('remotes', quietly=TRUE)) \
95-
install.packages('remotes'); \
96-
remotes::install_version('arrow', version='14.0.2.1', \
97-
repos='https://cran.r-project.org', upgrade='never'); \
98-
cat('R arrow version: ', as.character(packageVersion('arrow')), '\n')"
79+
RUN if [ "$WITH_R_SUPPORT" = "true" ]; then \
80+
curl -O https://cran.r-project.org/src/base/R-4/R-${R_VERSION}.tar.gz && \
81+
tar -xf R-${R_VERSION}.tar.gz && \
82+
cd R-${R_VERSION} && \
83+
./configure --prefix=/usr/local \
84+
--enable-R-shlib \
85+
--with-blas \
86+
--with-lapack && \
87+
make -j 4 && \
88+
make install && \
89+
cd .. && \
90+
rm -rf R-${R_VERSION}* && R --version && pip3 install --upgrade pip setuptools wheel && \
91+
pip3 install -r /tmp/requirements.txt && \
92+
pip3 install -r /tmp/operator-requirements.txt && \
93+
pip3 install -r /tmp/r-requirements.txt; \
94+
else \
95+
pip3 install --upgrade pip setuptools wheel && \
96+
pip3 install -r /tmp/requirements.txt && \
97+
pip3 install -r /tmp/operator-requirements.txt; \
98+
fi
99+
# Install R packages, pinning arrow to 14.0.2.1 explicitly (conditional)
100+
RUN if [ "$WITH_R_SUPPORT" = "true" ]; then \
101+
Rscript -e "options(repos = c(CRAN = 'https://cran.r-project.org')); \
102+
install.packages(c('coro', 'dplyr'), \
103+
Ncpus = parallel::detectCores())" && \
104+
Rscript -e "options(repos = c(CRAN = 'https://cran.r-project.org')); \
105+
if (!requireNamespace('remotes', quietly=TRUE)) \
106+
install.packages('remotes'); \
107+
remotes::install_version('arrow', version='14.0.2.1', \
108+
repos='https://cran.r-project.org', upgrade='never'); \
109+
cat('R arrow version: ', as.character(packageVersion('arrow')), '\n')"; \
110+
fi
99111
ENV LD_LIBRARY_PATH=/usr/local/lib/R/lib:$LD_LIBRARY_PATH
100112

101113
# Copy the built texera binary from the build phase

bin/computing-unit-worker.dockerfile

Lines changed: 59 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,25 +43,76 @@ RUN unzip amber/target/universal/amber-*.zip -d amber/target/
4343

4444
FROM eclipse-temurin:11-jre-jammy AS runtime
4545

46+
# Build argument to enable/disable R support (default: false for backward compatibility)
47+
ARG WITH_R_SUPPORT=false
48+
4649
WORKDIR /texera/amber
4750

51+
COPY --from=build /texera/amber/r-requirements.txt /tmp/r-requirements.txt
4852
COPY --from=build /texera/amber/requirements.txt /tmp/requirements.txt
4953
COPY --from=build /texera/amber/operator-requirements.txt /tmp/operator-requirements.txt
5054

51-
# Install Python runtime and dependencies
55+
# Install Python runtime dependencies (always) and R runtime dependencies (conditional)
5256
RUN apt-get update && apt-get install -y \
5357
python3-pip \
5458
python3-dev \
5559
libpq-dev \
60+
$(if [ "$WITH_R_SUPPORT" = "true" ]; then echo "\
61+
gfortran \
62+
curl \
63+
build-essential \
64+
libreadline-dev \
65+
libncurses-dev \
66+
libssl-dev \
67+
libxml2-dev \
68+
xorg-dev \
69+
libbz2-dev \
70+
liblzma-dev \
71+
libpcre++-dev \
72+
libpango1.0-dev \
73+
libcurl4-openssl-dev"; fi) \
5674
&& apt-get clean
5775

58-
RUN pip3 install --upgrade pip setuptools wheel
59-
RUN pip3 install python-lsp-server python-lsp-server[websockets]
60-
61-
# Install requirements with a fallback for wordcloud
62-
RUN pip3 install -r /tmp/requirements.txt
63-
RUN pip3 install --no-cache-dir --find-links https://pypi.org/simple/ -r /tmp/operator-requirements.txt || \
64-
pip3 install --no-cache-dir wordcloud==1.9.2
76+
# Install R and needed libraries (conditional)
77+
ENV R_VERSION=4.3.3
78+
RUN if [ "$WITH_R_SUPPORT" = "true" ]; then \
79+
curl -O https://cran.r-project.org/src/base/R-4/R-${R_VERSION}.tar.gz && \
80+
tar -xf R-${R_VERSION}.tar.gz && \
81+
cd R-${R_VERSION} && \
82+
./configure --prefix=/usr/local \
83+
--enable-R-shlib \
84+
--with-blas \
85+
--with-lapack && \
86+
make -j 4 && \
87+
make install && \
88+
cd .. && \
89+
rm -rf R-${R_VERSION}* && R --version && pip3 install --upgrade pip setuptools wheel && \
90+
pip3 install python-lsp-server python-lsp-server[websockets] && \
91+
pip3 install -r /tmp/requirements.txt && \
92+
pip3 install --no-cache-dir --find-links https://pypi.org/simple/ -r /tmp/operator-requirements.txt || \
93+
pip3 install --no-cache-dir wordcloud==1.9.2 && \
94+
pip3 install -r /tmp/r-requirements.txt; \
95+
else \
96+
pip3 install --upgrade pip setuptools wheel && \
97+
pip3 install python-lsp-server python-lsp-server[websockets] && \
98+
pip3 install -r /tmp/requirements.txt && \
99+
pip3 install --no-cache-dir --find-links https://pypi.org/simple/ -r /tmp/operator-requirements.txt || \
100+
pip3 install --no-cache-dir wordcloud==1.9.2; \
101+
fi
102+
103+
# Install R packages, pinning arrow to 14.0.2.1 explicitly (conditional)
104+
RUN if [ "$WITH_R_SUPPORT" = "true" ]; then \
105+
Rscript -e "options(repos = c(CRAN = 'https://cran.r-project.org')); \
106+
install.packages(c('coro', 'dplyr'), \
107+
Ncpus = parallel::detectCores())" && \
108+
Rscript -e "options(repos = c(CRAN = 'https://cran.r-project.org')); \
109+
if (!requireNamespace('remotes', quietly=TRUE)) \
110+
install.packages('remotes'); \
111+
remotes::install_version('arrow', version='14.0.2.1', \
112+
repos='https://cran.r-project.org', upgrade='never'); \
113+
cat('R arrow version: ', as.character(packageVersion('arrow')), '\n')"; \
114+
fi
115+
ENV LD_LIBRARY_PATH=/usr/local/lib/R/lib:$LD_LIBRARY_PATH
65116

66117
# Copy the built texera binary from the build phase
67118
COPY --from=build /texera/amber/target/amber-* /texera/amber/

0 commit comments

Comments
 (0)