Skip to content

Commit

Permalink
Added a --force flag (fixes #46)
Browse files Browse the repository at this point in the history
It passes -force to packer which overwrites temporary build artifacts
and it passes --force to `vagrant box add` which allows a pre-existing
box to be overwritten.
  • Loading branch information
obilodeau committed Jul 13, 2017
1 parent 3e6273f commit b853ca7
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,12 @@ For a detailed view of what has changed, refer to the {uri-repo}/commits/master[
Enhancements::
* New profile: Windows 7 64-bit: win7_64_analyst (#42)
* Support for trial versions of Windows 7 Enterprise x86 and x64
* debug: Passes -on-error=abort to packer to allow investigation of failures (#35)
* Better out of the box support of Fedora, CentOS and RedHat as host (#53)
* Use user cache directories for packer. This avoids caching in memory-backed locations to
prevent unnecessary memory pressure during builds or free space issues on
low RAM systems (#45)
* Added a --force flag to overwrite pre-existing packer artifacts or vagrant boxes (#46)
* debug: Passes -on-error=abort to packer to allow investigation of failures (#35)
* Documentation improvements

Bug fixes::
Expand Down
14 changes: 13 additions & 1 deletion malboxes/malboxes.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ def init_parser():
parser_build.add_argument('profile', help='Name of the profile to build. '
'Use list command to view '
'available profiles.')
parser_build.add_argument('--force', action='store_true',
help='Force the build to happen. Overwrites '
'pre-existing builds or vagrant boxes.')
parser_build.add_argument('--skip-packer-build', action='store_true',
help='Skip packer build phase. '
'Only useful for debugging.')
Expand Down Expand Up @@ -326,6 +329,9 @@ def run_packer(packer_tmpl, args):
special_env['PACKER_LOG'] = '1'
flags.append('-on-error=abort')

if args.force:
flags.append('-force')

cmd = [binary, 'build']
cmd.extend(flags)
cmd.append(packer_tmpl)
Expand All @@ -347,7 +353,13 @@ def add_box(config, args):
box = os.path.join(DIRS.user_cache_dir, box)
box = box.replace('{{user `name`}}', args.profile)

cmd = ['vagrant', 'box', 'add', box, '--name={}'.format(args.profile)]
flags = ['--name={}'.format(args.profile)]
if args.force:
flags.append('--force')

cmd = ['vagrant', 'box', 'add']
cmd.extend(flags)
cmd.append(box)
ret = run_foreground(cmd)

print("----------------------------")
Expand Down

0 comments on commit b853ca7

Please sign in to comment.