Is there any kind of ASSERT in Docker?
In this specific case I want to be able to validate that an environment variable has been set and force the build to fail if it hasn't.
The code that has caused me issues is:
echo ${LICENSE_KEY} > /etc/license.key
I have been tasked with getting a previous employee's code working correctly and have found that this file was empty. It strikes me that this variable being unset should be fatal for this build script and would have saved me lots of debugging.
From my reading of the Docker docs (since Docker 0.7) I can run a shell command that returns a non zero status and that would cause the build to fail. e.g.
RUN [ ! -z "${LICENSE_KEY}" ]
Though this will cause extra layers and code in the image, that may not be obvious to others that it is just there for debugging/protection and does not explicitly state the reason for the failure when combined with other commands. I was really expecting docker to have something akin to:
ASSERT ${LICENSE_KEY} != ""
I had a similar problem, and I did something like:
RUN [ ! -z "${LICENSE_KEY}" ] || { echo "License key cannot be empty"; exit 1; } && \
... other run commands ...