From 3f60346cbb5108444612bd62602681e972192739 Mon Sep 17 00:00:00 2001 From: SteveViss Date: Tue, 30 Jan 2024 15:25:01 -0500 Subject: [PATCH 1/5] CST-241 Add app folder --- DESCRIPTION => app/DESCRIPTION | 0 app.R => app/app.R | 0 {code => app/code}/cumulHotspots.R | 0 {code => app/code}/cumulIntensity.R | 0 {code => app/code}/dataDescription.R | 0 {code => app/code}/histDriver.R | 0 {code => app/code}/histHotspot.R | 0 {code => app/code}/multiDescription.R | 0 {code => app/code}/param.R | 0 {data => app/data}/drivers_ss.RData | Bin {data => app/data}/drivers_stl.RData | Bin {data => app/data}/eDrivers.RData | Bin {data => app/data}/layers_ss.RData | Bin {data => app/data}/layers_stl.RData | Bin {modules => app/modules}/appServer.R | 0 {modules => app/modules}/appUI.R | 0 {texts => app/texts}/eDrivers.R | 0 {texts => app/texts}/layers_ss.R | 0 {texts => app/texts}/layers_stl.R | 0 {www => app/www}/CRSNG-color.png | Bin {www => app/www}/INREST.png | Bin {www => app/www}/NCEAS.png | Bin {www => app/www}/Notre_Golfe.png | Bin {www => app/www}/SCBQ_logo2.png | Bin {www => app/www}/UdeS.png | Bin {www => app/www}/benthos.png | Bin {www => app/www}/chone.jpg | Bin {www => app/www}/eDrivers.css | 0 {www => app/www}/frqnt.png | Bin {www => app/www}/ielab.jpg | Bin {www => app/www}/inSilecoLogo.png | Bin {www => app/www}/logo-QO_png.png | Bin {www => app/www}/logo-ogsl-fr.png | Bin {www => app/www}/mddelcc.png | Bin {www => app/www}/mpo.png | Bin {www => app/www}/port7I.png | Bin {www => app/www}/structure.png | Bin {www => app/www}/takuvik.jpg | Bin {www => app/www}/ul.png | Bin {www => app/www}/uqar_ismer.png | Bin 40 files changed, 0 insertions(+), 0 deletions(-) rename DESCRIPTION => app/DESCRIPTION (100%) rename app.R => app/app.R (100%) rename {code => app/code}/cumulHotspots.R (100%) rename {code => app/code}/cumulIntensity.R (100%) rename {code => app/code}/dataDescription.R (100%) rename {code => app/code}/histDriver.R (100%) rename {code => app/code}/histHotspot.R (100%) rename {code => app/code}/multiDescription.R (100%) rename {code => app/code}/param.R (100%) rename {data => app/data}/drivers_ss.RData (100%) rename {data => app/data}/drivers_stl.RData (100%) rename {data => app/data}/eDrivers.RData (100%) rename {data => app/data}/layers_ss.RData (100%) rename {data => app/data}/layers_stl.RData (100%) rename {modules => app/modules}/appServer.R (100%) rename {modules => app/modules}/appUI.R (100%) rename {texts => app/texts}/eDrivers.R (100%) rename {texts => app/texts}/layers_ss.R (100%) rename {texts => app/texts}/layers_stl.R (100%) rename {www => app/www}/CRSNG-color.png (100%) rename {www => app/www}/INREST.png (100%) rename {www => app/www}/NCEAS.png (100%) rename {www => app/www}/Notre_Golfe.png (100%) rename {www => app/www}/SCBQ_logo2.png (100%) rename {www => app/www}/UdeS.png (100%) rename {www => app/www}/benthos.png (100%) rename {www => app/www}/chone.jpg (100%) rename {www => app/www}/eDrivers.css (100%) rename {www => app/www}/frqnt.png (100%) rename {www => app/www}/ielab.jpg (100%) rename {www => app/www}/inSilecoLogo.png (100%) rename {www => app/www}/logo-QO_png.png (100%) rename {www => app/www}/logo-ogsl-fr.png (100%) rename {www => app/www}/mddelcc.png (100%) rename {www => app/www}/mpo.png (100%) rename {www => app/www}/port7I.png (100%) rename {www => app/www}/structure.png (100%) rename {www => app/www}/takuvik.jpg (100%) rename {www => app/www}/ul.png (100%) rename {www => app/www}/uqar_ismer.png (100%) 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 From 2d1376f7793107b52402a32f99c18f715772d638 Mon Sep 17 00:00:00 2001 From: SteveViss Date: Tue, 30 Jan 2024 15:25:40 -0500 Subject: [PATCH 2/5] CST-241 Deploy app and forward logs --- Dockerfile | 30 +++++++++++++++++++++--------- shiny-server.conf | 22 ++++++++++++++++++++++ shiny-server.sh | 7 +++++++ 3 files changed, 50 insertions(+), 9 deletions(-) create mode 100644 shiny-server.conf create mode 100644 shiny-server.sh diff --git a/Dockerfile b/Dockerfile index 3e1c102..b01f321 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,18 +1,30 @@ # Base R Shiny image -FROM rocker/geospatial:latest +FROM rocker/shiny:latest -RUN apt-get update && apt-get install -y +RUN apt-get update \ + && apt-get install -y --no-install-recommends \ + libproj-dev \ + libudunits2-dev \ + libgdal-dev \ + libgeos-dev \ + libsqlite0-dev -# Copy the Shiny app code -WORKDIR /home/app -ADD . /home/app +# Copy shiny app into the Docker image +COPY app /srv/shiny-server/ # Install R dependencies RUN install2.r remotes -RUN Rscript -e 'remotes::install_deps()' +RUN Rscript -e "remotes::install_deps('/srv/shiny-server/')" + +# Copy configuration files into the Docker image +COPY shiny-server.conf /etc/shiny-server/shiny-server.conf # Expose the application port -EXPOSE 8083 +EXPOSE 5000 + +# Copy shiny app execution file into the Docker image +COPY shiny-server.sh /usr/bin/shiny-server.sh + +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/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..87cdb3e --- /dev/null +++ b/shiny-server.sh @@ -0,0 +1,7 @@ +#!/bin/sh + +# Make sure the directory for individual app logs exists +mkdir -p /var/log/shiny-server +chown shiny:shiny /var/log/shiny-server + +Rscript -e "shiny::runApp(port = 5000, host = '0.0.0.0')" >> /var/log/shiny-server.log 2>&1 \ No newline at end of file From 9eb88a8dbec5ee3393b0da353676f42133aa7d30 Mon Sep 17 00:00:00 2001 From: SteveViss Date: Tue, 30 Jan 2024 16:40:53 -0500 Subject: [PATCH 3/5] CST-241 Update readme --- README.md | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 373b7a6..7142e98 100644 --- a/README.md +++ b/README.md @@ -17,8 +17,21 @@ Rscript -e "shiny::runApp(port = 8083, host = '0.0.0.0')" **Build and deploy the application within a container** ```bash -docker build -t edrivers . && docker run -p 8083:8083 -it --rm edriver +docker build -t edrivers . && docker run -p 5000:5000 -it --rm edriver ``` Deployment tested on `Docker version 25.0.0` +## Publish docker image on Google cloud artifact registry +Send gcloud credentials to docker + +```bash +gcloud auth configure-docker northamerica-northeast1-docker.pkg.dev +``` + +Build locally and publish manually docker to google cloud artifacts + +```bash +docker build --tag=northamerica-northeast1-docker.pkg.dev/pof-stac-insileco/shiny-docker-prod/edrivers:v1.0.0 . +docker push northamerica-northeast1-docker.pkg.dev/pof-stac-insileco/shiny-docker-prod/edrivers:v1.0.0 +``` \ No newline at end of file From ddc84a9c30559f4b40c546cfc5259513a19af7a9 Mon Sep 17 00:00:00 2001 From: SteveViss Date: Wed, 31 Jan 2024 10:56:25 -0500 Subject: [PATCH 4/5] CST-241 review README --- README.md | 40 +++++++++++++++++++++++++++++++++------- 1 file changed, 33 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 7142e98..88072d3 100644 --- a/README.md +++ b/README.md @@ -2,24 +2,46 @@ Shiny application to visualize eDrivers platform data. -## Local deployment +## `dev` - Local deployment + +**Local R environment** ```bash +cd app Rscript -e "shiny::runApp(port = 8083, host = '0.0.0.0')" ``` -## Docker deployment +**Build and deploy the application within a container** + +```bash +docker build -t edrivers . && docker run -p 5000:5000 -it --rm edriver +``` + +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 -docker build -t edrivers . && docker run -p 5000:5000 -it --rm edriver +# 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 ``` -Deployment tested on `Docker version 25.0.0` ## Publish docker image on Google cloud artifact registry @@ -28,10 +50,14 @@ Send gcloud credentials to docker ```bash gcloud auth configure-docker northamerica-northeast1-docker.pkg.dev ``` - -Build locally and publish manually docker to google cloud artifacts +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 From 67ef81a7a0f34d0524301c427fae96106c4e780a Mon Sep 17 00:00:00 2001 From: SteveViss Date: Thu, 1 Feb 2024 09:12:06 -0500 Subject: [PATCH 5/5] CST-241 reviews --- Dockerfile | 23 +++++++++++++++-------- README.md | 4 ++-- shiny-server.sh | 6 +----- 3 files changed, 18 insertions(+), 15 deletions(-) diff --git a/Dockerfile b/Dockerfile index b01f321..c6c918d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,5 +1,5 @@ # Base R Shiny image -FROM rocker/shiny:latest +FROM rocker/shiny:4.3.0 RUN apt-get update \ && apt-get install -y --no-install-recommends \ @@ -9,22 +9,29 @@ RUN apt-get update \ libgeos-dev \ libsqlite0-dev -# Copy shiny app into the Docker image -COPY app /srv/shiny-server/ - # Install R dependencies RUN install2.r remotes -RUN Rscript -e "remotes::install_deps('/srv/shiny-server/')" +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 -# Expose the application port -EXPOSE 5000 - # Copy shiny app execution file into the Docker image COPY shiny-server.sh /usr/bin/shiny-server.sh +# Expose the application port +EXPOSE 5000 + USER shiny CMD ["/usr/bin/shiny-server"] \ No newline at end of file diff --git a/README.md b/README.md index 88072d3..977eb4f 100644 --- a/README.md +++ b/README.md @@ -8,13 +8,13 @@ Shiny application to visualize eDrivers platform data. ```bash cd app -Rscript -e "shiny::runApp(port = 8083, host = '0.0.0.0')" +Rscript -e "shiny::runApp(port = 5000, host = '0.0.0.0')" ``` **Build and deploy the application within a container** ```bash -docker build -t edrivers . && docker run -p 5000:5000 -it --rm edriver +docker build -t edrivers:latest . && docker run -p 5000:5000 -it --rm edrivers:latest ``` Deployment tested on `Docker version 25.0.0` diff --git a/shiny-server.sh b/shiny-server.sh index 87cdb3e..a91c71c 100644 --- a/shiny-server.sh +++ b/shiny-server.sh @@ -1,7 +1,3 @@ #!/bin/sh -# Make sure the directory for individual app logs exists -mkdir -p /var/log/shiny-server -chown shiny:shiny /var/log/shiny-server - -Rscript -e "shiny::runApp(port = 5000, host = '0.0.0.0')" >> /var/log/shiny-server.log 2>&1 \ No newline at end of file +Rscript -e "shiny::runApp(port = 5000, host = '0.0.0.0')" 2>&1 \ No newline at end of file