image: Moving $BUILD_DIR check at the beginning of the script