Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
P
packer
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kristopher Ruzic
packer
Commits
2788ccc6
Commit
2788ccc6
authored
Sep 02, 2014
by
Mitchell Hashimoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update scripts to latest HashiCorp style
parent
db906582
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
151 additions
and
174 deletions
+151
-174
Makefile
Makefile
+13
-32
README.md
README.md
+31
-27
scripts/build.sh
scripts/build.sh
+77
-0
scripts/devcompile.sh
scripts/devcompile.sh
+0
-67
scripts/dist.sh
scripts/dist.sh
+30
-48
No files found.
Makefile
View file @
2788ccc6
NO_COLOR
=
\0
33[0m
OK_COLOR
=
\0
33[32
;
01m
ERROR_COLOR
=
\0
33[31
;
01m
WARN_COLOR
=
\0
33[33
;
01m
DEPS
=
$
(
go list
-f
'{{range .TestImports}}{{.}} {{end}}'
./...
)
UNAME
:=
$(
shell
uname
-s
)
ifeq
($(UNAME),Darwin)
ECHO
=
echo
else
ECHO
=
/bin/echo
-e
endif
TEST
?=
./...
all
:
deps
@
mkdir
-p
bin/
@
$(ECHO)
"
$(OK_COLOR)
==> Building
$(NO_COLOR)
"
@
bash
--norc
-i
./scripts/devcompile.sh
default
:
test
deps
:
@
$(ECHO)
"
$(OK_COLOR)
==> Installing dependencies
$(NO_COLOR)
"
@
go get
-d
-v
./...
@
go get github.com/mitchellh/gox
@
echo
$(DEPS)
| xargs
-n1
go get
-d
bin
:
@
sh
-c
"
$(CURDIR)
/scripts/build.sh"
updatedeps
:
@
$(ECHO)
"
$(OK_COLOR)
==> Updating all dependencies
$(NO_COLOR)
"
@
go get
-d
-v
-u
./...
@
echo
$(DEPS)
| xargs
-n1
go get
-d
-u
dev
:
@
TF_DEV
=
1 sh
-c
"
$(CURDIR)
/scripts/build.sh"
clean
:
@
rm
-rf
bin/
local
/ pkg/ src/ website/.sass-cache website/build
test
:
go
test
$(TEST)
$(TESTARGS)
-timeout
=
10s
format
:
go
fmt
./...
testrace
:
go
test
-race
$(TEST)
$(TESTARGS)
test
:
deps
@
$(ECHO)
"
$(OK_COLOR)
==> Testing Packer...
$(NO_COLOR)
"
go
test
./...
updatedeps
:
go get
-u
-v
./...
.PHONY
:
all clean deps forma
t test updatedeps
.PHONY
:
bin defaul
t test updatedeps
README.md
View file @
2788ccc6
...
...
@@ -78,40 +78,44 @@ http://www.packer.io/docs
## Developing Packer
If you wish to work on Packer itself, you'll first need
[
Go
](
http://golang.org
)
installed (version 1.2+ is _required_). Make sure you have Go properly installed,
including setting up your
[
GOPATH
](
http://golang.org/doc/code.html#GOPATH
)
.
If you wish to work on Packer itself or any of its built-in providers,
you'll first need
[
Go
](
http://www.golang.org
)
installed (version 1.2+ is
_required_
). Make sure Go is properly installed, including setting up
a
[
GOPATH
](
http://golang.org/doc/code.html#GOPATH
)
.
For some additional dependencies, Go needs
[
Mercurial
](
http://mercurial.selenic.com/
)
and
[
Bazaar
](
http://bazaar.canonical.com/en/
)
to be installed.
Packer itself doesn't require these, but a dependency of a dependency does.
Next, install the following software packages, which are needed for some dependencies:
You'll also need
[
`gox`
](
https://github.com/mitchellh/gox
)
to compile packer. You can install that with:
-
[
Bazaar
](
http://bazaar.canonical.com/en/
)
-
[
Git
](
http://git-scm.com/
)
-
[
Mercurial
](
http://mercurial.selenic.com/
)
```
$ go get -u github.com/mitchellh/gox
```
Then, install
[
Gox
](
https://github.com/mitchellh/gox
)
, which is used
as a compilation tool on top of Go:
Next, clone this repository into
`$GOPATH/src/github.com/mitchellh/packer`
and
then just type
`make`
. In a few moments, you'll have a working
`packer`
executable:
$ go get -u github.com/mitchellh/gox
```
$ make
...
$ bin/packer
...
```
Next, clone this repository into
`$GOPATH/src/github.com/mitchellh/packer`
.
Install the necessary dependencies by running
`make updatedeps`
and then just
type
`make`
. This will compile some more dependencies and then run the tests. If
this exits with exit status 0, then everything is working!
$ make updatedeps
...
$ make
...
If you need to cross-compile Packer for other platforms, take a look at
`scripts/dist.sh`
.
To compile a development version of Packer and the built-in plugins,
run
`make dev`
. This will put Packer binaries in the
`bin`
folder:
You can run tests by typing
`make test`
.
$ make dev
...
$ bin/packer
...
This will run tests for Packer core along with all the core builders and commands and such that come with Packer.
If you make any changes to the code, run
`make format`
in order to automatically
format the code according to Go standards.
If you're developing a specific package, you can run tests for just that
package by specifying the
`TEST`
variable. For example below, only
`packer`
package tests will be run.
When new dependencies are added to packer you can use
`make updatedeps`
to
get the latest and subsequently use
`make`
to compile and generate the
`packer`
binary
.
$ make test TEST=./packer
..
.
scripts/
compile
.sh
→
scripts/
build
.sh
View file @
2788ccc6
#!/bin/bash
#
# This script compiles Packer for various platforms (specified by the
# PACKER_OS and PACKER_ARCH environmental variables).
# This script builds the application from source for multiple platforms.
set
-e
NO_COLOR
=
"
\x
1b[0m"
OK_COLOR
=
"
\x
1b[32;01m"
ERROR_COLOR
=
"
\x
1b[31;01m"
WARN_COLOR
=
"
\x
1b[33;01m"
# Get the parent directory of where this script is.
SOURCE
=
"
${
BASH_SOURCE
[0]
}
"
while
[
-h
"
$SOURCE
"
]
;
do
SOURCE
=
"
$(
readlink
"
$SOURCE
"
)
"
;
done
...
...
@@ -25,28 +19,59 @@ GIT_DIRTY=$(test -n "`git status --porcelain`" && echo "+CHANGES" || true)
XC_ARCH
=
${
XC_ARCH
:-
"386 amd64 arm"
}
XC_OS
=
${
XC_OS
:-
linux
darwin windows freebsd openbsd
}
# Make sure that if we're killed, we kill all our subprocseses
trap
"kill 0"
SIGINT SIGTERM EXIT
echo
-e
"
${
OK_COLOR
}
==> Installing dependencies to speed up builds...
${
NO_COLOR
}
"
# Install dependencies
echo
"==> Getting dependencies..."
go get ./...
echo
-e
"
${
OK_COLOR
}
==> Beginning compile...
${
NO_COLOR
}
"
rm
-rf
pkg/
# Delete the old dir
echo
"==> Removing old directory..."
rm
-f
bin/
*
rm
-rf
pkg/
*
mkdir
-p
bin/
# If its dev mode, only build for ourself
if
[
"
${
TF_DEV
}
x"
!=
"x"
]
;
then
XC_OS
=
$(
go
env
GOOS
)
XC_ARCH
=
$(
go
env
GOARCH
)
fi
# Build!
echo
"==> Building..."
gox
\
-os
=
"
${
XC_OS
}
"
\
-arch
=
"
${
XC_ARCH
}
"
\
-ldflags
"-X
github.com/mitchellh/packer/packer
.GitCommit
${
GIT_COMMIT
}${
GIT_DIRTY
}
"
\
-ldflags
"-X
main
.GitCommit
${
GIT_COMMIT
}${
GIT_DIRTY
}
"
\
-output
"pkg/{{.OS}}_{{.Arch}}/packer-{{.Dir}}"
\
./...
# Make sure "packer-packer" is renamed properly
for
PLATFORM
in
$(
find ./pkg
-mindepth
1
-maxdepth
1
-type
d
)
;
do
set
+e
mv
${
PLATFORM
}
/packer-packer
*
.exe
${
PLATFORM
}
/packer.exe
2>/dev/null
mv
${
PLATFORM
}
/packer-packer
*
${
PLATFORM
}
/packer 2>/dev/null
mv
${
PLATFORM
}
/packer-packer
${
PLATFORM
}
/packer
2>/dev/null
mv
${
PLATFORM
}
/packer-packer
${
PLATFORM
}
/packer 2>/dev/null
set
-e
done
# Reset signal trapping to avoid "Terminated: 15" at the end
trap
- SIGINT SIGTERM EXIT
# Copy our OS/Arch to the bin/ directory
DEV_PLATFORM
=
"./pkg/
$(
go
env
GOOS
)
_
$(
go
env
GOARCH
)
"
for
F
in
$(
find
${
DEV_PLATFORM
}
-mindepth
1
-maxdepth
1
-type
f
)
;
do
cp
${
F
}
bin/
done
if
[
"
${
TF_DEV
}
x"
=
"x"
]
;
then
# Zip and copy to the dist dir
echo
"==> Packaging..."
for
PLATFORM
in
$(
find ./pkg
-mindepth
1
-maxdepth
1
-type
d
)
;
do
OSARCH
=
$(
basename
${
PLATFORM
}
)
echo
"-->
${
OSARCH
}
"
pushd
$PLATFORM
>
/dev/null 2>&1
zip ../
${
OSARCH
}
.zip ./
*
popd
>
/dev/null 2>&1
done
fi
# Done!
echo
echo
"==> Results:"
ls
-hl
bin/
scripts/devcompile.sh
deleted
100755 → 0
View file @
db906582
#!/bin/bash
#
# This script only builds the application from source.
set
-e
NO_COLOR
=
"
\x
1b[0m"
OK_COLOR
=
"
\x
1b[32;01m"
ERROR_COLOR
=
"
\x
1b[31;01m"
WARN_COLOR
=
"
\x
1b[33;01m"
# http://stackoverflow.com/questions/4023830/bash-how-compare-two-strings-in-version-format
verify_go
()
{
if
[[
$1
==
$2
]]
;
then
return
0
fi
if
[[
"
$2
"
==
"devel"
]]
;
then
return
0
fi
local
IFS
=
.
local
i
ver1
=(
$1
)
ver2
=(
$2
)
for
((
i
=
${#
ver1
[@]
}
;
i<
${#
ver2
[@]
}
;
i++
))
;
do
ver1[i]
=
0
done
for
((
i
=
0
;
i<
${#
ver1
[@]
}
;
i++
))
;
do
if
[[
-z
${
ver2
[i]
}
]]
;
then
ver2[i]
=
0
fi
if
((
10#
${
ver1
[i]
}
>
10#
${
ver2
[i]
}
))
;
then
echo
-e
"
${
ERROR_COLOR
}
==> Required Go version
$1
not installed. Found
$2
instead"
exit
1
fi
done
}
GO_MINIMUM_VERSION
=
1.2
GO_INSTALLED_VERSION
=
$(
go version |
cut
-d
' '
-f
3
)
GO_INSTALLED_VERSION
=
${
GO_INSTALLED_VERSION
#
"go"
}
echo
-e
"
${
OK_COLOR
}
==> Verifying Go"
verify_go
$GO_MINIMUM_VERSION
$GO_INSTALLED_VERSION
# Get the parent directory of where this script is.
SOURCE
=
"
${
BASH_SOURCE
[0]
}
"
while
[
-h
"
$SOURCE
"
]
;
do
SOURCE
=
"
$(
readlink
"
$SOURCE
"
)
"
;
done
DIR
=
"
$(
cd
-P
"
$(
dirname
"
$SOURCE
"
)
/.."
&&
pwd
)
"
# Change into that directory
cd
$DIR
# Compile the thing
export
XC_ARCH
=
$(
go
env
GOARCH
)
export
XC_OS
=
$(
go
env
GOOS
)
./scripts/compile.sh
# Move all the compiled things to the PATH
case
$(
uname
)
in
CYGWIN
*
)
GOPATH
=
"
$(
cygpath
$GOPATH
)
"
;;
esac
IFS
=
:
MAIN_GOPATH
=(
$GOPATH
)
cp
pkg/
${
XC_OS
}
_
${
XC_ARCH
}
/
*
${
MAIN_GOPATH
}
/bin
cp
pkg/
${
XC_OS
}
_
${
XC_ARCH
}
/
*
./bin
scripts/dist.sh
View file @
2788ccc6
#!/bin/bash
set
-e
# Get the version from the command line
VERSION
=
$1
if
[
-z
$VERSION
]
;
then
echo
"Please specify a version."
exit
1
fi
# Make sure we have a bintray API key
if
[
-z
$BINTRAY_API_KEY
]
;
then
echo
"Please set your bintray API key in the BINTRAY_API_KEY env var."
exit
1
fi
# Get the parent directory of where this script is.
SOURCE
=
"
${
BASH_SOURCE
[0]
}
"
while
[
-h
"
$SOURCE
"
]
;
do
SOURCE
=
"
$(
readlink
"
$SOURCE
"
)
"
;
done
...
...
@@ -9,59 +22,28 @@ DIR="$( cd -P "$( dirname "$SOURCE" )/.." && pwd )"
# Change into that dir because we expect that
cd
$DIR
# Determine the version that we're building based on the contents
# of packer/version.go.
VERSION
=
$(
grep
"const Version "
packer/version.go |
sed
-E
's/.*"(.+)"$/\1/'
)
VERSIONDIR
=
"
${
VERSION
}
"
PREVERSION
=
$(
grep
"const VersionPrerelease "
packer/version.go |
sed
-E
's/.*"(.*)"$/\1/'
)
if
[
!
-z
$PREVERSION
]
;
then
PREVERSION
=
"
${
PREVERSION
}
.
$(
date
-u
+%s
)
"
VERSIONDIR
=
"
${
VERSIONDIR
}
-
${
PREVERSION
}
"
fi
# This function waits for all background tasks to complete
waitAll
()
{
RESULT
=
0
for
job
in
`
jobs
-p
`
;
do
wait
$job
if
[
$?
-ne
0
]
;
then
RESULT
=
1
fi
done
if
[
$RESULT
-ne
0
]
;
then
exit
$RESULT
fi
}
# Compile the main project
./scripts/compile.sh
# Make sure that if we're killed, we kill all our subprocseses
trap
"kill 0"
SIGINT SIGTERM EXIT
# Zip all the packages
# Zip all the files
rm
-rf
./pkg/dist
mkdir
-p
./pkg/dist
for
PLATFORM
in
$(
find ./pkg
-mindepth
1
-maxdepth
1
-type
d
)
;
do
PLATFORM_NAME
=
$(
basename
${
PLATFORM
}
)
ARCHIVE_NAME
=
"
${
VERSIONDIR
}
_
${
PLATFORM_NAME
}
"
if
[
$PLATFORM_NAME
=
"dist"
]
;
then
continue
fi
(
pushd
${
PLATFORM
}
zip
${
DIR
}
/pkg/dist/
${
ARCHIVE_NAME
}
.zip ./
*
popd
)
&
for
FILENAME
in
$(
find ./pkg
-mindepth
1
-maxdepth
1
-type
f
)
;
do
FILENAME
=
$(
basename
$FILENAME
)
cp
./pkg/
${
FILENAME
}
./pkg/dist/packer_
${
VERSION
}
_
${
FILENAME
}
done
waitAll
# Make the checksums
pushd
./pkg/dist
shasum
-a256
*
>
./
${
VERSIONDIR
}
_SHA256SUMS
shasum
-a256
*
>
./
packer_
${
VERSION
}
_SHA256SUMS
popd
# Upload
for
ARCHIVE
in
./pkg/dist/
*
;
do
ARCHIVE_NAME
=
$(
basename
${
ARCHIVE
}
)
echo
Uploading:
$ARCHIVE_NAME
curl
\
-T
${
ARCHIVE
}
\
-umitchellh
:
${
BINTRAY_API_KEY
}
\
"https://api.bintray.com/content/mitchellh/packer/packer/
${
VERSION
}
/
${
ARCHIVE_NAME
}
"
done
exit
0
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment