Update scripts to latest HashiCorp style
This commit is contained in:
parent
db90658250
commit
2788ccc653
49
Makefile
49
Makefile
|
@ -1,39 +1,20 @@
|
|||
NO_COLOR=\033[0m
|
||||
OK_COLOR=\033[32;01m
|
||||
ERROR_COLOR=\033[31;01m
|
||||
WARN_COLOR=\033[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"
|
||||
|
||||
dev:
|
||||
@TF_DEV=1 sh -c "$(CURDIR)/scripts/build.sh"
|
||||
|
||||
test:
|
||||
go test $(TEST) $(TESTARGS) -timeout=10s
|
||||
|
||||
testrace:
|
||||
go test -race $(TEST) $(TESTARGS)
|
||||
|
||||
updatedeps:
|
||||
@$(ECHO) "$(OK_COLOR)==> Updating all dependencies$(NO_COLOR)"
|
||||
@go get -d -v -u ./...
|
||||
@echo $(DEPS) | xargs -n1 go get -d -u
|
||||
go get -u -v ./...
|
||||
|
||||
clean:
|
||||
@rm -rf bin/ local/ pkg/ src/ website/.sass-cache website/build
|
||||
|
||||
format:
|
||||
go fmt ./...
|
||||
|
||||
test: deps
|
||||
@$(ECHO) "$(OK_COLOR)==> Testing Packer...$(NO_COLOR)"
|
||||
go test ./...
|
||||
|
||||
.PHONY: all clean deps format test updatedeps
|
||||
.PHONY: bin default test updatedeps
|
||||
|
|
58
README.md
58
README.md
|
@ -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!
|
||||
|
||||
If you need to cross-compile Packer for other platforms, take a look at
|
||||
`scripts/dist.sh`.
|
||||
$ make updatedeps
|
||||
...
|
||||
$ make
|
||||
...
|
||||
|
||||
You can run tests by typing `make test`.
|
||||
To compile a development version of Packer and the built-in plugins,
|
||||
run `make dev`. This will put Packer binaries in the `bin` folder:
|
||||
|
||||
This will run tests for Packer core along with all the core builders and commands and such that come with Packer.
|
||||
$ make dev
|
||||
...
|
||||
$ bin/packer
|
||||
...
|
||||
|
||||
If you make any changes to the code, run `make format` in order to automatically
|
||||
format the code according to Go standards.
|
||||
|
||||
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.
|
||||
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.
|
||||
|
||||
$ make test TEST=./packer
|
||||
...
|
||||
|
|
|
@ -0,0 +1,77 @@
|
|||
#!/bin/bash
|
||||
#
|
||||
# This script builds the application from source for multiple platforms.
|
||||
set -e
|
||||
|
||||
# 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
|
||||
|
||||
# Get the git commit
|
||||
GIT_COMMIT=$(git rev-parse HEAD)
|
||||
GIT_DIRTY=$(test -n "`git status --porcelain`" && echo "+CHANGES" || true)
|
||||
|
||||
# Determine the arch/os combos we're building for
|
||||
XC_ARCH=${XC_ARCH:-"386 amd64 arm"}
|
||||
XC_OS=${XC_OS:-linux darwin windows freebsd openbsd}
|
||||
|
||||
# Install dependencies
|
||||
echo "==> Getting dependencies..."
|
||||
go get ./...
|
||||
|
||||
# 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 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 ${PLATFORM}/packer 2>/dev/null
|
||||
mv ${PLATFORM}/packer-packer ${PLATFORM}/packer 2>/dev/null
|
||||
set -e
|
||||
done
|
||||
|
||||
# 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/
|
|
@ -1,52 +0,0 @@
|
|||
#!/bin/bash
|
||||
#
|
||||
# This script compiles Packer for various platforms (specified by the
|
||||
# PACKER_OS and PACKER_ARCH environmental variables).
|
||||
set -e
|
||||
|
||||
NO_COLOR="\x1b[0m"
|
||||
OK_COLOR="\x1b[32;01m"
|
||||
ERROR_COLOR="\x1b[31;01m"
|
||||
WARN_COLOR="\x1b[33;01m"
|
||||
|
||||
# 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
|
||||
|
||||
# Get the git commit
|
||||
GIT_COMMIT=$(git rev-parse HEAD)
|
||||
GIT_DIRTY=$(test -n "`git status --porcelain`" && echo "+CHANGES" || true)
|
||||
|
||||
# Determine the arch/os combos we're building for
|
||||
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}"
|
||||
go get ./...
|
||||
|
||||
echo -e "${OK_COLOR}==> Beginning compile...${NO_COLOR}"
|
||||
rm -rf pkg/
|
||||
gox \
|
||||
-os="${XC_OS}" \
|
||||
-arch="${XC_ARCH}" \
|
||||
-ldflags "-X github.com/mitchellh/packer/packer.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
|
||||
set -e
|
||||
done
|
||||
|
||||
# Reset signal trapping to avoid "Terminated: 15" at the end
|
||||
trap - SIGINT SIGTERM EXIT
|
|
@ -1,67 +0,0 @@
|
|||
#!/bin/bash
|
||||
#
|
||||
# This script only builds the application from source.
|
||||
set -e
|
||||
|
||||
NO_COLOR="\x1b[0m"
|
||||
OK_COLOR="\x1b[32;01m"
|
||||
ERROR_COLOR="\x1b[31;01m"
|
||||
WARN_COLOR="\x1b[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
|
|
@ -1,6 +1,19 @@
|
|||
#!/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
|
||||
|
|
Loading…
Reference in New Issue