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?
1 Answers
I see a couple of ways you could do this.
- In
/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 the BUILD_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.
$ echo "export BUILD_VERSION=`readlink /home/dotcloud/code`" >> /home/dotcloud/.profile
$ echo $BUILD_VERSION
With PHP you should be able to get it at runtime with the following variable.
$_ENV["BUILD_VERSION"]
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.

- 75,357
- 9
- 52
- 60
-
Thank you, that worked marvelously. I ended up adding it to my postinstall script where I modified my config file with the current build number. – Dmitry Grekov May 24 '12 at 02:02