build.sh 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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. export GOBIN="$(go env GOPATH)/bin"
  16. parm="" # "-u"
  17. {
  18. "${say}" "go get (install dependencies)"
  19. # go get "${parm}" github.com/jteeuwen/go-bindata/...
  20. go get "${parm}" github.com/kevinburke/go-bindata/...
  21. }
  22. "$(go env GOBIN)/go-bindata" -ignore="\\.DS_Store" -ignore=".+\\.woff" -prefix static static/... tpl/...
  23. VERSION="$(grep -F 'version = ' version.go | cut -d \" -f 2)"
  24. LDFLAGS="-s -w -X main.GitSHA1=$(git rev-parse --short HEAD)"
  25. rm shaarligo*.cgi 2>/dev/null
  26. "${say}" "test"
  27. umask 0022
  28. go fmt || { exit $?; }
  29. go vet || { exit $?; }
  30. go test || { exit $?; }
  31. "${say}" "build localhost"
  32. go build -ldflags "${LDFLAGS}" -o "shaarligo.cgi" || { echo "Aua" 1>&2 && exit 1; }
  33. mv "shaarligo.cgi" "shaarligo-${VERSION}-$(uname -s)-$(uname -m).cgi"
  34. # open "http://localhost/~$(whoami)/b/shaarligo.cgi"
  35. "${say}" bench
  36. go test -bench=.
  37. "${say}" ok
  38. "${say}" "linux build"
  39. rm -rf build
  40. mkdir -p "build/${VERSION}-Linux-x86_64/"
  41. mkdir -p "build/${VERSION}-Linux-armv6l/"
  42. # http://dave.cheney.net/2015/08/22/cross-compilation-with-go-1-5
  43. env GOOS=linux GOARCH=amd64 go build -ldflags="${LDFLAGS}" -o "build/${VERSION}-Linux-x86_64/shaarligo.cgi" || { echo "Aua" 1>&2 && exit 1; }
  44. env GOOS=linux GOARCH=arm GOARM=6 go build -ldflags="${LDFLAGS}" -o "build/${VERSION}-Linux-armv6l/shaarligo.cgi" || { echo "Aua" 1>&2 && exit 1; }
  45. "${say}" "deploy"
  46. if [ "${1}" = "prod" ] ; then
  47. rsync -avPz "build/" c1:"/var/www/vhosts/darknet.mro.name/pages/dev/shaarligo/"
  48. else
  49. rsync -avPz "build/${VERSION}-Linux-x86_64/shaarligo.cgi" c0:"/var/www/vhosts/demo.mro.name/"
  50. fi
  51. "${say}" "done"