# 1. THE FOUNDATION
# The Rocker project provides pre-built images with R + Shiny pre-installed.
# We lock to R version 4.3.1 — this version never changes in our container.
FROM rocker/shiny-verse:4.3.1

# 2. SYSTEM LIBRARIES
# Install the Linux C++ libraries that sf and rstan need.
# This is the step that fixes the 'gdal-config not found' nightmare.
RUN apt-get update && apt-get install -y \
    libgdal-dev \
    libv8-dev \
    libcurl4-openssl-dev \
    && rm -rf /var/lib/apt/lists/*

# 3. R PACKAGES
# Install the packages our app needs.
RUN R -e "install.packages(c('sf','rstan','bslib'), repos='https://cloud.r-project.org/')"

# 4. COPY THE APP
# Copy our app.R from our laptop into the container's filesystem.
COPY app.R /srv/shiny-server/myapp/app.R

# 5. EXPOSE THE PORT
# Shiny runs on port 3838. Tell the container to allow traffic on this port.
EXPOSE 3838

# 6. START THE APP
# The command that runs when the container starts.
CMD ["R", "-e", "shiny::runApp('/srv/shiny-server/myapp', host='0.0.0.0', port=3838)"]
