有没有人有资源或先前的例子来启动一个闪亮的 dockerized 应用程序,该应用程序是在 AWS EC2 实例上使用 golem 框架构建的?主要是,我可以使用一些帮助来配置 Dockerfile、shiny-server.conf 和 shiny-server.sh 文件。
该应用程序严重依赖 PostgreSQL 数据库来管理用户数据。我已经能够使用本地 docker 容器部署应用程序,但我不确定如何在 EC2 实例上导航启动。这主要是因为 golem 框架与 Shiny 应用程序的传统结构(server.r、ui.r、app.r)略有不同。我们需要对这个应用程序进行容器化,因为需要保留一个全局变量用户 ID,以及每个图像周围至少有四个唯一的用户数据集。我通常不会使用 AWS EC2 实例来为应用程序提供服务,但这是我们在项目团队中讨论的内容。
我不确定的另一个元素是 EC2 实例类型。图像约为 2.5Gb(并且还在增长)。该应用程序可能会为每位用户保存超过 500Mb 的数据。我们有大约 3,000 美元的托管费用,它应该至少持续两年(包括 RDS 成本)。一般来说,我不确定给定大小的应用程序的价格是否可行。
我的项目团队正在使用这种设置进入未知领域,因此非常欢迎任何建议。
这是我认为应该为 AWS EC2 实例设置的工作 Dockerfile。
FROM rocker/r-ver:4.0.3
RUN apt-get update && apt-get install -y git-core \
sqlite3 libsqlite3-dev \
libcurl4-openssl-dev \
libgit2-dev \
libicu-dev \
libssh2-1-dev \
libssl-dev \
libxml2-dev \
libpng-dev \
libudunits2-dev \
libgdal-dev \
libproj-dev \
libgeos-dev \
make pandoc pandoc-citeproc \
zlib1g-dev \
&& rm -rf /var/lib/apt/lists/*
RUN echo "options(repos = c(CRAN = 'https://packagemanager.rstudio.com/all/latest/'), download.file.method = 'libcurl')" >> /usr/local/lib/R/etc/Rprofile.site
RUN R -e 'install.packages("remotes")'
RUN R -e 'remotes::install_github("r-lib/remotes", ref = "97bbf81")'
RUN Rscript -e 'remotes::install_version("glue",upgrade="never", version = "1.4.2")'
RUN Rscript -e 'remotes::install_version("processx",upgrade="never", version = "3.4.4")'
RUN Rscript -e 'remotes::install_version("pkgload",upgrade="never", version = "1.1.0")'
RUN Rscript -e 'remotes::install_version("htmltools",upgrade="never", version = "0.5.0")'
RUN Rscript -e 'remotes::install_version("attempt",upgrade="never", version = "0.3.1")'
RUN Rscript -e 'remotes::install_version("testthat",upgrade="never", version = "3.0.0")'
RUN Rscript -e 'remotes::install_version("shiny",upgrade="never", version = "1.5.0")'
RUN Rscript -e 'remotes::install_version("config",upgrade="never", version = "0.3")'
RUN Rscript -e 'remotes::install_version("golem",upgrade="never", version = "0.2.1")'
RUN Rscript -e 'remotes::install_version("shinydashboard",upgrade="never", version = "0.7.1")'
RUN Rscript -e 'remotes::install_version("usmap",upgrade="never", version = "0.5.1")'
RUN Rscript -e 'remotes::install_version("rgeos",upgrade="never", version = "0.5-5")'
RUN Rscript -e 'remotes::install_version("tidyverse",upgrade="never", version = "1.3.0")'
RUN Rscript -e 'remotes::install_version("shinyWidgets",upgrade="never", version = "0.5.4")'
RUN Rscript -e 'remotes::install_version("leaflet",upgrade="never", version = "2.0.3")'
RUN Rscript -e 'remotes::install_version("sf",upgrade="never", version = "0.9-6")'
RUN Rscript -e 'remotes::install_version("DBI",upgrade="never", version = "1.1.0")'
RUN Rscript -e 'remotes::install_version("rpostgis",upgrade="never", version = "1.4.3")'
RUN Rscript -e 'remotes::install_version("ggplot2",upgrade="never", version = "3.3.2")'
RUN Rscript -e 'remotes::install_version("rgdal",upgrade="never", version = "1.5-18")'
RUN Rscript -e 'remotes::install_version("RSQLite",upgrade="never", version = "2.2.1")'
RUN Rscript -e 'remotes::install_version("shinyjs",upgrade="never", version = "2.0.0")'
RUN Rscript -e 'remotes::install_version("tigris",upgrade="never", version = "1.0")'
RUN Rscript -e 'remotes::install_version("sp",upgrade="never", version = "1.4-4")'
RUN Rscript -e 'remotes::install_version("RCurl",upgrade="never", version = "1.98-1.2")'
RUN Rscript -e 'remotes::install_version("DT",upgrade="never", version = "0.16")'
RUN Rscript -e 'remotes::install_version("rmarkdown",upgrade="never", version = "2.5")'
RUN Rscript -e 'remotes::install_version("knitr",upgrade="never", version = "1.30")'
RUN mkdir /build_zone
ADD . /build_zone
WORKDIR /build_zone
RUN R -e 'remotes::install_local(upgrade="never")'
EXPOSE 3838
COPY shiny-server.sh /usr/bin/shiny-server.sh
COPY shiny-customized.config /etc/shiny-server/shiny-server.conf
CMD R -e "options('shiny.port'=3838,shiny.host='0.0.0.0');my_app::run_app()"
RUN ["chmod", "+x", "/usr/bin/shiny-server.sh"]
CMD ["/usr/bin/shiny-server.sh"]
闪亮的server.conf
# Instruct Shiny Server to run applications as the user "shiny"
run_as shiny;
# Define a server that listens on port 3838
server {
listen 3838;
# Define a location at the base URL
location / {
# Host the directory of Shiny Apps stored in this directory
app_dir /srv/shiny-server/ga-reporter;
# Log all Shiny output to files in this directory
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 on;
}
}
闪亮的server.sh
#!/bin/sh
# ShinyServer: Make sure the directory for individual app logs exists
mkdir -p /var/log/shiny-server
chown -R shiny.shiny /var/log/shiny-server
# RUN ShinyServer
exec shiny-server >> /var/log/shiny-server.log 2>&1
提前致谢。