Add --nocache to build docker from scratch

This commit is contained in:
Jin Li 2017-04-24 12:18:46 -07:00
Родитель c940b27250
Коммит d23ed23abe
3 изменённых файлов: 23 добавлений и 9 удалений

Просмотреть файл

@ -28,9 +28,13 @@ if __name__ == '__main__':
help="Tag of the docker build, or [current]",
action = "store",
default = "current" )
parser.add_argument("--nocache",
help="Tag of the docker build, or [current]",
action = "store_true")
args = parser.parse_args()
dockerprefix = args.prefix
dockertag = args.tag
dockername = dockerprefix + ":" + dockertag
dockername = build_docker(dockername, dirname)
#print args.nocache
dockername = build_docker(dockername, dirname, nocache = args.nocache)
run_docker(dockername, "DevDocker")

Просмотреть файл

@ -45,6 +45,7 @@ coreosversion = "1235.9.0"
coreoschannel = "stable"
coreosbaseurl = ""
verbose = False
nocache = False
# These are the default configuration parameter
default_config_parameters = {
@ -1803,13 +1804,13 @@ def build_docker_images(nargs):
render_docker_images()
if verbose:
print "Build docker ..."
build_dockers("./deploy/docker-images/", config["dockerprefix"], config["dockertag"], nargs, verbose)
build_dockers("./deploy/docker-images/", config["dockerprefix"], config["dockertag"], nargs, verbose, nocache = nocache )
def push_docker_images(nargs):
render_docker_images()
if verbose:
print "Build & push docker images to docker register ..."
push_dockers("./deploy/docker-images/", config["dockerprefix"], config["dockertag"], nargs, config, verbose)
push_dockers("./deploy/docker-images/", config["dockerprefix"], config["dockertag"], nargs, config, verbose, nocache = nocache )
def run_docker_image( imagename, native = False ):
full_dockerimage_name = build_docker_fullname( config, imagename )
@ -1920,6 +1921,10 @@ Command:
parser.add_argument("-v", "--verbose",
help = "verbose print",
action="store_true")
parser.add_argument("--nocache",
help = "Build docker without cache",
action="store_true")
parser.add_argument("--glusterfs",
help = textwrap.dedent('''"Additional glusterfs launch parameter, \
detach: detach all glusterfs nodes (to rebuild cluster),
@ -1935,6 +1940,8 @@ Command:
help="Additional command argument",
)
args = parser.parse_args()
nocache = args.nocache
# If necessary, show parsed arguments.
# print args
discoverserver = args.discoverserver

Просмотреть файл

@ -12,12 +12,15 @@ import grp
from os.path import expanduser
from DirectoryUtils import cd
def build_docker( dockername, dirname, verbose=False):
def build_docker( dockername, dirname, verbose=False, nocache=False ):
# docker name is designed to use lower case.
dockername = dockername.lower()
if verbose:
print "Building docker ... " + dockername + " .. @" + dirname
with cd(dirname):
if nocache:
cmd = "docker build --no-cache -t "+ dockername + " ."
else:
cmd = "docker build -t "+ dockername + " ."
os.system(cmd)
return dockername
@ -128,18 +131,18 @@ def get_docker_list(rootdir, dockerprefix, dockertag, nargs, verbose = False ):
docker_list[dockername] = ( basename, entry )
return docker_list
def build_dockers(rootdir, dockerprefix, dockertag, nargs, verbose = False ):
def build_dockers(rootdir, dockerprefix, dockertag, nargs, verbose = False, nocache = False ):
docker_list = get_docker_list(rootdir, dockerprefix, dockertag, nargs, verbose )
for dockername, tuple in docker_list.iteritems():
build_docker(dockername, tuple[1], verbose)
build_docker(dockername, tuple[1], verbose, nocache = nocache )
def push_dockers(rootdir, dockerprefix, dockertag, nargs, config, verbose = False ):
def push_dockers(rootdir, dockerprefix, dockertag, nargs, config, verbose = False, nocache = False ):
infra_dockers = config["infrastructure-dockers"] if "infrastructure-dockers" in config else {}
infra_docker_registry = config["infrastructure-dockerregistry"] if "infrastructure-dockerregistry" in config else config["dockerregistry"]
worker_docker_registry = config["worker-dockerregistry"] if "worker-dockerregistry" in config else config["dockerregistry"]
docker_list = get_docker_list(rootdir, dockerprefix, dockertag, nargs, verbose );
for dockername, tuple in docker_list.iteritems():
build_docker(dockername, tuple[1], verbose)
build_docker(dockername, tuple[1], verbose, nocache = nocache )
if tuple[0] in infra_dockers:
if verbose:
print "Push to infrastructure docker register %s with name %s" % ( infra_docker_registry , dockername )