Environment variables inside application.yml

Hi,

I noticed that environment variables can be used inside the application.yml using sping’s SpEL.
However, this works on most parts, but not when setting the image of an application. See dummy application.yml

debug: true
proxy:
  title: ShinyProxy
  landing-page: /
  heartbeat-rate: 10000
  heartbeat-timeout: 60000
  port: 8080
  authentication: simple
  admin-groups: admin
  users:
  - name: admin
    password: admin
    groups: admin
  - name: user
    password: user
    groups: user
  # Docker configuration
  docker:
internal-networking: true
  support:
container-log-path: ./container-logs
  specs:
  - id: 01_hello
display-name: Hello Application
description: Application which demonstrates the basics of a Shiny app
container-cmd: ["R", "-e", "shinyproxy::run_01_hello()"]
container-image: "openanalytics/shinyproxy-demo:${branch}"
container-network: "${network}"
access-groups: admin

logging:
  file:
./shinyproxy-log/shinyproxy.log

So I am trying to use environment variables to set the branch and other fields in the application.yml. All that I have testes so far work, except the image.

all these environment variables are passed in the docker compose

I made an open source solution for this, maybe it could help you? It does bash-interp on an application.yml.template file and actually creates a new applicaiton.yml on each container startup (using ENV vars):

You can pull the Dockerfile and start.sh, then make your own application.yml.template file… though make sure to escape bash-interpreted characters like quotes/parens/etc

2 Likes

Hi @gbisschoff,

You can indeed use expressions in the yaml, but there is an important distinction to make:

  • Property expressions (with the dollar notation) are parsed by Spring Boot’s externalized configuration system, when ShinyProxy starts up.

  • SpEl expressions (with the hash notation) are parsed by SpEL, when a proxy is launched. More info here.

That being said, I’m not sure why the expression would fail in the container-image setting. I just tested with an expression like this, and its value got inserted correctly:

container-image: "openanalytics/shinyproxy-demo/${TEMP}/abcdef"
1 Like

Hi @SudoBrendan,

Thanks for sharing this, it looks interesting!

Hi @fmichielssen,
I am trying to use environment variables to set up simple authentication. I am passing the username and pass to the shinyproxy container (swarm backend) and can check the values in it but the authentication fails when I try to log in. Is there any limit in using the environment variables for authentication?