如何在闪亮服务器 R 应用程序的 docker 容器中设置 _auth0.yml 值
How to set _auth0.yml values in a docker container for a shiny-server R app
仅供参考 - 对于闪亮的应用程序,我绝对是新手,但我正在尝试帮助闪亮的应用程序开发人员使用 docker 容器部署他们的应用程序(也是 docker 的新手但我已经完成了其中的一些,所以我明白发生了什么)。
我有一个闪亮的应用程序,部署在 docker 容器中的闪亮服务器上。这个闪亮的应用程序正在使用 auth0,我正在关注这篇文章 (https://github.com/curso-r/auth0),以便 _auth0.yml 文件将从环境变量中获取它的秘密。
问题在于如何在 docker 容器中正确设置这些环境变量,以便我的 _auth0.yml 文件将填充它们的值?任何帮助将不胜感激!
我已经尝试在我的 Dockerfile 中设置“ENV”,
ENV AUTH0_USER="user" \
AUTH0_KEY="key" \
AUTH0_SECRET="secret"
如果我这样做,并将它放入我的 docker 容器中,我会看到环境变量已设置,但是当我 运行 应用程序时,环境变量不会填充“api_url”,并尝试转到“https://.auth0.com/authorize?client_id=&scope=openid%20profile&redirect_uri=http%3A%2F %2Flocalhost%3A3838&response_type=code&state=LmNvuzzUB8"
我的 Dockerfile 如下所示:
#shiny-more
FROM rocker/shiny-verse:latest
# install R packages required
RUN apt-get update -qq && apt-get install -y --no-install-recommends vim
RUN mkdir -p /opt/software/setup/R
ADD install_packages.R /opt/software/setup/R/
RUN Rscript /opt/software/setup/R/install_packages.R
#shiny-auth0
# copy the app to the image
COPY *.Rproj /srv/shiny-server/
COPY *.R /srv/shiny-server/
COPY *.xlsx /srv/shiny-server/data/
COPY *.png /srv/shiny-server/www/
COPY logs /srv/shiny-server/logs
COPY rsconnect /srv/shiny-server/rsconnect
COPY _auth0.yml /srv/shiny-server/
# select port
EXPOSE 3838 8080
# allow permission
RUN sudo chown -R shiny:shiny /srv/shiny-server
# Copy further configuration files into the Docker image
COPY shiny-server.sh /usr/bin/shiny-server.sh
RUN ["chmod", "+x", "/usr/bin/shiny-server.sh"]
ENV AUTH0_USER="user" \
AUTH0_KEY="key" \
AUTH0_SECRET="secret"
# run app
CMD ["/usr/bin/shiny-server.sh"]
我的 _auth0.yml 文件如下所示:
remote_url: ''
auth0_config:
api_url: !expr paste0('https://', Sys.getenv("AUTH0_USER"), '.auth0.com')
credentials:
key: !expr Sys.getenv("AUTH0_KEY")
secret: !expr Sys.getenv("AUTH0_SECRET")
编辑:我在这里读到 (https://groups.google.com/g/shiny-discuss/c/nNs0kztwdWo/m/90InjZXfAPEJ) 启动 R 时不会读取环境变量。那么怎么会这个解决方案真的有效吗? https://github.com/curso-r/auth0
所以从技术上讲,我想出了解决这个问题的方法。我在项目的根目录下创建了一个“.Renviron”文件,将所有环境变量保存在该文件中,然后将其复制到我的 docker 图像中。
当我启动我的容器时,我能够成功地运行我的应用程序,使用 .Renviron 提供的数据,以便应用程序可以连接到 auth0 以验证用户。
现在我需要弄清楚如何将此文件传递给 docker 容器,以便安全地提取此 .Renviron 文件,而不必像 github.
仅供参考 - 对于闪亮的应用程序,我绝对是新手,但我正在尝试帮助闪亮的应用程序开发人员使用 docker 容器部署他们的应用程序(也是 docker 的新手但我已经完成了其中的一些,所以我明白发生了什么)。
我有一个闪亮的应用程序,部署在 docker 容器中的闪亮服务器上。这个闪亮的应用程序正在使用 auth0,我正在关注这篇文章 (https://github.com/curso-r/auth0),以便 _auth0.yml 文件将从环境变量中获取它的秘密。
问题在于如何在 docker 容器中正确设置这些环境变量,以便我的 _auth0.yml 文件将填充它们的值?任何帮助将不胜感激!
我已经尝试在我的 Dockerfile 中设置“ENV”,
ENV AUTH0_USER="user" \
AUTH0_KEY="key" \
AUTH0_SECRET="secret"
如果我这样做,并将它放入我的 docker 容器中,我会看到环境变量已设置,但是当我 运行 应用程序时,环境变量不会填充“api_url”,并尝试转到“https://.auth0.com/authorize?client_id=&scope=openid%20profile&redirect_uri=http%3A%2F %2Flocalhost%3A3838&response_type=code&state=LmNvuzzUB8"
我的 Dockerfile 如下所示:
#shiny-more
FROM rocker/shiny-verse:latest
# install R packages required
RUN apt-get update -qq && apt-get install -y --no-install-recommends vim
RUN mkdir -p /opt/software/setup/R
ADD install_packages.R /opt/software/setup/R/
RUN Rscript /opt/software/setup/R/install_packages.R
#shiny-auth0
# copy the app to the image
COPY *.Rproj /srv/shiny-server/
COPY *.R /srv/shiny-server/
COPY *.xlsx /srv/shiny-server/data/
COPY *.png /srv/shiny-server/www/
COPY logs /srv/shiny-server/logs
COPY rsconnect /srv/shiny-server/rsconnect
COPY _auth0.yml /srv/shiny-server/
# select port
EXPOSE 3838 8080
# allow permission
RUN sudo chown -R shiny:shiny /srv/shiny-server
# Copy further configuration files into the Docker image
COPY shiny-server.sh /usr/bin/shiny-server.sh
RUN ["chmod", "+x", "/usr/bin/shiny-server.sh"]
ENV AUTH0_USER="user" \
AUTH0_KEY="key" \
AUTH0_SECRET="secret"
# run app
CMD ["/usr/bin/shiny-server.sh"]
我的 _auth0.yml 文件如下所示:
remote_url: ''
auth0_config:
api_url: !expr paste0('https://', Sys.getenv("AUTH0_USER"), '.auth0.com')
credentials:
key: !expr Sys.getenv("AUTH0_KEY")
secret: !expr Sys.getenv("AUTH0_SECRET")
编辑:我在这里读到 (https://groups.google.com/g/shiny-discuss/c/nNs0kztwdWo/m/90InjZXfAPEJ) 启动 R 时不会读取环境变量。那么怎么会这个解决方案真的有效吗? https://github.com/curso-r/auth0
所以从技术上讲,我想出了解决这个问题的方法。我在项目的根目录下创建了一个“.Renviron”文件,将所有环境变量保存在该文件中,然后将其复制到我的 docker 图像中。
当我启动我的容器时,我能够成功地运行我的应用程序,使用 .Renviron 提供的数据,以便应用程序可以连接到 auth0 以验证用户。
现在我需要弄清楚如何将此文件传递给 docker 容器,以便安全地提取此 .Renviron 文件,而不必像 github.