mirror of https://github.com/hashicorp/packer
parent
7e5a5eeefe
commit
8516e03eed
@ -1,101 +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"
|
||||
|
||||
# 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)
|
||||
|
||||
# If we're building on Windows, specify an extension
|
||||
EXTENSION=""
|
||||
if [ "$(go env GOOS)" = "windows" ]; then
|
||||
EXTENSION=".exe"
|
||||
fi
|
||||
|
||||
# Make sure that if we're killed, we kill all our subprocseses
|
||||
trap "kill 0" SIGINT SIGTERM EXIT
|
||||
|
||||
# If we're building a race-enabled build, then set that up.
|
||||
if [ ! -z $PACKER_RACE ]; then
|
||||
echo -e "${OK_COLOR}--> Building with race detection enabled${NO_COLOR}"
|
||||
PACKER_RACE="-race"
|
||||
fi
|
||||
|
||||
echo -e "${OK_COLOR}--> Installing dependencies to speed up builds...${NO_COLOR}"
|
||||
go get ./...
|
||||
|
||||
# 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
|
||||
}
|
||||
|
||||
waitSingle() {
|
||||
if [ ! -z $PACKER_NO_BUILD_PARALLEL ]; then
|
||||
waitAll
|
||||
fi
|
||||
}
|
||||
|
||||
if [ -z $PACKER_NO_BUILD_PARALLEL ]; then
|
||||
echo -e "${OK_COLOR}--> NOTE: Compilation of components " \
|
||||
"will be done in parallel.${NO_COLOR}"
|
||||
fi
|
||||
|
||||
# Compile the main Packer app
|
||||
echo -e "${OK_COLOR}--> Compiling Packer${NO_COLOR}"
|
||||
(
|
||||
go build \
|
||||
${PACKER_RACE} \
|
||||
-ldflags "-X github.com/mitchellh/packer/packer.GitCommit ${GIT_COMMIT}${GIT_DIRTY}" \
|
||||
-v \
|
||||
-o bin/packer${EXTENSION} .
|
||||
|
||||
cp bin/packer${EXTENSION} ${GOPATH}/bin
|
||||
) &
|
||||
|
||||
waitSingle
|
||||
|
||||
# Go over each plugin and build it
|
||||
for PLUGIN in $(find ./plugin -mindepth 1 -maxdepth 1 -type d); do
|
||||
PLUGIN_NAME=$(basename ${PLUGIN})
|
||||
echo -e "${OK_COLOR}--> Compiling Plugin: ${PLUGIN_NAME}${NO_COLOR}"
|
||||
(
|
||||
go build \
|
||||
${PACKER_RACE} \
|
||||
-ldflags "-X github.com/mitchellh/packer/packer.GitCommit ${GIT_COMMIT}${GIT_DIRTY}" \
|
||||
-v \
|
||||
-o bin/packer-${PLUGIN_NAME}${EXTENSION} ${PLUGIN}
|
||||
|
||||
cp bin/packer-${PLUGIN_NAME}${EXTENSION} ${GOPATH}/bin
|
||||
) &
|
||||
|
||||
waitSingle
|
||||
done
|
||||
|
||||
waitAll
|
||||
|
||||
# Reset signal trapping to avoid "Terminated: 15" at the end
|
||||
trap - SIGINT SIGTERM EXIT
|
||||
@ -0,0 +1,52 @@
|
||||
#!/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 ${PLATFORM}/packer 2>/dev/null
|
||||
mv ${PLATFORM}/packer-packer.exe ${PLATFORM}/packer.exe 2>/dev/null
|
||||
set -e
|
||||
done
|
||||
|
||||
# Reset signal trapping to avoid "Terminated: 15" at the end
|
||||
trap - SIGINT SIGTERM EXIT
|
||||
@ -0,0 +1,25 @@
|
||||
#!/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"
|
||||
|
||||
# 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
|
||||
cp pkg/${XC_OS}_${XC_ARCH}/* ${GOPATH}/bin
|
||||
Loading…
Reference in new issue