statping/Makefile

330 lines
14 KiB
Makefile
Raw Normal View History

2018-11-29 02:03:41 +00:00
VERSION=$(shell cat version.txt)
2018-11-29 21:31:41 +00:00
SIGN_KEY=1CD16653F89EDB72A5621D2D253A2CB79B43052D
2018-08-16 06:22:20 +00:00
BINARY_NAME=statup
2018-08-14 05:59:51 +00:00
GOPATH:=$(GOPATH)
2018-08-15 03:02:52 +00:00
GOCMD=go
2018-08-14 04:13:06 +00:00
GOBUILD=$(GOCMD) build
GOTEST=$(GOCMD) test
GOGET=$(GOCMD) get
GOINSTALL=$(GOCMD) install
2018-10-02 08:50:08 +00:00
XGO=GOPATH=$(GOPATH) xgo -go 1.11 --dest=build
2018-11-29 02:03:41 +00:00
BUILDVERSION=-ldflags "-X main.VERSION=${VERSION} -X main.COMMIT=$(TRAVIS_COMMIT)"
2018-08-14 05:59:51 +00:00
RICE=$(GOPATH)/bin/rice
2018-08-14 04:13:06 +00:00
PATH:=/usr/local/bin:$(GOPATH)/bin:$(PATH)
2018-11-29 16:35:04 +00:00
PUBLISH_BODY='{ "request": { "branch": "master", "config": { "env": { "VERSION": "${VERSION}", "COMMIT": "$(TRAVIS_COMMIT)" } } } }'
2018-11-29 22:58:31 +00:00
TRAVIS_BUILD_CMD='{ "request": { "branch": "master", "message": "Compile master for Statup v${VERSION}", "config": { "os": [ "linux" ], "language": "go", "go": [ "1.10.x" ], "go_import_path": "github.com/hunterlong/statup", "install": true, "sudo": "required", "services": [ "docker" ], "env": { "VERSION": "${VERSION}" }, "matrix": { "allow_failures": [ { "go": "master" } ], "fast_finish": true }, "before_deploy": [ "git config --local user.name \"hunterlong\"", "git config --local user.email \"info@socialeck.com\"", "make tag" ], "deploy": [ { "provider": "releases", "api_key": "$(GH_TOKEN)", "file_glob": true, "file": "build/*", "skip_cleanup": true } ], "notifications": { "email": false }, "before_script": ["gem install sass"], "script": [ "wget -O statup.gpg $(SIGN_URL)", "gpg --import statup.gpg", "travis_wait 30 docker pull karalabe/xgo-latest", "make release" ], "after_success": [], "after_deploy": [ "make publish-dev" ] } } }'
2018-08-16 20:55:30 +00:00
TEST_DIR=$(GOPATH)/src/github.com/hunterlong/statup
2018-10-07 04:48:33 +00:00
PATH:=$(PATH)
2018-08-15 08:08:50 +00:00
# build all arch's and release Statup
2018-09-11 00:09:48 +00:00
release: dev-deps build-all
2018-11-09 01:41:51 +00:00
# build and push the images to docker hub
docker: docker-build-all docker-publish-all
# test all versions of Statup, golang testing and then cypress UI testing
test-all: dev-deps test
# test all versions of Statup, golang testing and then cypress UI testing
test-ui: dev-deps docker-build-dev cypress-test
2018-08-14 04:13:06 +00:00
# testing to be ran on travis ci
travis-test: dev-deps cypress-install test coverage
# build and compile all arch's for Statup
build-all: build-mac build-linux build-windows build-alpine compress
2018-08-21 17:08:58 +00:00
# build all docker tags
2018-11-10 03:42:32 +00:00
docker-build-all: docker-build-latest
# push all docker tags built
2018-11-10 03:42:32 +00:00
docker-publish-all: docker-push-latest
# build Statup for local arch
2018-08-17 16:13:20 +00:00
build: compile
$(GOBUILD) $(BUILDVERSION) -o $(BINARY_NAME) -v ./cmd
# build Statup plugins
build-plugin:
2018-10-08 10:06:25 +00:00
$(GOBUILD) $(BUILDVERSION) -buildmode=plugin -o ./dev/plugin/example.so -v ./dev/plugin
2018-10-08 21:15:01 +00:00
test-plugin: clean
mkdir plugins
$(GOBUILD) $(BUILDVERSION) -buildmode=plugin -o ./dev/plugin/example.so -v ./dev/plugin
mv ./dev/plugin/example.so ./plugins/example.so
STATUP_DIR=$(TEST_DIR) go test -v -p=1 $(BUILDVERSION) -coverprofile=coverage.out ./plugin
# build Statup debug app
build-debug: compile
$(GOBUILD) $(BUILDVERSION) -tags debug -o $(BINARY_NAME) -v ./cmd
# install Statup for local arch and move binary to gopath/src/bin/statup
install: build
2018-08-14 04:13:06 +00:00
mv $(BINARY_NAME) $(GOPATH)/bin/$(BINARY_NAME)
$(GOPATH)/bin/$(BINARY_NAME) version
# run Statup from local arch
2018-08-14 04:13:06 +00:00
run: build
2018-08-17 04:39:25 +00:00
./$(BINARY_NAME) --ip 0.0.0.0 --port 8080
2018-08-14 04:13:06 +00:00
# compile assets using SASS and Rice. compiles scss -> css, and run rice embed-go
2018-08-14 04:13:06 +00:00
compile:
2018-08-16 06:22:20 +00:00
sass source/scss/base.scss source/css/base.css
2018-09-18 22:02:27 +00:00
cd source && $(GOPATH)/bin/rice embed-go
2018-08-21 06:54:39 +00:00
rm -rf .sass-cache
2018-08-14 04:13:06 +00:00
# benchmark testing
benchmark:
cd handlers && go test -v -run=^$ -bench=. -benchtime=5s -memprofile=prof.mem -cpuprofile=prof.cpu
# view benchmark testing using pprof
benchmark-view:
go tool pprof handlers/handlers.test handlers/prof.cpu > top20
# test Statup golang tetsing files
2018-10-08 21:15:01 +00:00
test: clean compile install build-plugin
2018-08-17 15:03:46 +00:00
STATUP_DIR=$(TEST_DIR) go test -v -p=1 $(BUILDVERSION) -coverprofile=coverage.out ./...
2018-08-16 01:15:14 +00:00
gocov convert coverage.out > coverage.json
2018-08-14 04:13:06 +00:00
2018-11-17 17:24:30 +00:00
test-api:
2018-11-17 20:10:57 +00:00
DB_CONN=sqlite DB_HOST=localhost DB_DATABASE=sqlite DB_PASS=none DB_USER=none statup &
2018-11-17 17:24:30 +00:00
sleep 15 && newman run source/tmpl/postman.json -e dev/postman_environment.json
# report coverage to Coveralls
2018-08-14 05:10:51 +00:00
coverage:
$(GOPATH)/bin/goveralls -coverprofile=coverage.out -service=travis -repotoken $(COVERALLS)
# generate documentation for Statup functions
docs:
2018-10-06 10:11:36 +00:00
godoc2md -ex github.com/hunterlong/statup/cmd >> dev/README.md
godoc2md -ex github.com/hunterlong/statup/core > dev/README.md
godoc2md -ex github.com/hunterlong/statup/handlers >> dev/README.md
godoc2md -ex github.com/hunterlong/statup/notifiers >> dev/README.md
godoc2md -ex github.com/hunterlong/statup/plugin >> dev/README.md
godoc2md -ex github.com/hunterlong/statup/source >> dev/README.md
godoc2md -ex github.com/hunterlong/statup/types >> dev/README.md
godoc2md -ex github.com/hunterlong/statup/utils >> dev/README.md
2018-10-06 05:00:40 +00:00
gocov-html coverage.json > dev/COVERAGE.html
revive -formatter stylish > dev/LINT.md
#
# Build binary for Statup
#
# build Statup for Mac, 64 and 32 bit
build-mac: compile
2018-08-14 04:13:06 +00:00
mkdir build
2018-11-29 05:05:04 +00:00
$(XGO) $(BUILDVERSION) --targets=darwin/amd64,darwin/386 ./cmd
# build Statup for Linux 64, 32 bit, arm6/arm7
build-linux: compile
2018-11-29 05:05:04 +00:00
$(XGO) $(BUILDVERSION) --targets=linux/amd64,linux/386,linux/arm-7,linux/arm-6,linux/arm64 ./cmd
2018-08-16 06:22:20 +00:00
# build for windows 64 bit only
build-windows: compile
$(XGO) $(BUILDVERSION) --targets=windows-6.0/amd64 ./cmd
# build Alpine linux binary (used in docker images)
build-alpine: compile
2018-11-29 02:03:41 +00:00
$(XGO) --targets=linux/amd64 -ldflags="-X main.VERSION=${VERSION} -X main.COMMIT=$(TRAVIS_COMMIT) -linkmode external -extldflags -static" -out alpine ./cmd
2018-08-14 04:13:06 +00:00
#
# Docker Makefile commands
#
# build :latest docker tag
2018-11-06 03:26:37 +00:00
docker-build-latest:
2018-11-29 02:03:41 +00:00
docker build --build-arg VERSION=${VERSION} -t hunterlong/statup:latest --no-cache -f Dockerfile .
docker tag hunterlong/statup:latest hunterlong/statup:v${VERSION}
2018-08-14 04:13:06 +00:00
# build :dev docker tag
2018-11-06 03:26:37 +00:00
docker-build-dev:
2018-11-29 02:03:41 +00:00
docker build --build-arg VERSION=${VERSION} -t hunterlong/statup:latest --no-cache -f Dockerfile .
docker tag hunterlong/statup:dev hunterlong/statup:dev-v${VERSION}
# build Cypress UI testing :cypress docker tag
docker-build-cypress: clean
2018-11-29 02:03:41 +00:00
GOPATH=$(GOPATH) xgo -out statup -go 1.10.x -ldflags "-X main.VERSION=${VERSION} -X main.COMMIT=$(TRAVIS_COMMIT)" --targets=linux/amd64 ./cmd
docker build -t hunterlong/statup:cypress -f dev/Dockerfile-cypress .
rm -f statup
# run hunterlong/statup:latest docker image
docker-run: docker-build-latest
docker run -it -p 8080:8080 hunterlong/statup:latest
# run hunterlong/statup:dev docker image
docker-run-dev: docker-build-dev
docker run -t -p 8080:8080 hunterlong/statup:dev
# run Cypress UI testing, hunterlong/statup:cypress docker image
docker-run-cypress: docker-build-cypress
docker run -t hunterlong/statup:cypress
# push the :base and :base-v{VERSION} tag to Docker hub
docker-push-base:
2018-11-29 02:03:41 +00:00
docker tag hunterlong/statup:base hunterlong/statup:base-v${VERSION}
docker push hunterlong/statup:base
2018-11-29 02:03:41 +00:00
docker push hunterlong/statup:base-v${VERSION}
# push the :dev tag to Docker hub
docker-push-dev:
2018-08-19 00:37:00 +00:00
docker push hunterlong/statup:dev
2018-11-29 02:03:41 +00:00
docker push hunterlong/statup:dev-v${VERSION}
2018-09-06 21:46:45 +00:00
# push the :cypress tag to Docker hub
2018-09-06 21:46:45 +00:00
docker-push-cypress:
docker push hunterlong/statup:cypress
2018-08-19 00:37:00 +00:00
# push the :latest tag to Docker hub
2018-09-12 04:14:22 +00:00
docker-push-latest:
2018-08-19 09:16:15 +00:00
docker push hunterlong/statup:latest
2018-11-29 02:03:41 +00:00
docker push hunterlong/statup:v${VERSION}
2018-08-21 17:08:58 +00:00
2018-09-19 06:12:42 +00:00
docker-run-mssql:
docker run -e 'ACCEPT_EULA=Y' -e 'SA_PASSWORD=PaSsW0rD123' -p 1433:1433 -d microsoft/mssql-server-linux
# create Postgres, and MySQL instance using Docker (used for testing)
2018-08-14 05:10:51 +00:00
databases:
2018-08-16 06:52:13 +00:00
docker run --name statup_postgres -p 5432:5432 -e POSTGRES_PASSWORD=password123 -e POSTGRES_USER=root -e POSTGRES_DB=root -d postgres
docker run --name statup_mysql -p 3306:3306 -e MYSQL_ROOT_PASSWORD=password123 -e MYSQL_DATABASE=root -d mysql
2018-08-14 05:10:51 +00:00
sleep 30
2018-08-14 04:13:06 +00:00
#
# Download and Install dependencies
#
# run dep to install all required golang dependecies
dep:
2018-08-19 08:48:02 +00:00
dep ensure -vendor-only
# install all required golang dependecies
2018-10-06 05:00:40 +00:00
dev-deps:
2018-08-14 04:13:06 +00:00
$(GOGET) github.com/stretchr/testify/assert
$(GOGET) golang.org/x/tools/cmd/cover
$(GOGET) github.com/mattn/goveralls
$(GOINSTALL) github.com/mattn/goveralls
$(GOGET) github.com/rendon/testcli
$(GOGET) github.com/karalabe/xgo
$(GOGET) github.com/GeertJohan/go.rice
$(GOGET) github.com/GeertJohan/go.rice/rice
2018-08-14 05:59:51 +00:00
$(GOINSTALL) github.com/GeertJohan/go.rice/rice
$(GOCMD) get github.com/axw/gocov/gocov
2018-08-17 15:03:46 +00:00
$(GOCMD) get gopkg.in/matm/v1/gocov-html
$(GOCMD) install gopkg.in/matm/v1/gocov-html
$(GOCMD) get github.com/mgechev/revive
2018-10-09 02:24:17 +00:00
$(GOCMD) get github.com/fatih/structs
2018-11-01 15:11:54 +00:00
$(GOCMD) get github.com/oliveroneill/exponent-server-sdk-golang/sdk
2018-08-14 04:13:06 +00:00
# remove files for a clean compile/build
2018-08-14 04:13:06 +00:00
clean:
2018-08-25 16:10:28 +00:00
rm -rf ./{logs,assets,plugins,statup.db,config.yml,.sass-cache,config.yml,statup,build,.sass-cache,statup.db,index.html,vendor}
2018-08-19 23:51:56 +00:00
rm -rf cmd/{logs,assets,plugins,statup.db,config.yml,.sass-cache,*.log}
rm -rf core/{logs,assets,plugins,statup.db,config.yml,.sass-cache,*.log}
rm -rf handlers/{logs,assets,plugins,statup.db,config.yml,.sass-cache,*.log}
rm -rf notifiers/{logs,assets,plugins,statup.db,config.yml,.sass-cache,*.log}
rm -rf source/{logs,assets,plugins,statup.db,config.yml,.sass-cache,*.log}
rm -rf types/{logs,assets,plugins,statup.db,config.yml,.sass-cache,*.log}
rm -rf utils/{logs,assets,plugins,statup.db,config.yml,.sass-cache,*.log}
2018-11-29 04:47:35 +00:00
rm -rf {parts,prime,snap,stage}
2018-08-19 08:48:02 +00:00
rm -rf dev/test/cypress/videos
2018-08-25 16:10:28 +00:00
rm -f coverage.* sass
2018-11-07 09:28:46 +00:00
rm -f source/rice-box.go
rm -f *.db-journal
2018-11-29 04:47:35 +00:00
rm -rf *.snap
find . -name "*.out" -type f -delete
find . -name "*.cpu" -type f -delete
find . -name "*.mem" -type f -delete
find . -name "*.test" -type f -delete
2018-08-14 04:13:06 +00:00
# tag version using git
2018-08-14 04:13:06 +00:00
tag:
2018-11-29 04:47:35 +00:00
git tag v${VERSION} --force
2018-08-14 04:13:06 +00:00
# compress built binaries into tar.gz and zip formats
2018-08-14 04:13:06 +00:00
compress:
2018-08-15 05:30:15 +00:00
cd build && mv alpine-linux-amd64 $(BINARY_NAME)
2018-11-29 23:49:48 +00:00
cd build && gpg --default-key $(SIGN_KEY) --batch --detach-sign --output statup.asc --armor $(BINARY_NAME)
cd build && tar -czvf $(BINARY_NAME)-linux-alpine.tar.gz $(BINARY_NAME) statup.asc && rm -f $(BINARY_NAME) statup.asc
2018-08-15 05:30:15 +00:00
cd build && mv cmd-darwin-10.6-amd64 $(BINARY_NAME)
2018-11-29 23:49:48 +00:00
cd build && gpg --default-key $(SIGN_KEY) --batch --detach-sign --output statup.asc --armor $(BINARY_NAME)
cd build && tar -czvf $(BINARY_NAME)-osx-x64.tar.gz $(BINARY_NAME) statup.asc && rm -f $(BINARY_NAME) statup.asc
2018-08-15 05:30:15 +00:00
cd build && mv cmd-darwin-10.6-386 $(BINARY_NAME)
2018-11-29 23:49:48 +00:00
cd build && gpg --default-key $(SIGN_KEY) --batch --detach-sign --output statup.asc --armor $(BINARY_NAME)
cd build && tar -czvf $(BINARY_NAME)-osx-x32.tar.gz $(BINARY_NAME) statup.asc && rm -f $(BINARY_NAME) statup.asc
2018-08-15 05:30:15 +00:00
cd build && mv cmd-linux-amd64 $(BINARY_NAME)
2018-11-29 23:49:48 +00:00
cd build && gpg --default-key $(SIGN_KEY) --batch --detach-sign --output statup.asc --armor $(BINARY_NAME)
cd build && tar -czvf $(BINARY_NAME)-linux-x64.tar.gz $(BINARY_NAME) statup.asc && rm -f $(BINARY_NAME) statup.asc
2018-08-15 05:30:15 +00:00
cd build && mv cmd-linux-386 $(BINARY_NAME)
2018-11-29 23:49:48 +00:00
cd build && gpg --default-key $(SIGN_KEY) --batch --detach-sign --output statup.asc --armor $(BINARY_NAME)
cd build && tar -czvf $(BINARY_NAME)-linux-x32.tar.gz $(BINARY_NAME) statup.asc && rm -f $(BINARY_NAME) statup.asc
2018-08-15 05:30:15 +00:00
cd build && mv cmd-windows-6.0-amd64.exe $(BINARY_NAME).exe
2018-11-29 23:49:48 +00:00
cd build && gpg --default-key $(SIGN_KEY) --batch --detach-sign --output statup.asc --armor $(BINARY_NAME).exe
cd build && zip $(BINARY_NAME)-windows-x64.zip $(BINARY_NAME).exe statup.asc && rm -f $(BINARY_NAME).exe statup.asc
2018-08-15 05:30:15 +00:00
cd build && mv cmd-linux-arm-7 $(BINARY_NAME)
2018-11-29 23:49:48 +00:00
cd build && gpg --default-key $(SIGN_KEY) --batch --detach-sign --output statup.asc --armor $(BINARY_NAME)
cd build && tar -czvf $(BINARY_NAME)-linux-arm7.tar.gz $(BINARY_NAME) statup.asc && rm -f $(BINARY_NAME) statup.asc
2018-11-29 05:05:04 +00:00
cd build && mv cmd-linux-arm-6 $(BINARY_NAME)
2018-11-29 23:49:48 +00:00
cd build && gpg --default-key $(SIGN_KEY) --batch --detach-sign --output statup.asc --armor $(BINARY_NAME)
cd build && tar -czvf $(BINARY_NAME)-linux-arm6.tar.gz $(BINARY_NAME) statup.asc && rm -f $(BINARY_NAME) statup.asc
2018-08-15 05:30:15 +00:00
cd build && mv cmd-linux-arm64 $(BINARY_NAME)
2018-11-29 23:49:48 +00:00
cd build && gpg --default-key $(SIGN_KEY) --batch --detach-sign --output statup.asc --armor $(BINARY_NAME)
cd build && tar -czvf $(BINARY_NAME)-linux-arm64.tar.gz $(BINARY_NAME) statup.asc && rm -f $(BINARY_NAME) statup.asc
2018-08-15 08:08:50 +00:00
# push the :dev docker tag using curl
2018-08-16 06:22:20 +00:00
publish-dev:
curl -H "Content-Type: application/json" --data '{"docker_tag": "dev"}' -X POST $(DOCKER)
# update the homebrew application to latest for mac
2018-08-16 06:22:20 +00:00
publish-homebrew:
2018-08-16 06:52:13 +00:00
curl -s -X POST -H "Content-Type: application/json" -H "Accept: application/json" -H "Travis-API-Version: 3" -H "Authorization: token $(TRAVIS_API)" -d $(PUBLISH_BODY) https://api.travis-ci.com/repo/hunterlong%2Fhomebrew-statup/requests
2018-08-16 06:22:20 +00:00
# install NPM reuqirements for cypress testing
cypress-install:
2018-08-19 22:16:59 +00:00
cd dev/test && npm install
2018-08-16 06:22:20 +00:00
# run Cypress UI testing
2018-08-17 08:59:01 +00:00
cypress-test: clean cypress-install
2018-08-19 08:48:02 +00:00
cd dev/test && npm test
2018-08-17 01:43:12 +00:00
# build Statup using a travis ci trigger
2018-08-17 16:13:20 +00:00
travis-build:
curl -s -X POST -H "Content-Type: application/json" -H "Accept: application/json" -H "Travis-API-Version: 3" -H "Authorization: token $(TRAVIS_API)" -d $(TRAVIS_BUILD_CMD) https://api.travis-ci.com/repo/hunterlong%2Fstatup/requests
2018-11-18 00:09:39 +00:00
curl -H "Content-Type: application/json" --data '{"docker_tag": "latest"}' -X POST $(DOCKER)
2018-08-17 16:13:20 +00:00
2018-11-29 04:47:35 +00:00
snapcraft: snapcraft-build snapcraft-release
snapcraft-build:
PWD=$(shell pwd)
cp build/$(BINARY_NAME)-linux-x64.tar.gz build/$(BINARY_NAME)-linux.tar.gz
snapcraft clean statup -s pull
docker run --rm -v ${PWD}:/build -w /build --env VERSION=${VERSION} snapcore/snapcraft bash -c "apt update && snapcraft --target-arch=amd64"
cp build/$(BINARY_NAME)-linux-x32.tar.gz build/$(BINARY_NAME)-linux.tar.gz
snapcraft clean statup -s pull
docker run --rm -v ${PWD}:/build -w /build --env VERSION=${VERSION} snapcore/snapcraft bash -c "apt update && snapcraft --target-arch=i386"
cp build/$(BINARY_NAME)-linux-arm64.tar.gz build/$(BINARY_NAME)-linux.tar.gz
snapcraft clean statup -s pull
docker run --rm -v ${PWD}:/build -w /build --env VERSION=${VERSION} snapcore/snapcraft bash -c "apt update && snapcraft --target-arch=arm64"
cp build/$(BINARY_NAME)-linux-arm7.tar.gz build/$(BINARY_NAME)-linux.tar.gz
snapcraft clean statup -s pull
docker run --rm -v ${PWD}:/build -w /build --env VERSION=${VERSION} snapcore/snapcraft bash -c "apt update && snapcraft --target-arch=armhf"
rm -f build/$(BINARY_NAME)-linux.tar.gz
snapcraft-release:
snapcraft push *.snap --release edge
2018-11-28 22:35:49 +00:00
2018-11-29 16:35:04 +00:00
snap:
snapcraft cleanbuild
2018-11-29 21:31:41 +00:00
sign-all:
gpg --default-key CB1895149EEA4A2B8DBC9FB4C326E5C3B26BBA53 --detach-sign --armor statuper
valid-sign:
gpg --verify statuper.asc
# install xgo and pull the xgo docker image
2018-08-19 08:48:02 +00:00
xgo-install: clean
go get github.com/karalabe/xgo
docker pull karalabe/xgo-latest
2018-11-18 00:09:39 +00:00
.PHONY: all build build-all build-alpine test-all test test-api