mirror of https://github.com/hashicorp/packer
parent
db90658250
commit
2788ccc653
@ -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"
|
||||
|
||||
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 format test updatedeps
|
||||
.PHONY: bin default test updatedeps
|
||||
|
||||
@ -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
|
||||
Loading…
Reference in new issue