Skip to content

Commit

Permalink
Merge pull request #3 from Ecosystem-Assessments/CST-241-deploy-app
Browse files Browse the repository at this point in the history
CST-241-deploy-app
  • Loading branch information
KevCaz authored Feb 1, 2024
2 parents 61150d7 + 67ef81a commit 73a3cb0
Show file tree
Hide file tree
Showing 44 changed files with 99 additions and 16 deletions.
39 changes: 29 additions & 10 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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')"
CMD ["/usr/bin/shiny-server"]
51 changes: 45 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
22 changes: 22 additions & 0 deletions shiny-server.conf
Original file line number Diff line number Diff line change
@@ -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;
}
}
3 changes: 3 additions & 0 deletions shiny-server.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/sh

Rscript -e "shiny::runApp(port = 5000, host = '0.0.0.0')" 2>&1

0 comments on commit 73a3cb0

Please sign in to comment.