-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpacker-build.ps1
46 lines (34 loc) · 1.06 KB
/
packer-build.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# set variables
$BUILDDIR = "./vagrant_build_dir"
$VAGRANTFILETMPL = "./packer/files-prov/template/Vagrantfile"
$SSHKEY = "./packer/files-prov/ssh/insecure_public_key"
$OUTPUTFILE = "package.box"
$APPLICATIONFILE = "installed-application.md"
# delete build directory
if (Test-Path -LiteralPath $BUILDDIR) {
Remove-Item "$BUILDDIR" -Recurse
}
# create build directory
New-Item -ItemType "directory" -Path "$BUILDDIR" | Out-Null
# copy Vagrantfile template
Copy-Item "$VAGRANTFILETMPL" -Destination "$BUILDDIR"
# copy ssh key
Copy-Item "$SSHKEY" -Destination "$BUILDDIR"
# save location
Push-Location
# start vagrant in build directory
cd $BUILDDIR
vagrant up
# export vagrant box
vagrant halt
vagrant package --output $OUTPUTFILE
# destroy vagrant
vagrant destroy -f
# restore location
Pop-Location
# copy installed-application.md
Copy-Item "$BUILDDIR/$APPLICATIONFILE" -Destination "."
# run packer for vagrant virtualbox provider
packer build packer-virtualbox.json
# delete build directory
Remove-Item "$BUILDDIR" -Recurse