I am trying to get the build number available in the php instance. I will use it as a type of "cache-buster" for the static assets (css, js). Is there any way to get it at run time? If not, is there a way to get it at build time in the postinstall script?
Is there any way to get the build number in the environment or at build-time for a php instance?
60 Views Asked by Dmitry Grekov At
1
I see a couple of ways you could do this.
/home/dotcloud/
the code directory is a symlink to the build version, so for example my code directory points togit-16ae997
. In yourpostinstall
script if you get the name of that directory and store it in a temp file, env variable, or maybe inject it into one of your config scripts, you could reference it from your program.Putting this in your
postinstall
script will add theBUILD_VERSION
variable to your.profile
and be available to you from$BUILD_VERSION
in a shell, or other languages. You might need to re-source the.profile
after you make the change to be sure it gets set.With PHP you should be able to get it at runtime with the following variable.
Another approach I have used myself on other projects is to create .version file in the postinstall that just includes the timestamp of the build, and reference that file for the build_version and use it as your cache-buster. The problem with this approach is because it is created at
postinstall
if you scale above 1 instance, you will most likely end up with different timestamps for each instance, and I'm guessing this isn't what you want.$ date '+%s' > /home/dotcloud/.version
I would stick with #1 since it works when you scale, and it is more strait forward.
Hope that helps.