mirror of https://github.com/status-im/consul.git
Use gox for building
This commit is contained in:
parent
81dce36e6a
commit
6c528f0ff2
|
@ -21,7 +21,7 @@ _cgo_export.*
|
||||||
|
|
||||||
_testmain.go
|
_testmain.go
|
||||||
|
|
||||||
/dist
|
/pkg
|
||||||
*.exe
|
*.exe
|
||||||
*.test
|
*.test
|
||||||
bin/
|
bin/
|
||||||
|
@ -41,3 +41,6 @@ ui/dist/
|
||||||
|
|
||||||
website/.bundle
|
website/.bundle
|
||||||
website/vendor
|
website/vendor
|
||||||
|
|
||||||
|
ui/.bundle
|
||||||
|
ui/vendor
|
||||||
|
|
30
Makefile
30
Makefile
|
@ -2,11 +2,24 @@ DEPS = $(shell go list -f '{{range .TestImports}}{{.}} {{end}}' ./...)
|
||||||
PACKAGES = $(shell go list ./...)
|
PACKAGES = $(shell go list ./...)
|
||||||
VETARGS?=-asmdecl -atomic -bool -buildtags -copylocks -methods \
|
VETARGS?=-asmdecl -atomic -bool -buildtags -copylocks -methods \
|
||||||
-nilfunc -printf -rangeloops -shift -structtags -unsafeptr
|
-nilfunc -printf -rangeloops -shift -structtags -unsafeptr
|
||||||
|
VERSION?=$(shell awk -F\" '/^const Version/ { print $$2; exit }' version.go)
|
||||||
|
|
||||||
all: deps format
|
all: deps format
|
||||||
@mkdir -p bin/
|
@mkdir -p bin/
|
||||||
@bash --norc -i ./scripts/build.sh
|
@bash --norc -i ./scripts/build.sh
|
||||||
|
|
||||||
|
# bin generates the releasable binaries
|
||||||
|
bin: generate
|
||||||
|
@sh -c "'$(CURDIR)/scripts/build.sh'"
|
||||||
|
|
||||||
|
# dev creates binares for testing locally. There are put into ./bin and $GOPATH
|
||||||
|
dev: generate
|
||||||
|
@CONSUL_DEV=1 sh -c "'$(CURDIR)/scripts/build.sh'"
|
||||||
|
|
||||||
|
# dist creates the binaries for distibution
|
||||||
|
dist: bin
|
||||||
|
@sh -c "'$(CURDIR)/scripts/dist.sh' $(VERSION)"
|
||||||
|
|
||||||
cov:
|
cov:
|
||||||
gocov test ./... | gocov-html > /tmp/coverage.html
|
gocov test ./... | gocov-html > /tmp/coverage.html
|
||||||
open /tmp/coverage.html
|
open /tmp/coverage.html
|
||||||
|
@ -16,8 +29,14 @@ deps:
|
||||||
@go get -d -v ./... $(DEPS)
|
@go get -d -v ./... $(DEPS)
|
||||||
|
|
||||||
updatedeps: deps
|
updatedeps: deps
|
||||||
@echo "--> Updating build dependencies"
|
go get -u github.com/mitchellh/gox
|
||||||
@go get -d -f -u ./... $(DEPS)
|
go get -u golang.org/x/tools/cmd/stringer
|
||||||
|
go list ./... \
|
||||||
|
| xargs go list -f '{{join .Deps "\n"}}' \
|
||||||
|
| grep -v github.com/hashicorp/consul \
|
||||||
|
| grep -v '/internal/' \
|
||||||
|
| sort -u \
|
||||||
|
| xargs go get -f -u -v
|
||||||
|
|
||||||
test: deps
|
test: deps
|
||||||
@./scripts/verify_no_uuid.sh
|
@./scripts/verify_no_uuid.sh
|
||||||
|
@ -46,10 +65,15 @@ vet:
|
||||||
echo "and fix them if necessary before submitting the code for reviewal."; \
|
echo "and fix them if necessary before submitting the code for reviewal."; \
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# generate runs `go generate` to build the dynamically generated source files
|
||||||
|
generate: deps
|
||||||
|
find . -type f -name '.DS_Store' -delete
|
||||||
|
go generate ./...
|
||||||
|
|
||||||
web:
|
web:
|
||||||
./scripts/website_run.sh
|
./scripts/website_run.sh
|
||||||
|
|
||||||
web-push:
|
web-push:
|
||||||
./scripts/website_push.sh
|
./scripts/website_push.sh
|
||||||
|
|
||||||
.PHONY: all cov deps integ test vet web web-push test-nodep
|
.PHONY: all bin dev dist cov deps integ test vet web web-push generate test-nodep
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
#!/usr/bin/env bash
|
#!/bin/bash
|
||||||
#
|
#
|
||||||
# This script builds the application from source.
|
# This script builds the application from source for multiple platforms.
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
# Get the parent directory of where this script is.
|
# Get the parent directory of where this script is.
|
||||||
|
@ -16,37 +16,67 @@ GIT_COMMIT=$(git rev-parse HEAD)
|
||||||
GIT_DIRTY=$(test -n "`git status --porcelain`" && echo "+CHANGES" || true)
|
GIT_DIRTY=$(test -n "`git status --porcelain`" && echo "+CHANGES" || true)
|
||||||
GIT_DESCRIBE=$(git describe --tags)
|
GIT_DESCRIBE=$(git describe --tags)
|
||||||
|
|
||||||
# If we're building on Windows, specify an extension
|
# Determine the arch/os combos we're building for
|
||||||
EXTENSION=""
|
XC_ARCH=${XC_ARCH:-"386 amd64 arm"}
|
||||||
if [ "$(go env GOOS)" = "windows" ]; then
|
XC_OS=${XC_OS:-"darwin freebsd linux netbsd openbsd windows"}
|
||||||
EXTENSION=".exe"
|
|
||||||
fi
|
|
||||||
|
|
||||||
GOPATHSINGLE=${GOPATH%%:*}
|
|
||||||
if [ "$(go env GOOS)" = "windows" ]; then
|
|
||||||
GOPATHSINGLE=${GOPATH%%;*}
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ "$(go env GOOS)" = "freebsd" ]; then
|
|
||||||
export CC="clang"
|
|
||||||
fi
|
|
||||||
|
|
||||||
# On OSX, we need to use an older target to ensure binaries are
|
|
||||||
# compatible with older linkers
|
|
||||||
if [ "$(go env GOOS)" = "darwin" ]; then
|
|
||||||
export MACOSX_DEPLOYMENT_TARGET=10.6
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Install dependencies
|
# Install dependencies
|
||||||
echo "--> Installing dependencies to speed up builds..."
|
echo "==> Getting dependencies..."
|
||||||
go get \
|
go get ./...
|
||||||
-ldflags "${CGO_LDFLAGS}" \
|
|
||||||
./...
|
# 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 [ "${CONSUL_DEV}x" != "x" ]; then
|
||||||
|
XC_OS=$(go env GOOS)
|
||||||
|
XC_ARCH=$(go env GOARCH)
|
||||||
|
fi
|
||||||
|
|
||||||
# Build!
|
# Build!
|
||||||
echo "--> Building..."
|
echo "==> Building..."
|
||||||
go build \
|
gox \
|
||||||
-ldflags "${CGO_LDFLAGS} -X main.GitCommit=${GIT_COMMIT}${GIT_DIRTY} -X main.GitDescribe=${GIT_DESCRIBE}" \
|
-os="${XC_OS}" \
|
||||||
-v \
|
-arch="${XC_ARCH}" \
|
||||||
-o bin/consul${EXTENSION}
|
-ldflags "-X main.GitCommit ${GIT_COMMIT}${GIT_DIRTY} -X main.GitDescribe ${GIT_DESCRIBE}" \
|
||||||
cp bin/consul${EXTENSION} "${GOPATHSINGLE}/bin"
|
-output "pkg/{{.OS}}_{{.Arch}}/consul" \
|
||||||
|
.
|
||||||
|
|
||||||
|
# Move all the compiled things to the $GOPATH/bin
|
||||||
|
GOPATH=${GOPATH:-$(go env GOPATH)}
|
||||||
|
case $(uname) in
|
||||||
|
CYGWIN*)
|
||||||
|
GOPATH="$(cygpath $GOPATH)"
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
OLDIFS=$IFS
|
||||||
|
IFS=: MAIN_GOPATH=($GOPATH)
|
||||||
|
IFS=$OLDIFS
|
||||||
|
|
||||||
|
# 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/
|
||||||
|
cp ${F} ${MAIN_GOPATH}/bin/
|
||||||
|
done
|
||||||
|
|
||||||
|
if [ "${CONSUL_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/
|
||||||
|
|
|
@ -8,12 +8,6 @@ if [ -z $VERSION ]; then
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
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.
|
# Get the parent directory of where this script is.
|
||||||
SOURCE="${BASH_SOURCE[0]}"
|
SOURCE="${BASH_SOURCE[0]}"
|
||||||
while [ -h "$SOURCE" ] ; do SOURCE="$(readlink "$SOURCE")"; done
|
while [ -h "$SOURCE" ] ; do SOURCE="$(readlink "$SOURCE")"; done
|
||||||
|
@ -22,53 +16,45 @@ DIR="$( cd -P "$( dirname "$SOURCE" )/.." && pwd )"
|
||||||
# Change into that dir because we expect that
|
# Change into that dir because we expect that
|
||||||
cd $DIR
|
cd $DIR
|
||||||
|
|
||||||
|
# Generate the tag
|
||||||
|
if [ -z $NOTAG ]; then
|
||||||
|
echo "==> Tagging..."
|
||||||
|
git commit --allow-empty -a --gpg-sign=348FFC4C -m "Release v$VERSION"
|
||||||
|
git tag -a -m "Version $VERSION" -s -u 348FFC4C "v${VERSION}" master
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Generate the UI
|
||||||
|
if [ -z $NOUI ]; then
|
||||||
|
echo "==> Generating Consul UI..."
|
||||||
|
make -f ui/Makefile dist
|
||||||
|
fi
|
||||||
|
|
||||||
# Zip all the files
|
# Zip all the files
|
||||||
rm -rf ./dist/pkg
|
rm -rf ./pkg/dist
|
||||||
mkdir -p ./dist/pkg
|
mkdir -p ./pkg/dist
|
||||||
for FILENAME in $(find ./dist -mindepth 1 -maxdepth 1 -type f); do
|
for FILENAME in $(find ./pkg -mindepth 1 -maxdepth 1 -type f); do
|
||||||
FILENAME=$(basename $FILENAME)
|
FILENAME=$(basename $FILENAME)
|
||||||
EXTENSION="${FILENAME##*.}"
|
cp ./pkg/${FILENAME} ./pkg/dist/consul_${VERSION}_${FILENAME}
|
||||||
PLATFORM="${FILENAME%.*}"
|
|
||||||
|
|
||||||
if [ "${EXTENSION}" != "exe" ]; then
|
|
||||||
EXTENSION=""
|
|
||||||
else
|
|
||||||
EXTENSION=".${EXTENSION}"
|
|
||||||
fi
|
|
||||||
|
|
||||||
CONSULNAME="consul${EXTENSION}"
|
|
||||||
|
|
||||||
pushd ./dist
|
|
||||||
|
|
||||||
if [ "${FILENAME}" = "ui.zip" ]; then
|
|
||||||
cp ${FILENAME} ./pkg/${VERSION}_web_ui.zip
|
|
||||||
else
|
|
||||||
if [ "${EXTENSION}" = "" ]; then
|
|
||||||
chmod +x ${FILENAME}
|
|
||||||
fi
|
|
||||||
|
|
||||||
cp ${FILENAME} ${CONSULNAME}
|
|
||||||
zip ./pkg/${VERSION}_${PLATFORM}.zip ${CONSULNAME}
|
|
||||||
rm ${CONSULNAME}
|
|
||||||
fi
|
|
||||||
|
|
||||||
popd
|
|
||||||
done
|
done
|
||||||
|
|
||||||
# Make the checksums
|
# Make the checksums
|
||||||
pushd ./dist/pkg
|
pushd ./pkg/dist
|
||||||
shasum -a256 * > ./${VERSION}_SHA256SUMS
|
shasum -a256 * > ./consul_${VERSION}_SHA256SUMS
|
||||||
|
if [ -z $NOSIGN ]; then
|
||||||
|
echo "==> Signing..."
|
||||||
|
gpg --default-key 348FFC4C --detach-sig ./consul_${VERSION}_SHA256SUMS
|
||||||
|
fi
|
||||||
popd
|
popd
|
||||||
|
|
||||||
# Upload
|
# # Upload
|
||||||
for ARCHIVE in ./dist/pkg/*; do
|
# for ARCHIVE in ./pkg/dist/*; do
|
||||||
ARCHIVE_NAME=$(basename ${ARCHIVE})
|
# ARCHIVE_NAME=$(basename ${ARCHIVE})
|
||||||
|
|
||||||
echo Uploading: $ARCHIVE_NAME
|
# echo Uploading: $ARCHIVE_NAME
|
||||||
curl \
|
# curl \
|
||||||
-T ${ARCHIVE} \
|
# -T ${ARCHIVE} \
|
||||||
-umitchellh:${BINTRAY_API_KEY} \
|
# -umitchellh:${BINTRAY_API_KEY} \
|
||||||
"https://api.bintray.com/content/mitchellh/consul/consul/${VERSION}/${ARCHIVE_NAME}"
|
# "https://api.bintray.com/content/mitchellh/consul/consul/${VERSION}/${ARCHIVE_NAME}"
|
||||||
done
|
# done
|
||||||
|
|
||||||
exit 0
|
# exit 0
|
||||||
|
|
14
ui/Makefile
14
ui/Makefile
|
@ -1,3 +1,5 @@
|
||||||
|
ROOT:=$(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))
|
||||||
|
|
||||||
server:
|
server:
|
||||||
python -m SimpleHTTPServer
|
python -m SimpleHTTPServer
|
||||||
|
|
||||||
|
@ -5,16 +7,6 @@ watch:
|
||||||
sass styles:static --watch
|
sass styles:static --watch
|
||||||
|
|
||||||
dist:
|
dist:
|
||||||
@echo clean dist
|
@sh -c "'$(ROOT)/scripts/dist.sh'"
|
||||||
@rm -rf dist/index.html
|
|
||||||
@rm -rf dist/static
|
|
||||||
@echo "compile styles/*.scss"
|
|
||||||
@sass styles/base.scss static/base.css
|
|
||||||
@ruby scripts/compile.rb
|
|
||||||
cp -R ./static dist/static/
|
|
||||||
cp index.html dist/index.html
|
|
||||||
sed -E -e "/ASSETS/,/\/ASSETS/ d" -ibak dist/index.html
|
|
||||||
sed -E -e "s#<\/body>#<script src=\"static/application.min.js\"></script></body>#" -ibak dist/index.html
|
|
||||||
rm dist/index.htmlbak
|
|
||||||
|
|
||||||
.PHONY: server watch dist
|
.PHONY: server watch dist
|
||||||
|
|
|
@ -0,0 +1,37 @@
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
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"
|
||||||
|
|
||||||
|
# Generate the tag
|
||||||
|
DEPLOY="../pkg/web_ui"
|
||||||
|
|
||||||
|
rm -rf $DEPLOY
|
||||||
|
mkdir -p $DEPLOY
|
||||||
|
|
||||||
|
bundle check >/dev/null 2>&1 || bundle install
|
||||||
|
bundle exec sass styles/base.scss static/base.css
|
||||||
|
|
||||||
|
bundle exec ruby scripts/compile.rb
|
||||||
|
|
||||||
|
# Copy into deploy
|
||||||
|
shopt -s dotglob
|
||||||
|
cp -r $DIR/static/* $DEPLOY/
|
||||||
|
cp index.html $DEPLOY/
|
||||||
|
|
||||||
|
# Magic scripting
|
||||||
|
sed -E -e "/ASSETS/,/\/ASSETS/ d" -ibak $DEPLOY/index.html
|
||||||
|
sed -E -e "s#<\/body>#<script src=\"static/application.min.js\"></script></body>#" -ibak $DEPLOY/index.html
|
||||||
|
|
||||||
|
# Remove the backup file from sed
|
||||||
|
rm $DEPLOY/index.htmlbak
|
||||||
|
|
||||||
|
pushd $DEPLOY >/dev/null 2>&1
|
||||||
|
zip ../web_ui.zip ./*
|
||||||
|
popd >/dev/null 2>&1
|
Loading…
Reference in New Issue