# -*- Dockerfile -*-

FROM fedora:36

# -------------------------------------------------------------------------
RUN yum install -y R-devel
RUN R -q -e 'source("https://pak.r-lib.org/install.R")'

# -------------------------------------------------------------------------
# Only copy DESCRIPTION, so Docker can cache the dependency install
RUN mkdir /root/bigrquerystorage
COPY DESCRIPTION /root/bigrquerystorage/
WORKDIR /root/bigrquerystorage
# No upgrade, to always install binary packages, in case P3M is behind
RUN R -q -e 'pak::local_install_deps(upgrade = FALSE)'

# -------------------------------------------------------------------------
# FIXME: We don't need this once grpc is in the system requirements db
RUN dnf install -y grpc-devel pkgconf

# -------------------------------------------------------------------------
# Call R CMD build first, so we get rid of Makevars, .o, .so, etc.
# Change file ownership, otherwise git complains
# Clean up thoroughly, in case the cleanup script is not perfect.
RUN dnf install -y git
COPY . /root/bigrquerystorage
RUN chown root:root -R .
RUN git clean -fdx .

# -------------------------------------------------------------------------
WORKDIR /root
RUN R CMD build bigrquerystorage
RUN R CMD INSTALL bigrquerystorage_*.tar.gz
