cloudcaptainsh / cloudcaptain

Issue Tracker for CloudCaptain
13 stars 3 forks source link

Deployed -envvars not shown or used by console. #193

Open knocknarea opened 6 years ago

knocknarea commented 6 years ago

As part of our automated build process we fuse and then run out spring boot image with an additional command line environment variable via

-envvars.SPRING_PROFILES_ACTIVE=[deployment]

We let boxfuse look after the database configuration but supply an additional spring profile for services that the application connects to based on different deployment scenarios

It all works fine in the build and deploy stage.

If I want to subsequently scale the application I can go to the boxfuse console, however...

If I scale the node there, what actually gets executed (the additional node that is spun up) does not have the envvars set as the initial node that was created when the application was run via the command line.

This means that the scaled nodes are not properly configured for the environment they are executing in.

Why is this? Surely when I run boxfuse in a particular environment, it should remember what the configuration for the images is (in that environment)

The deployment script looks like this:

case $ENV in
    dev|local)
    CONF_OPT="-configfile=$PROJECT_LOC/deployment/boxfuse/boxfuse-dev.conf"
    SPRING_OPT="-envvars.SPRING_PROFILES_ACTIVE=dev"
    ;;
    stage)
    CONF_OPT="-configfile=$PROJECT_LOC/deployment/boxfuse/boxfuse-stage.conf"
    SPRING_OPT="-envvars.SPRING_PROFILES_ACTIVE=stage"
    ;;
    production)
    CONF_OPT=""
    ;;  
esac

if [ ! -z "$CONF_OPT" ]; then
    echo "Fusing $BOXFUSE_JAR -> Selecting Boxfuse Version $BOXFUSE_VER"

    boxfuse fuse $BOXFUSE_JAR "$CONF_OPT" -image=$BOXFUSE_VER || { echo "Unable to fuse boxfuse image $BOXFUSE_VER"; exit 1; }

    echo "Deploying to $ENV with options: $CONF_OPT"

    boxfuse -X run "$CONF_OPT" "$SPRING_OPT" "$BOXFUSE_VER" || { echo "Unable to run boxfuse image $BOXFUSE_VER with $ENV_OPT"; exit 1; }
fi

The key element here is the $SPRING_OPT value is not preserved so that it is acted on when using the console.

Your advice on what to do would be much appreciated.

axelfontaine commented 6 years ago

You are correct that environment variables added during run are not currently persisted for subsequent runs. The scenario that you describe does make sense though. Until we come up with a solution for this, your best workaround for passing the Spring profile is probably to use the system property as described here: https://boxfuse.com/docs/payloads/springboot#profiles

Make sure to include those JVM args when fusing the image. This way they will be baked into the image and the scaling scenario you described will work out of the box without issues.

knocknarea commented 6 years ago

Ok I'll try that. Thanks for the help @axelfontaine