diff --git a/Dockerfile b/Dockerfile index 3e1c102..c6c918d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,18 +1,37 @@ # Base R Shiny image -FROM rocker/geospatial:latest +FROM rocker/shiny:4.3.0 -RUN apt-get update && apt-get install -y - -# Copy the Shiny app code -WORKDIR /home/app -ADD . /home/app +RUN apt-get update \ + && apt-get install -y --no-install-recommends \ + libproj-dev \ + libudunits2-dev \ + libgdal-dev \ + libgeos-dev \ + libsqlite0-dev # Install R dependencies RUN install2.r remotes -RUN Rscript -e 'remotes::install_deps()' +RUN Rscript -e 'remotes::install_version("raster", upgrade = "never", version = "3.6-14")' +RUN Rscript -e 'remotes::install_version("leaflet", upgrade = "never", version = "2.1.1")' +RUN Rscript -e 'remotes::install_version("shiny", upgrade = "never", version = "1.7.0")' +RUN Rscript -e 'remotes::install_version("shinyjs", upgrade = "never", version = "2.0.0")' +RUN Rscript -e 'remotes::install_version("magrittr", upgrade = "never", version = "2.0.3")' +RUN Rscript -e 'remotes::install_version("sf", upgrade = "never", version = "1.0-9")' +RUN Rscript -e 'remotes::install_version("dplyr", upgrade = "never", version = "1.0.4")' +RUN Rscript -e 'remotes::install_version("tidyr", upgrade = "never", version = "1.2.1")' + +# Copy shiny app into the Docker image +COPY app /srv/shiny-server/ + +# Copy configuration files into the Docker image +COPY shiny-server.conf /etc/shiny-server/shiny-server.conf + +# Copy shiny app execution file into the Docker image +COPY shiny-server.sh /usr/bin/shiny-server.sh # Expose the application port -EXPOSE 8083 +EXPOSE 5000 + +USER shiny -# Run the R Shiny app -CMD Rscript -e "shiny::runApp(port = 8083, host = '0.0.0.0')" \ No newline at end of file +CMD ["/usr/bin/shiny-server"] \ No newline at end of file diff --git a/README.md b/README.md index 373b7a6..977eb4f 100644 --- a/README.md +++ b/README.md @@ -2,23 +2,62 @@ Shiny application to visualize eDrivers platform data. -## Local deployment +## `dev` - Local deployment + +**Local R environment** ```bash -Rscript -e "shiny::runApp(port = 8083, host = '0.0.0.0')" +cd app +Rscript -e "shiny::runApp(port = 5000, host = '0.0.0.0')" ``` -## Docker deployment +**Build and deploy the application within a container** + +```bash +docker build -t edrivers:latest . && docker run -p 5000:5000 -it --rm edrivers:latest +``` + +Deployment tested on `Docker version 25.0.0` + +## `prod` - Docker deployment **Requirements** - Install docker on your computer: https://docs.docker.com/engine/install/ +- Install gcloud SDK client: https://cloud.google.com/sdk/docs/install -**Build and deploy the application within a container** +## Create google artifacts repository + +```bash +# Authentication with Google Cloud +gcloud auth login + +# setting the project - Lets say PROJECT_ID = someproject-123 +gcloud config set project pof-stac-insileco + +# Creatng AR +gcloud artifacts repositories create docker-repo --repository-format=docker \ +--location=northamerica-northeast1 --description="shiny-docker-prod" + +#listing AR +gcloud artifacts repositories list +``` + +## Publish docker image on Google cloud artifact registry + +Send gcloud credentials to docker ```bash -docker build -t edrivers . && docker run -p 8083:8083 -it --rm edriver +gcloud auth configure-docker northamerica-northeast1-docker.pkg.dev ``` -Deployment tested on `Docker version 25.0.0` +Build and tag docker image for release +```bash +docker build --tag=northamerica-northeast1-docker.pkg.dev/pof-stac-insileco/shiny-docker-prod/edrivers:v1.0.0 . +``` +Publish docker image to google cloud artifacts repository + +```bash +docker push northamerica-northeast1-docker.pkg.dev/pof-stac-insileco/shiny-docker-prod/edrivers:v1.0.0 +``` \ No newline at end of file diff --git a/DESCRIPTION b/app/DESCRIPTION similarity index 100% rename from DESCRIPTION rename to app/DESCRIPTION diff --git a/app.R b/app/app.R similarity index 100% rename from app.R rename to app/app.R diff --git a/code/cumulHotspots.R b/app/code/cumulHotspots.R similarity index 100% rename from code/cumulHotspots.R rename to app/code/cumulHotspots.R diff --git a/code/cumulIntensity.R b/app/code/cumulIntensity.R similarity index 100% rename from code/cumulIntensity.R rename to app/code/cumulIntensity.R diff --git a/code/dataDescription.R b/app/code/dataDescription.R similarity index 100% rename from code/dataDescription.R rename to app/code/dataDescription.R diff --git a/code/histDriver.R b/app/code/histDriver.R similarity index 100% rename from code/histDriver.R rename to app/code/histDriver.R diff --git a/code/histHotspot.R b/app/code/histHotspot.R similarity index 100% rename from code/histHotspot.R rename to app/code/histHotspot.R diff --git a/code/multiDescription.R b/app/code/multiDescription.R similarity index 100% rename from code/multiDescription.R rename to app/code/multiDescription.R diff --git a/code/param.R b/app/code/param.R similarity index 100% rename from code/param.R rename to app/code/param.R diff --git a/data/drivers_ss.RData b/app/data/drivers_ss.RData similarity index 100% rename from data/drivers_ss.RData rename to app/data/drivers_ss.RData diff --git a/data/drivers_stl.RData b/app/data/drivers_stl.RData similarity index 100% rename from data/drivers_stl.RData rename to app/data/drivers_stl.RData diff --git a/data/eDrivers.RData b/app/data/eDrivers.RData similarity index 100% rename from data/eDrivers.RData rename to app/data/eDrivers.RData diff --git a/data/layers_ss.RData b/app/data/layers_ss.RData similarity index 100% rename from data/layers_ss.RData rename to app/data/layers_ss.RData diff --git a/data/layers_stl.RData b/app/data/layers_stl.RData similarity index 100% rename from data/layers_stl.RData rename to app/data/layers_stl.RData diff --git a/modules/appServer.R b/app/modules/appServer.R similarity index 100% rename from modules/appServer.R rename to app/modules/appServer.R diff --git a/modules/appUI.R b/app/modules/appUI.R similarity index 100% rename from modules/appUI.R rename to app/modules/appUI.R diff --git a/texts/eDrivers.R b/app/texts/eDrivers.R similarity index 100% rename from texts/eDrivers.R rename to app/texts/eDrivers.R diff --git a/texts/layers_ss.R b/app/texts/layers_ss.R similarity index 100% rename from texts/layers_ss.R rename to app/texts/layers_ss.R diff --git a/texts/layers_stl.R b/app/texts/layers_stl.R similarity index 100% rename from texts/layers_stl.R rename to app/texts/layers_stl.R diff --git a/www/CRSNG-color.png b/app/www/CRSNG-color.png similarity index 100% rename from www/CRSNG-color.png rename to app/www/CRSNG-color.png diff --git a/www/INREST.png b/app/www/INREST.png similarity index 100% rename from www/INREST.png rename to app/www/INREST.png diff --git a/www/NCEAS.png b/app/www/NCEAS.png similarity index 100% rename from www/NCEAS.png rename to app/www/NCEAS.png diff --git a/www/Notre_Golfe.png b/app/www/Notre_Golfe.png similarity index 100% rename from www/Notre_Golfe.png rename to app/www/Notre_Golfe.png diff --git a/www/SCBQ_logo2.png b/app/www/SCBQ_logo2.png similarity index 100% rename from www/SCBQ_logo2.png rename to app/www/SCBQ_logo2.png diff --git a/www/UdeS.png b/app/www/UdeS.png similarity index 100% rename from www/UdeS.png rename to app/www/UdeS.png diff --git a/www/benthos.png b/app/www/benthos.png similarity index 100% rename from www/benthos.png rename to app/www/benthos.png diff --git a/www/chone.jpg b/app/www/chone.jpg similarity index 100% rename from www/chone.jpg rename to app/www/chone.jpg diff --git a/www/eDrivers.css b/app/www/eDrivers.css similarity index 100% rename from www/eDrivers.css rename to app/www/eDrivers.css diff --git a/www/frqnt.png b/app/www/frqnt.png similarity index 100% rename from www/frqnt.png rename to app/www/frqnt.png diff --git a/www/ielab.jpg b/app/www/ielab.jpg similarity index 100% rename from www/ielab.jpg rename to app/www/ielab.jpg diff --git a/www/inSilecoLogo.png b/app/www/inSilecoLogo.png similarity index 100% rename from www/inSilecoLogo.png rename to app/www/inSilecoLogo.png diff --git a/www/logo-QO_png.png b/app/www/logo-QO_png.png similarity index 100% rename from www/logo-QO_png.png rename to app/www/logo-QO_png.png diff --git a/www/logo-ogsl-fr.png b/app/www/logo-ogsl-fr.png similarity index 100% rename from www/logo-ogsl-fr.png rename to app/www/logo-ogsl-fr.png diff --git a/www/mddelcc.png b/app/www/mddelcc.png similarity index 100% rename from www/mddelcc.png rename to app/www/mddelcc.png diff --git a/www/mpo.png b/app/www/mpo.png similarity index 100% rename from www/mpo.png rename to app/www/mpo.png diff --git a/www/port7I.png b/app/www/port7I.png similarity index 100% rename from www/port7I.png rename to app/www/port7I.png diff --git a/www/structure.png b/app/www/structure.png similarity index 100% rename from www/structure.png rename to app/www/structure.png diff --git a/www/takuvik.jpg b/app/www/takuvik.jpg similarity index 100% rename from www/takuvik.jpg rename to app/www/takuvik.jpg diff --git a/www/ul.png b/app/www/ul.png similarity index 100% rename from www/ul.png rename to app/www/ul.png diff --git a/www/uqar_ismer.png b/app/www/uqar_ismer.png similarity index 100% rename from www/uqar_ismer.png rename to app/www/uqar_ismer.png diff --git a/shiny-server.conf b/shiny-server.conf new file mode 100644 index 0000000..ce64afd --- /dev/null +++ b/shiny-server.conf @@ -0,0 +1,22 @@ +# Instruct Shiny Server to run applications as the user "shiny" +run_as shiny; + +# Define a server that listens on port 3838 +server { + listen 5000; + + # Define a location at the base URL + location / { + + # Run this location in 'site_dir' mode, which hosts the entire directory + # tree at '/srv/shiny-server' + site_dir /srv/shiny-server; + + # Define where we should put the log files for this location + log_dir /var/log/shiny-server; + + # When a user visits the base URL rather than a particular application, + # an index of the applications available in this directory will be shown. + directory_index off; + } +} \ No newline at end of file diff --git a/shiny-server.sh b/shiny-server.sh new file mode 100644 index 0000000..a91c71c --- /dev/null +++ b/shiny-server.sh @@ -0,0 +1,3 @@ +#!/bin/sh + +Rscript -e "shiny::runApp(port = 5000, host = '0.0.0.0')" 2>&1 \ No newline at end of file