From d9c51eb569fb930bce47f298784cdecebb3e5b8b Mon Sep 17 00:00:00 2001 From: Erick Date: Tue, 30 Jun 2026 13:29:41 +0200 Subject: [PATCH] Fix Docker image: install NatureDataCubeR package The image was built from the package layout but never installed the NatureDataCubeR package itself, so the app crash-looped at startup with "there is no package called 'NatureDataCubeR'" (502 at the proxy). - Dockerfile: COPY the package source and R CMD INSTALL it, so library(NatureDataCubeR) and system.file() (Shiny app in inst/shiny, data in inst/extdata) resolve at runtime. Launch via the package's own ndc_shiny() launcher instead of a hardcoded /srv path. Drop the obsolete COPY R/naturedatacube_app, R/retrieval_functions, data lines (those paths no longer exist in the package layout). - .env.example: rename AGRO_DATA_TOKEN to ADC_TOKEN to match app.R, which reads ADC_TOKEN and stop()s without it. - .dockerignore: keep .git/.env/tests out of the build context. Verified: image builds, package installs, container boots past the package load (now only the runtime token check remains). Co-Authored-By: Claude Opus 4.8 (1M context) --- .dockerignore | 9 +++++++ .env.example | 2 +- Dockerfile | 71 +++++++++++++++++++++++++++------------------------ 3 files changed, 48 insertions(+), 34 deletions(-) create mode 100644 .dockerignore diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..88f5b9d --- /dev/null +++ b/.dockerignore @@ -0,0 +1,9 @@ +.git +.gitignore +.env +.Rproj.user +.Rhistory +.RData +tests/ +README.md +LICENSE diff --git a/.env.example b/.env.example index 8536de4..194cd23 100644 --- a/.env.example +++ b/.env.example @@ -1,3 +1,3 @@ NDC_TOKEN=your_token_here -AGRO_DATA_TOKEN=gettokenat_https://ndc-test.containers.wur.nl +ADC_TOKEN=gettokenat_https://ndc-test.containers.wur.nl SHINY_APP_BASE_URL=/naturedatacube \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index e6fddca..3e1d5dc 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,33 +1,38 @@ -# Use a base image with R and Shiny -FROM rocker/shiny:latest - -# Install system libraries needed by some R packages -RUN apt-get update && apt-get install -y \ - libcurl4-openssl-dev \ - libxml2-dev \ - libssl-dev \ - libgeos-dev \ - libgdal-dev \ - libproj-dev \ - libudunits2-dev \ - && rm -rf /var/lib/apt/lists/* - -# Install required R packages (leaflet.extras from GitHub — not on CRAN for R 4.5+) -RUN R -e "install.packages(c( \ - 'shiny', 'leaflet', 'sf', 'dplyr', 'purrr', \ - 'stringr', 'httr', 'geojsonsf', 'jsonlite', 'zip', 'here', 'terra', \ - 'lubridate', 'tools', 'tibble', 'shinyjs', 'rstac', 'remotes' \ -), repos='https://packagemanager.posit.co/cran/__linux__/noble/latest')" && \ - R -e "remotes::install_github('bhaskarvk/leaflet.extras')" - -# Copy app code and data — retrieval_functions must land inside the app dir -# so that here::here() resolves paths correctly at runtime -COPY R/naturedatacube_app /srv/shiny-server/naturedatacube_app -COPY R/retrieval_functions /srv/shiny-server/naturedatacube_app/R/retrieval_functions -COPY data /srv/shiny-server/naturedatacube_app/data - -# Expose the port Shiny uses -EXPOSE 3838 - -# Command to run the app -CMD ["R", "-e", "shiny::runApp('/srv/shiny-server/naturedatacube_app', host='0.0.0.0', port=3838)"] \ No newline at end of file +# Use a base image with R and Shiny +FROM rocker/shiny:latest + +# Install system libraries needed by some R packages +RUN apt-get update && apt-get install -y \ + libcurl4-openssl-dev \ + libxml2-dev \ + libssl-dev \ + libgeos-dev \ + libgdal-dev \ + libproj-dev \ + libudunits2-dev \ + && rm -rf /var/lib/apt/lists/* + +# Install required R packages (leaflet.extras from GitHub — not on CRAN for R 4.5+). +# DESCRIPTION has no Imports field, so the package's dependencies are installed +# explicitly here rather than resolved by R CMD INSTALL. +RUN R -e "install.packages(c( \ + 'shiny', 'leaflet', 'sf', 'dplyr', 'purrr', \ + 'stringr', 'httr', 'geojsonsf', 'jsonlite', 'zip', 'here', 'terra', \ + 'lubridate', 'tools', 'tibble', 'shinyjs', 'rstac', 'remotes' \ +), repos='https://packagemanager.posit.co/cran/__linux__/noble/latest')" && \ + R -e "remotes::install_github('bhaskarvk/leaflet.extras')" + +# Install the NatureDataCubeR package itself. This puts the Shiny app +# (inst/shiny/naturedatacube_app) and bundled data (inst/extdata) on the +# package's installed path, so library(NatureDataCubeR) and +# system.file(...) resolve at runtime. +COPY . /tmp/NatureDataCubeR +RUN R CMD INSTALL --no-multiarch --with-keep.source /tmp/NatureDataCubeR \ + && rm -rf /tmp/NatureDataCubeR + +# Expose the port Shiny uses +EXPOSE 3838 + +# Launch the app via the package's own launcher, which locates the app dir +# with system.file(). SHINY_APP_BASE_URL (from .env) sets the proxy path. +CMD ["R", "-e", "NatureDataCubeR::ndc_shiny(host='0.0.0.0', port=3838)"]