2

I have a question about an application based on CloudFoundry. Until now we had random routes (via ports) on any environment. Now there is a requirement that on each environment (dev, test, prod) always the same port is used, so that the recipients do not have to change the URL every time. So far we do this after each deployment via the console via "cf map-route ..." .

Is there any way to do this statically via config/yaml file? Is it possible to specify environment specific variables in the YAML? Example:

  - name: odata_kbs_sv-app
    type: html5
    path: app
    parameters:
    port: ~{specificPort}
    [...]
    when space = 'DEV' then specificPort = 55555 etc.

thanks.

Tobias
  • 4,921
  • 4
  • 31
  • 40

1 Answers1

2

You can set a static port for a route in your manifest.yml file. In the routes block, add a route with a port.

Ex:

---
  ...
  routes:
  - route: tcp-example.com:1234

https://docs.cloudfoundry.org/devguide/deploy-apps/manifest-attributes.html#routes

If you have the same port across all of your environments, you can stop here. If you need to use different fixed ports for each environment, then keep reading.

You cannot do any form of logic or branching within a manifest.yml file, but what you can do is use manifest variables.

Ex:

---
  ...
  routes:
  - route: tcp-example.com:((port))

https://docs.cloudfoundry.org/devguide/deploy-apps/manifest-attributes.html#variable-substitution

When you cf push, you then need to either set --var port=8080 or you need to set --vars-file=file/with/vars.

Taking this a bit further, when using --var port=, you could use shell environment variables or shell logic to control what port value is used, or you could reference different --vars-file files per environment. It ends up being pretty flexible.

Daniel Mikusa
  • 13,716
  • 1
  • 22
  • 28