FYI - I am an absolute newbie when it comes to shiny apps, but I am trying to help a shiny app developer deploy their app using a docker container (also a newbie with docker but I've done a few of them so I understand what is going on).
I have a shiny app, being deployed on a shiny-server in a docker container. This shiny app is using auth0, and I am following this write up (https://github.com/curso-r/auth0) so that the _auth0.yml file will get its secrets from environment variables.
Problem lies in how to correctly setup those environment variables in the docker container so that my _auth0.yml file will be populated with their values? Any help would be greatly appreciated!
I have tried setting "ENV" in my Dockerfile,
ENV AUTH0_USER="user" \
AUTH0_KEY="key" \
AUTH0_SECRET="secret"
If I do that, and -it into my docker container, I see that the environment variables are set, but when I run the application, the environment variable doesn't populate the "api_url", and it tries to go to "https://.auth0.com/authorize?client_id=&scope=openid%20profile&redirect_uri=http%3A%2F%2Flocalhost%3A3838&response_type=code&state=LmNvuzzUB8"
My Dockerfile looks like this:
#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"]
My _auth0.yml file looks like this:
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")
EDIT: I read here (https://groups.google.com/g/shiny-discuss/c/nNs0kztwdWo/m/90InjZXfAPEJ) that environment variables are not read when launching R. So how would this solution actually work? https://github.com/curso-r/auth0
So technically, I figured out how to solve this. I created an ".Renviron" file at the root of my project, saved all of my environment variables in the file, then copied it into my docker image.
When I started my container, I was able to successfully run my application, with the data from the .Renviron supplied so that the app could connect to auth0 to authenticate user.
Now I need to figure out how to pass in this file to the docker container so that this .Renviron file gets pulled in securely, and not have to check this into a repo like github.