build.sh 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. #!/bin/sh
  2. # get the go toolchain https://golang.org/dl/
  3. # https://golang.org/doc/install/source#environment
  4. #
  5. cd "$(dirname "${0}")" || exit 1
  6. if say -v '?' 1>/dev/null 2>/dev/null ; then
  7. say="say"
  8. else
  9. say="echo"
  10. fi
  11. # prevent GOPATH pointing outside userland (especially on Alpine)
  12. # go env -w GOPATH="${HOME}/go"
  13. # mkdir -p "${GOPATH}" 2>/dev/null
  14. # go env -w GOBIN="$(go env GOPATH)/bin"
  15. parm="" # "-u"
  16. {
  17. "${say}" "go get (install dependencies)"
  18. # go get "${parm}" github.com/jteeuwen/go-bindata/...
  19. go get "${parm}" github.com/kevinburke/go-bindata/...
  20. }
  21. "$(go env GOPATH)/bin/go-bindata" -ignore="\\.DS_Store" -ignore=".+\\.woff" -prefix static static/... tpl/...
  22. VERSION="$(grep -F 'version = ' version.go | cut -d \" -f 2)"
  23. LDFLAGS="-s -w -X main.GitSHA1=$(git rev-parse --short HEAD)"
  24. rm shaarligo*.cgi 2>/dev/null
  25. "${say}" "test"
  26. umask 0022
  27. go fmt || { exit $?; }
  28. go vet || { exit $?; }
  29. go test || { exit $?; }
  30. "${say}" "build localhost"
  31. go build -ldflags "${LDFLAGS}" -o "shaarligo.cgi" || { echo "Aua" 1>&2 && exit 1; }
  32. mv "shaarligo.cgi" "shaarligo-${VERSION}-$(uname -s)-$(uname -m).cgi"
  33. # open "http://localhost/~$(whoami)/b/shaarligo.cgi"
  34. "${say}" bench
  35. go test -bench=.
  36. "${say}" ok
  37. "${say}" "linux build"
  38. rm -rf build
  39. mkdir -p "build/${VERSION}-Linux-x86_64/"
  40. mkdir -p "build/${VERSION}-Linux-armv6l/"
  41. # http://dave.cheney.net/2015/08/22/cross-compilation-with-go-1-5
  42. env GOOS=linux GOARCH=amd64 go build -ldflags="${LDFLAGS}" -o "build/${VERSION}-Linux-x86_64/shaarligo.cgi" || { echo "Aua" 1>&2 && exit 1; }
  43. env GOOS=linux GOARCH=arm GOARM=6 go build -ldflags="${LDFLAGS}" -o "build/${VERSION}-Linux-armv6l/shaarligo.cgi" || { echo "Aua" 1>&2 && exit 1; }
  44. "${say}" "deploy"
  45. if [ "${1}" = "prod" ] ; then
  46. rsync -avPz "build/" c1:"/var/www/vhosts/darknet.mro.name/pages/dev/shaarligo/"
  47. else
  48. rsync -avPz "build/${VERSION}-Linux-x86_64/shaarligo.cgi" c2:"/var/www/vhosts/demo.mro.name/"
  49. fi
  50. "${say}" "done"