0

Is it possible to programmatically set a different profile for every instance of a spring boot application deployed in cloud foundry using for example ConfigurableEnvironment and cloud foundry instance index?

Moam
  • 176
  • 2
  • 16
  • What is your use case for this? You really don't want to have instances of an application that function differently. Each application you push to CF can have one or more instances and those instances should be exactly the same. If you want different behavior, you should push multiple applications. – Daniel Mikusa Nov 15 '17 at 01:49
  • instances have the same functions except that the profiles will be used to load configurations for running two or more bath job. Eatch job will run on it s own instance. – Moam Nov 15 '17 at 02:16
  • how about using quartz scheduler in clustered mode to spread the execution over all instances? If you hard-code which instance is running which job you have a problem if an instance goes down. – NOTtardy Nov 15 '17 at 06:30

1 Answers1

0

I would suggest that you look into using tasks.

https://docs.cloudfoundry.org/devguide/using-tasks.html

Here's roughly how this would work.

  1. Run cf push to deploy your application to CF. If you do not actually have an application to run, that is OK. You just need to push the app and start it once so that it stages and creates a droplet. After that, you can run cf stop to shutdown the instance (note: cf push --no-start won't work, because the app needs to stage at least once).

  2. Run cf run-task <app> <command>. This is where you kick off your batch jobs. The <command> argument is going to be the full command to run your batch job. In this, you can include an argument to indicate the profiles that should be used. Ex: --spring.profiles.active=dev,hsqldb.

    https://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-profiles.html

    You need to use the full or relative path to the java exceutable because the Java buildpack does not put it onto the path. If you wanted to run a task that printed the version of the JVM, you'd use this command '.java-buildpack/open_jdk_jre/bin/java -version'.

    Ex: cf run-task <app> '.java-buildpack/open_jdk_jre/bin/java -version'

    See this SO post though for drawbacks of hardcoding the path to the Java executable in your command. My suggestion would be to take the command that's listed when you run cf push and modify to your needs.

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