mirror of https://github.com/statping/statping
vue
parent
307e270fc9
commit
725aab9198
|
@ -19,3 +19,10 @@ config.yml
|
|||
*.db
|
||||
tmp
|
||||
frontend/node_modules
|
||||
.next
|
||||
node_modules
|
||||
source/dist
|
||||
frontend/dist
|
||||
Dockerfile
|
||||
Dockerfile.base
|
||||
docker
|
||||
|
|
|
@ -29,3 +29,5 @@ sass
|
|||
source/css/base.css.map
|
||||
dev/test/node_modules
|
||||
source/scss
|
||||
databases
|
||||
statping
|
||||
|
|
25
Dockerfile
25
Dockerfile
|
@ -1,26 +1,10 @@
|
|||
FROM golang:1.13.5-alpine as base
|
||||
LABEL maintainer="Hunter Long (https://github.com/hunterlong)"
|
||||
ARG VERSION
|
||||
RUN apk add --update --no-cache libstdc++ gcc g++ make git ca-certificates linux-headers wget curl jq libsass nodejs nodejs-npm
|
||||
RUN npm install -g yarn
|
||||
RUN curl -L -s https://assets.statping.com/sass -o /usr/local/bin/sass && \
|
||||
chmod +x /usr/local/bin/sass
|
||||
WORKDIR /go/src/github.com/hunterlong/statping
|
||||
ADD Makefile go.mod /go/src/github.com/hunterlong/statping/
|
||||
RUN go mod vendor && \
|
||||
make dev-deps
|
||||
ADD . /go/src/github.com/hunterlong/statping
|
||||
RUN cd frontend && yarn install --network-timeout 1000000
|
||||
RUN make compile install
|
||||
FROM hunterlong/statping:base as base
|
||||
|
||||
# Statping :latest Docker Image
|
||||
FROM alpine:latest
|
||||
LABEL maintainer="Hunter Long (https://github.com/hunterlong)"
|
||||
|
||||
ARG VERSION
|
||||
ENV IS_DOCKER=true
|
||||
ENV STATPING_DIR=/app
|
||||
ENV PORT=8080
|
||||
|
||||
RUN apk --no-cache add curl jq libsass
|
||||
|
||||
COPY --from=base /usr/local/bin/sass /usr/local/bin/sass
|
||||
|
@ -28,6 +12,11 @@ COPY --from=base /go/bin/statping /usr/local/bin/statping
|
|||
|
||||
WORKDIR /app
|
||||
VOLUME /app
|
||||
|
||||
ENV IS_DOCKER=true
|
||||
ENV STATPING_DIR=/app
|
||||
ENV PORT=8080
|
||||
|
||||
EXPOSE $PORT
|
||||
|
||||
HEALTHCHECK --interval=60s --timeout=10s --retries=3 CMD curl -s "http://localhost:$PORT/health" | jq -r -e ".online==true"
|
||||
|
|
|
@ -0,0 +1,29 @@
|
|||
FROM golang:1.13.5-alpine
|
||||
LABEL maintainer="Hunter Long (https://github.com/hunterlong)"
|
||||
ARG VERSION
|
||||
RUN apk add --update --no-cache libstdc++ gcc g++ make git ca-certificates linux-headers wget curl jq libsass nodejs nodejs-npm
|
||||
RUN npm install -g yarn
|
||||
|
||||
RUN curl -L -s https://assets.statping.com/sass -o /usr/local/bin/sass && \
|
||||
chmod +x /usr/local/bin/sass
|
||||
|
||||
WORKDIR /go/src/github.com/hunterlong/statping
|
||||
|
||||
ADD Makefile go.mod go.sum version.txt ./
|
||||
|
||||
RUN go mod download
|
||||
RUN make dev-deps
|
||||
|
||||
ADD frontend/package.json frontend/yarn.lock ./frontend/
|
||||
|
||||
RUN cd frontend && yarn install --pure-lockfile --network-timeout 1000000 && \
|
||||
yarn cache clean
|
||||
|
||||
ADD . ./
|
||||
|
||||
RUN make clean frontend-build compile
|
||||
RUN make build
|
||||
RUN chmod a+x statping && mv statping /go/bin/statping
|
||||
|
||||
WORKDIR /app
|
||||
|
385
Makefile
385
Makefile
|
@ -2,7 +2,7 @@ VERSION=$(shell cat version.txt)
|
|||
SIGN_KEY=B76D61FAA6DB759466E83D9964B9C6AAE2D55278
|
||||
BINARY_NAME=statping
|
||||
GOBUILD=go build -a
|
||||
GOVERSION=1.13.7
|
||||
GOVERSION=1.13.5
|
||||
XGO=xgo -go $(GOVERSION) --dest=build
|
||||
BUILDVERSION=-ldflags "-X main.VERSION=${VERSION} -X main.COMMIT=$(TRAVIS_COMMIT)"
|
||||
TRVIS_SECRET=lRqWSt5BoekFK6+padJF+b77YkGdispPXEUKNuD7/Hxb7yJMoI8T/n8xZrTHtCZPdjtpy7wIlJCezNoYEZB3l2GnD6Y1QEZEXF7MIxP7hwsB/uSc5/lgdGW0ZLvTBfv6lwI/GjQIklPBW/4xcKJtj4s1YBP7xvqyIb/lDN7TiOqAKF4gqRVVfsxvlkm7j4TiPCXtz17hYQfU8kKBbd+vd3PuZgdWqs//5RwKk3Ld8QR8zoo9xXQVC5NthiyVbHznzczBsHy2cRZZoWxyi7eJM1HrDw8Jn/ivJONIHNv3RgFVn2rAoKu1X8F6FyuvPO0D2hWC62mdO/e0kt4X0mn9/6xlLSKwrHir67UgNVQe3tvlH0xNKh+yNZqR5x9t0V54vNks6Pgbhas5EfLHoWn5cF4kbJzqkXeHjt1msrsqpA3HKbmtwwjJr4Slotfiu22mAhqLSOV+xWV+IxrcNnrEq/Pa+JAzU12Uyxs8swaLJGPRAlWnJwzL9HK5aOpN0sGTuSEsTwj0WxeMMRx25YEq3+LZOgwOy3fvezmeDnKuBZa6MVCoMMpx1CRxMqAOlTGZXHjj+ZPmqDUUBpzAsFSzIdVRgcnDlLy7YRiz3tVWa1G5S07l/VcBN7ZgvCwOWZ0QgOH0MxkoDfhrfoMhNO6MBFDTRKCEl4TroPEhcInmXU8=
|
||||
|
@ -11,243 +11,48 @@ TRAVIS_BUILD_CMD='{ "request": { "branch": "master", "message": "Compile master
|
|||
TEST_DIR=$(GOPATH)/src/github.com/hunterlong/statping
|
||||
PATH:=/usr/local/bin:$(GOPATH)/bin:$(PATH)
|
||||
|
||||
# build all arch's and release Statping
|
||||
release: dev-deps
|
||||
wget -O statping.gpg $(SIGN_URL)
|
||||
gpg --import statping.gpg
|
||||
make build-all
|
||||
up: docker-base
|
||||
docker-compose -f docker-compose.yml -f dev/docker-compose.full.yml up -d --remove-orphans --build
|
||||
|
||||
frontend:
|
||||
cd frontend && yarn serve
|
||||
down:
|
||||
docker-compose -f docker-compose.yml -f dev/docker-compose.full.yml down --volumes
|
||||
|
||||
logs:
|
||||
docker logs statping --follow
|
||||
|
||||
console:
|
||||
docker exec -t -i statping /bin/sh
|
||||
|
||||
docker-base:
|
||||
docker build -t hunterlong/statping:base -f Dockerfile.base --build-arg VERSION=${VERSION} .
|
||||
|
||||
docker-latest: docker-base
|
||||
docker build -t hunterlong/statping:latest --build-arg VERSION=${VERSION} .
|
||||
|
||||
docker-vue:
|
||||
docker build -t hunterlong/statping:vue --build-arg VERSION=${VERSION} .
|
||||
|
||||
top:
|
||||
docker-compose -f docker-compose.yml -f dev/docker-compose.full.yml top
|
||||
|
||||
frontend-build:
|
||||
cd frontend && rm -rf dist && yarn build
|
||||
rm -rf source/dist && cp -r frontend/dist source/ && cp -r frontend/src/assets/scss source/dist/
|
||||
cp -r source/tmpl/*.* source/dist/
|
||||
|
||||
# build and push the images to docker hub
|
||||
docker: docker-build-all docker-publish-all
|
||||
|
||||
push-vue:
|
||||
docker build -t hunterlong/statping:vue .
|
||||
docker push hunterlong/statping:vue
|
||||
|
||||
# test all versions of Statping, golang testing and then cypress UI testing
|
||||
test-all: dev-deps test
|
||||
|
||||
# test all versions of Statping, golang testing and then cypress UI testing
|
||||
test-ui: dev-deps docker-build-dev cypress-test
|
||||
|
||||
# testing to be ran on travis ci
|
||||
travis-test: dev-deps cypress-install test coverage
|
||||
|
||||
# build and compile all arch's for Statping
|
||||
build-all: build-mac build-linux build-windows build-alpine compress
|
||||
|
||||
# build all docker tags
|
||||
docker-build-all: docker-build-latest
|
||||
|
||||
# push all docker tags built
|
||||
docker-publish-all: docker-push-latest
|
||||
|
||||
snapcraft: clean snapcraft-build snapcraft-release
|
||||
|
||||
# build Statping for local arch
|
||||
build: compile
|
||||
go mod vendor
|
||||
$(GOBUILD) $(BUILDVERSION) -o $(BINARY_NAME) -v ./cmd
|
||||
|
||||
# build Statping plugins
|
||||
build-plugin:
|
||||
$(GOBUILD) $(BUILDVERSION) -buildmode=plugin -o ./dev/plugin/example.so -v ./dev/plugin
|
||||
|
||||
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
|
||||
STATPING_DIR=$(TEST_DIR) go test -v -p=1 $(BUILDVERSION) -coverprofile=coverage.out ./plugin
|
||||
|
||||
# build Statping debug app
|
||||
build-debug: compile
|
||||
$(GOBUILD) $(BUILDVERSION) -tags debug -o $(BINARY_NAME) -v ./cmd
|
||||
|
||||
# install Statping for local arch and move binary to gopath/src/bin/statping
|
||||
install: build
|
||||
mv $(BINARY_NAME) $(GOPATH)/bin/$(BINARY_NAME)
|
||||
$(GOPATH)/bin/$(BINARY_NAME) version
|
||||
|
||||
# run Statping from local arch
|
||||
run: build
|
||||
./$(BINARY_NAME) --ip 0.0.0.0 --port 8080
|
||||
|
||||
# run Statping with Delve for debugging
|
||||
rundlv:
|
||||
lsof -ti:8080 | xargs kill
|
||||
DB_CONN=sqlite DB_HOST=localhost DB_DATABASE=sqlite DB_PASS=none DB_USER=none GO_ENV=test \
|
||||
dlv --listen=:2345 --headless=true --api-version=2 --accept-multiclient exec ./statping
|
||||
|
||||
killdlv:
|
||||
lsof -ti:2345 | xargs kill
|
||||
|
||||
builddlv:
|
||||
$(GOBUILD) -gcflags "all=-N -l" -o ./$(BINARY_NAME) -v ./cmd
|
||||
|
||||
watch:
|
||||
find . -print | grep -i '.*\.\(go\|gohtml\)' | justrun -v -c \
|
||||
'go build -v -gcflags "all=-N -l" -o statping ./cmd && make rundlv &' \
|
||||
-delay 10s -stdin \
|
||||
-i="Makefile,statping,statup.db,statup.db-journal,handlers/graphql/generated.go"
|
||||
|
||||
# compile assets using SASS and Rice. compiles scss -> css, and run rice embed-go
|
||||
compile: frontend-build generate
|
||||
compile: generate
|
||||
cd source && rice embed-go
|
||||
|
||||
# benchmark testing
|
||||
benchmark:
|
||||
cd handlers && go test -v -run=^$ -bench=. -benchtime=5s -memprofile=prof.mem -cpuprofile=prof.cpu
|
||||
build:
|
||||
$(GOBUILD) $(BUILDVERSION) -o $(BINARY_NAME) ./cmd
|
||||
|
||||
# view benchmark testing using pprof
|
||||
benchmark-view:
|
||||
go tool pprof handlers/handlers.test handlers/prof.cpu > top20
|
||||
install:
|
||||
mv $(BINARY_NAME) $(GOPATH)/bin/$(BINARY_NAME)
|
||||
|
||||
# test Statping golang tetsing files
|
||||
test: clean compile install build-plugin
|
||||
STATPING_DIR=$(TEST_DIR) go test -v -p=1 $(BUILDVERSION) -coverprofile=coverage.out ./...
|
||||
gocov convert coverage.out > coverage.json
|
||||
|
||||
test-api:
|
||||
DB_CONN=sqlite DB_HOST=localhost DB_DATABASE=sqlite DB_PASS=none DB_USER=none statping &
|
||||
sleep 300 && newman run source/tmpl/postman.json -e dev/postman_environment.json --delay-request 500
|
||||
|
||||
# report coverage to Coveralls
|
||||
coverage:
|
||||
$(GOPATH)/bin/goveralls -coverprofile=coverage.out -service=travis -repotoken $(COVERALLS)
|
||||
|
||||
# generate documentation for Statping functions
|
||||
docs:
|
||||
rm -f dev/README.md
|
||||
printf "# Statping Dev Documentation\n" > dev/README.md
|
||||
printf "This readme is automatically generated from the Golang documentation. [](https://godoc.org/github.com/hunterlong/statping)\n\n" > dev/README.md
|
||||
godocdown github.com/hunterlong/statping >> dev/README.md
|
||||
godocdown github.com/hunterlong/statping/cmd >> dev/README.md
|
||||
godocdown github.com/hunterlong/statping/core >> dev/README.md
|
||||
godocdown github.com/hunterlong/statping/handlers >> dev/README.md
|
||||
godocdown github.com/hunterlong/statping/notifiers >> dev/README.md
|
||||
godocdown github.com/hunterlong/statping/plugin >> dev/README.md
|
||||
godocdown github.com/hunterlong/statping/source >> dev/README.md
|
||||
godocdown github.com/hunterlong/statping/types >> dev/README.md
|
||||
godocdown github.com/hunterlong/statping/utils >> dev/README.md
|
||||
gocov-html coverage.json > dev/COVERAGE.html
|
||||
revive -formatter stylish > dev/LINT.md
|
||||
|
||||
#
|
||||
# Build binary for Statping
|
||||
#
|
||||
|
||||
# build Statping for Mac, 64 and 32 bit
|
||||
build-mac: compile
|
||||
mkdir build
|
||||
$(XGO) $(BUILDVERSION) --targets=darwin/amd64,darwin/386 ./cmd
|
||||
|
||||
# build Statping for Linux 64, 32 bit, arm6/arm7
|
||||
build-linux: compile
|
||||
$(XGO) $(BUILDVERSION) --targets=linux/amd64,linux/386,linux/arm-7,linux/arm-6,linux/arm64 ./cmd
|
||||
|
||||
# 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
|
||||
$(XGO) --targets=linux/amd64 -ldflags="-X main.VERSION=${VERSION} -X main.COMMIT=$(TRAVIS_COMMIT) -linkmode external -extldflags -static" -out alpine ./cmd
|
||||
|
||||
#
|
||||
# Docker Makefile commands
|
||||
#
|
||||
|
||||
docker-test:
|
||||
docker-compose -f docker-compose.test.yml -p statping build
|
||||
docker-compose -f docker-compose.test.yml -p statping up -d
|
||||
docker logs -f statping_sut_1
|
||||
docker wait statping_sut_1
|
||||
|
||||
# build :latest docker tag
|
||||
docker-build-latest:
|
||||
docker build --build-arg VERSION=${VERSION} -t hunterlong/statping:latest --no-cache -f Dockerfile .
|
||||
docker tag hunterlong/statping:latest hunterlong/statping:v${VERSION}
|
||||
|
||||
# build :dev docker tag
|
||||
docker-build-dev:
|
||||
docker build --build-arg VERSION=${VERSION} -t hunterlong/statping:latest --no-cache -f Dockerfile .
|
||||
docker tag hunterlong/statping:dev hunterlong/statping:dev-v${VERSION}
|
||||
|
||||
# build Cypress UI testing :cypress docker tag
|
||||
docker-build-cypress: clean
|
||||
GOPATH=$(GOPATH) xgo -out statping -go $(GOVERSION) -ldflags "-X main.VERSION=${VERSION} -X main.COMMIT=$(TRAVIS_COMMIT)" --targets=linux/amd64 ./cmd
|
||||
docker build -t hunterlong/statping:cypress -f dev/Dockerfile-cypress .
|
||||
rm -f statping
|
||||
|
||||
# run hunterlong/statping:latest docker image
|
||||
docker-run: docker-build-latest
|
||||
docker run -it -p 8080:8080 hunterlong/statping:latest
|
||||
|
||||
# run hunterlong/statping:dev docker image
|
||||
docker-run-dev: docker-build-dev
|
||||
docker run -t -p 8080:8080 hunterlong/statping:dev
|
||||
|
||||
# run Cypress UI testing, hunterlong/statping:cypress docker image
|
||||
docker-run-cypress: docker-build-cypress
|
||||
docker run -t hunterlong/statping:cypress
|
||||
|
||||
# push the :base and :base-v{VERSION} tag to Docker hub
|
||||
docker-push-base:
|
||||
docker tag hunterlong/statping:base hunterlong/statping:base-v${VERSION}
|
||||
docker push hunterlong/statping:base
|
||||
docker push hunterlong/statping:base-v${VERSION}
|
||||
|
||||
# push the :dev tag to Docker hub
|
||||
docker-push-dev:
|
||||
docker push hunterlong/statping:dev
|
||||
docker push hunterlong/statping:dev-v${VERSION}
|
||||
|
||||
# push the :cypress tag to Docker hub
|
||||
docker-push-cypress:
|
||||
docker push hunterlong/statping:cypress
|
||||
|
||||
# push the :latest tag to Docker hub
|
||||
docker-push-latest:
|
||||
docker tag hunterlong/statping hunterlong/statping:dev
|
||||
docker push hunterlong/statping:latest
|
||||
docker push hunterlong/statping:dev
|
||||
docker push hunterlong/statping:v${VERSION}
|
||||
|
||||
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)
|
||||
databases:
|
||||
docker run --name statping_postgres -p 5432:5432 -e POSTGRES_PASSWORD=password123 -e POSTGRES_USER=root -e POSTGRES_DB=root -d postgres
|
||||
docker run --name statping_mysql -p 3306:3306 -e MYSQL_ROOT_PASSWORD=password123 -e MYSQL_DATABASE=root -d mysql
|
||||
sleep 30
|
||||
|
||||
# install all required golang dependecies
|
||||
dev-deps:
|
||||
go get github.com/stretchr/testify/assert
|
||||
go get golang.org/x/tools/cmd/cover
|
||||
go get github.com/mattn/goveralls
|
||||
go install github.com/mattn/goveralls
|
||||
go get github.com/rendon/testcli
|
||||
go get github.com/robertkrimen/godocdown/godocdown
|
||||
go get github.com/crazy-max/xgo
|
||||
go get github.com/GeertJohan/go.rice
|
||||
go get github.com/GeertJohan/go.rice/rice
|
||||
go install github.com/GeertJohan/go.rice/rice
|
||||
go get github.com/axw/gocov/gocov
|
||||
go get github.com/matm/gocov-html
|
||||
go get github.com/fatih/structs
|
||||
go get github.com/ararog/timeago
|
||||
go get gopkg.in/natefinch/lumberjack.v2
|
||||
go get golang.org/x/crypto/bcrypt
|
||||
generate:
|
||||
cd source && go generate
|
||||
cd handlers/graphql && go generate
|
||||
|
||||
# remove files for a clean compile/build
|
||||
clean:
|
||||
|
@ -269,117 +74,25 @@ clean:
|
|||
find . -name "*.out" -type f -delete
|
||||
find . -name "*.cpu" -type f -delete
|
||||
find . -name "*.mem" -type f -delete
|
||||
rm -rf {build,tmp}
|
||||
rm -rf {build,tmp,docker}
|
||||
|
||||
# tag version using git
|
||||
tag:
|
||||
git tag v${VERSION} --force
|
||||
|
||||
generate:
|
||||
cd source && go generate
|
||||
cd handlers/graphql && go generate
|
||||
|
||||
# compress built binaries into tar.gz and zip formats
|
||||
compress:
|
||||
cd build && mv alpine-linux-amd64 $(BINARY_NAME)
|
||||
cd build && gpg --default-key $(SIGN_KEY) --batch --detach-sign --output statping.asc --armor $(BINARY_NAME)
|
||||
cd build && tar -czvf $(BINARY_NAME)-linux-alpine.tar.gz $(BINARY_NAME) statping.asc && rm -f $(BINARY_NAME) statping.asc
|
||||
cd build && mv cmd-darwin-10.6-amd64 $(BINARY_NAME)
|
||||
cd build && gpg --default-key $(SIGN_KEY) --batch --detach-sign --output statping.asc --armor $(BINARY_NAME)
|
||||
cd build && tar -czvf $(BINARY_NAME)-osx-x64.tar.gz $(BINARY_NAME) statping.asc && rm -f $(BINARY_NAME) statping.asc
|
||||
cd build && mv cmd-darwin-10.6-386 $(BINARY_NAME)
|
||||
cd build && gpg --default-key $(SIGN_KEY) --batch --detach-sign --output statping.asc --armor $(BINARY_NAME)
|
||||
cd build && tar -czvf $(BINARY_NAME)-osx-x32.tar.gz $(BINARY_NAME) statping.asc && rm -f $(BINARY_NAME) statping.asc
|
||||
cd build && mv cmd-linux-amd64 $(BINARY_NAME)
|
||||
cd build && gpg --default-key $(SIGN_KEY) --batch --detach-sign --output statping.asc --armor $(BINARY_NAME)
|
||||
cd build && tar -czvf $(BINARY_NAME)-linux-x64.tar.gz $(BINARY_NAME) statping.asc && rm -f $(BINARY_NAME) statping.asc
|
||||
cd build && mv cmd-linux-386 $(BINARY_NAME)
|
||||
cd build && gpg --default-key $(SIGN_KEY) --batch --detach-sign --output statping.asc --armor $(BINARY_NAME)
|
||||
cd build && tar -czvf $(BINARY_NAME)-linux-x32.tar.gz $(BINARY_NAME) statping.asc && rm -f $(BINARY_NAME) statping.asc
|
||||
cd build && mv cmd-windows-6.0-amd64.exe $(BINARY_NAME).exe
|
||||
cd build && gpg --default-key $(SIGN_KEY) --batch --detach-sign --output statping.asc --armor $(BINARY_NAME).exe
|
||||
cd build && zip $(BINARY_NAME)-windows-x64.zip $(BINARY_NAME).exe statping.asc && rm -f $(BINARY_NAME).exe statping.asc
|
||||
cd build && mv cmd-linux-arm-7 $(BINARY_NAME)
|
||||
cd build && gpg --default-key $(SIGN_KEY) --batch --detach-sign --output statping.asc --armor $(BINARY_NAME)
|
||||
cd build && tar -czvf $(BINARY_NAME)-linux-arm7.tar.gz $(BINARY_NAME) statping.asc && rm -f $(BINARY_NAME) statping.asc
|
||||
cd build && mv cmd-linux-arm-6 $(BINARY_NAME)
|
||||
cd build && gpg --default-key $(SIGN_KEY) --batch --detach-sign --output statping.asc --armor $(BINARY_NAME)
|
||||
cd build && tar -czvf $(BINARY_NAME)-linux-arm6.tar.gz $(BINARY_NAME) statping.asc && rm -f $(BINARY_NAME) statping.asc
|
||||
cd build && mv cmd-linux-arm64 $(BINARY_NAME)
|
||||
cd build && gpg --default-key $(SIGN_KEY) --batch --detach-sign --output statping.asc --armor $(BINARY_NAME)
|
||||
cd build && tar -czvf $(BINARY_NAME)-linux-arm64.tar.gz $(BINARY_NAME) statping.asc && rm -f $(BINARY_NAME) statping.asc
|
||||
|
||||
# push the :dev docker tag using curl
|
||||
publish-dev:
|
||||
curl -H "Content-Type: application/json" --data '{"docker_tag": "dev"}' -X POST $(DOCKER)
|
||||
|
||||
# update the homebrew application to latest for mac
|
||||
publish-homebrew:
|
||||
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-statping/requests
|
||||
|
||||
# install NPM reuqirements for cypress testing
|
||||
cypress-install:
|
||||
cd dev/test && npm install
|
||||
|
||||
# run Cypress UI testing
|
||||
cypress-test: clean cypress-install
|
||||
cd dev/test && npm test
|
||||
|
||||
upload_to_s3:
|
||||
aws s3 cp ./source/css $(ASSETS_BKT) --recursive --exclude "*" --include "*.css"
|
||||
aws s3 cp ./source/js $(ASSETS_BKT) --recursive --exclude "*" --include "*.js"
|
||||
aws s3 cp ./source/font $(ASSETS_BKT) --recursive --exclude "*" --include "*.eot" --include "*.svg" --include "*.woff" --include "*.woff2" --include "*.ttf" --include "*.css"
|
||||
aws s3 cp ./source/scss $(ASSETS_BKT) --recursive --exclude "*" --include "*.scss"
|
||||
aws s3 cp ./install.sh $(ASSETS_BKT)
|
||||
|
||||
travis_s3_creds:
|
||||
mkdir -p ~/.aws
|
||||
echo "[default]\naws_access_key_id = ${AWS_ACCESS_KEY_ID}\naws_secret_access_key = ${AWS_SECRET_ACCESS_KEY}" > ~/.aws/credentials
|
||||
|
||||
# build Statping using a travis ci trigger
|
||||
travis-build: travis_s3_creds upload_to_s3
|
||||
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%2Fstatping/requests
|
||||
curl -H "Content-Type: application/json" --data '{"docker_tag": "latest"}' -X POST $(DOCKER)
|
||||
|
||||
snapcraft-build: build-all
|
||||
PWD=$(shell pwd)
|
||||
cp build/$(BINARY_NAME)-linux-x64.tar.gz build/$(BINARY_NAME)-linux.tar.gz
|
||||
snapcraft clean statping -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 statping -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 statping -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 statping -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 statping_${VERSION}_arm64.snap --release stable
|
||||
snapcraft push statping_${VERSION}_i386.snap --release stable
|
||||
snapcraft push statping_${VERSION}_armhf.snap --release stable
|
||||
|
||||
sign-all:
|
||||
gpg --default-key $SIGN_KEY --detach-sign --armor statpinger
|
||||
|
||||
valid-sign:
|
||||
gpg --verify statping.asc
|
||||
|
||||
# install xgo and pull the xgo docker image
|
||||
xgo-install: clean
|
||||
# install all required golang dependecies
|
||||
dev-deps:
|
||||
go get github.com/stretchr/testify/assert
|
||||
go get golang.org/x/tools/cmd/cover
|
||||
go get github.com/mattn/goveralls
|
||||
go install github.com/mattn/goveralls
|
||||
go get github.com/rendon/testcli
|
||||
go get github.com/robertkrimen/godocdown/godocdown
|
||||
go get github.com/crazy-max/xgo
|
||||
docker pull crazy-max/xgo:${GOVERSION}
|
||||
go get github.com/GeertJohan/go.rice
|
||||
go get github.com/GeertJohan/go.rice/rice
|
||||
go get github.com/axw/gocov/gocov
|
||||
go get github.com/matm/gocov-html
|
||||
go get github.com/fatih/structs
|
||||
go get github.com/ararog/timeago
|
||||
go get gopkg.in/natefinch/lumberjack.v2
|
||||
go get golang.org/x/crypto/bcrypt
|
||||
|
||||
heroku:
|
||||
git push heroku master
|
||||
heroku container:push web
|
||||
heroku container:release web
|
||||
|
||||
checkall:
|
||||
golangci-lint run ./...
|
||||
|
||||
.PHONY: all build build-all build-alpine test-all test test-api docker frontend
|
||||
.PHONY: all build build-all build-alpine test-all test test-api docker frontend up down
|
||||
.SILENT: travis_s3_creds
|
||||
|
|
|
@ -123,7 +123,7 @@ func defaultPort(db string) int {
|
|||
}
|
||||
}
|
||||
|
||||
// EnvToConfig converts environment variables to a DbConfig variable
|
||||
// EnvToConfig converts environment variables to a DbConfig
|
||||
func EnvToConfig() (*DbConfig, error) {
|
||||
var err error
|
||||
|
||||
|
@ -140,7 +140,7 @@ func EnvToConfig() (*DbConfig, error) {
|
|||
domain := utils.Getenv("DOMAIN", "").(string)
|
||||
sqlFile := utils.Getenv("SQL_FILE", "").(string)
|
||||
|
||||
if dbConn != "" {
|
||||
if dbConn != "" && dbConn != "sqlite" {
|
||||
if dbHost == "" {
|
||||
return nil, errors.New("Missing DB_HOST environment variable")
|
||||
}
|
||||
|
|
|
@ -358,5 +358,10 @@ func (c *Core) MigrateDatabase() error {
|
|||
return tx.Error()
|
||||
}
|
||||
log.Infoln("Statping Database Migrated")
|
||||
return tx.Commit().Error()
|
||||
|
||||
if err := tx.Commit().Error(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@ package database
|
|||
import (
|
||||
"fmt"
|
||||
"github.com/hunterlong/statping/types"
|
||||
"github.com/hunterlong/statping/utils"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strconv"
|
||||
|
@ -175,21 +176,16 @@ func (g *GroupQuery) duration() time.Duration {
|
|||
}
|
||||
}
|
||||
|
||||
func toInt(v string) int64 {
|
||||
val, _ := strconv.Atoi(v)
|
||||
return int64(val)
|
||||
}
|
||||
|
||||
func ParseQueries(r *http.Request, o isObject) *GroupQuery {
|
||||
fields := parseGet(r)
|
||||
grouping := fields.Get("group")
|
||||
if grouping == "" {
|
||||
grouping = "hour"
|
||||
}
|
||||
startField := toInt(fields.Get("start"))
|
||||
endField := toInt(fields.Get("end"))
|
||||
limit := toInt(fields.Get("limit"))
|
||||
offset := toInt(fields.Get("offset"))
|
||||
startField := utils.ToInt(fields.Get("start"))
|
||||
endField := utils.ToInt(fields.Get("end"))
|
||||
limit := utils.ToInt(fields.Get("limit"))
|
||||
offset := utils.ToInt(fields.Get("offset"))
|
||||
fill, _ := strconv.ParseBool(fields.Get("fill"))
|
||||
orderBy := fields.Get("order")
|
||||
if limit == 0 {
|
||||
|
@ -228,7 +224,7 @@ func ParseQueries(r *http.Request, o isObject) *GroupQuery {
|
|||
if query.Order != "" {
|
||||
db = db.Order(query.Order)
|
||||
}
|
||||
query.db = db.Debug()
|
||||
query.db = db
|
||||
|
||||
return query
|
||||
}
|
||||
|
|
|
@ -1,53 +1,14 @@
|
|||
statping:
|
||||
container_name: statping
|
||||
image: hunterlong/statping
|
||||
restart: always
|
||||
volumes:
|
||||
- statping_data:/app
|
||||
environment:
|
||||
DB_CONN: sqlite
|
||||
LETSENCRYPT_HOST: demo.statping.com
|
||||
VIRTUAL_HOST: demo.statping.com
|
||||
VIRTUAL_PORT: 8080
|
||||
version: '3.7'
|
||||
|
||||
prometheus:
|
||||
container_name: prometheus
|
||||
image: prom/prometheus:v2.0.0
|
||||
restart: always
|
||||
ports:
|
||||
- 9090:9090
|
||||
volumes:
|
||||
- prometheus_config_data:/etc/prometheus/
|
||||
- prometheus_data:/prometheus
|
||||
links:
|
||||
- statping
|
||||
depends_on:
|
||||
- statping
|
||||
services:
|
||||
|
||||
grafana:
|
||||
container_name: grafana
|
||||
image: grafana/grafana
|
||||
restart: always
|
||||
ports:
|
||||
- 3000:3000
|
||||
volumes:
|
||||
- grafana_data:/var/lib/grafana
|
||||
environment:
|
||||
- GF_SECURITY_ADMIN_PASSWORD=password123
|
||||
- GF_USERS_ALLOW_SIGN_UP=false
|
||||
depends_on:
|
||||
- prometheus
|
||||
links:
|
||||
- prometheus
|
||||
|
||||
|
||||
global:
|
||||
scrape_interval: 30s
|
||||
evaluation_interval: 30s
|
||||
|
||||
scrape_configs:
|
||||
- job_name: 'statping'
|
||||
scrape_interval: 30s
|
||||
bearer_token: 'SECRET API KEY HERE'
|
||||
static_configs:
|
||||
- targets: ['statping:8080']
|
||||
statping:
|
||||
container_name: statping
|
||||
image: hunterlong/statping:latest
|
||||
restart: always
|
||||
volumes:
|
||||
- statping_data:/app
|
||||
environment:
|
||||
DB_CONN: sqlite
|
||||
ports:
|
||||
- 8080:8080
|
||||
|
|
File diff suppressed because one or more lines are too long
4
go.mod
4
go.mod
|
@ -1,6 +1,8 @@
|
|||
module github.com/hunterlong/statping
|
||||
|
||||
go 1.13.5
|
||||
go 1.13
|
||||
|
||||
replace github.com/hunterlong/statping/utils v0.0.0 => ./utils
|
||||
|
||||
require (
|
||||
github.com/99designs/gqlgen v0.10.1
|
||||
|
|
2
go.sum
2
go.sum
|
@ -85,7 +85,9 @@ github.com/gorilla/mux v1.6.1/go.mod h1:1lud6UwP+6orDFRuTfBEV8e9/aOM/c4fVVCaMa2z
|
|||
github.com/gorilla/mux v1.6.2/go.mod h1:1lud6UwP+6orDFRuTfBEV8e9/aOM/c4fVVCaMa2zaAs=
|
||||
github.com/gorilla/mux v1.7.3 h1:gnP5JzjVOuiZD07fKKToCAOjS0yOpj/qPETTXCCS6hw=
|
||||
github.com/gorilla/mux v1.7.3/go.mod h1:1lud6UwP+6orDFRuTfBEV8e9/aOM/c4fVVCaMa2zaAs=
|
||||
github.com/gorilla/websocket v1.2.0 h1:VJtLvh6VQym50czpZzx07z/kw9EgAxI3x1ZB8taTMQQ=
|
||||
github.com/gorilla/websocket v1.2.0/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ=
|
||||
github.com/hashicorp/golang-lru v0.5.0 h1:CL2msUPvZTLb5O648aiLNJw3hnBxN2+1Jq8rCOH9wdo=
|
||||
github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
|
||||
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
|
||||
github.com/jessevdk/go-flags v1.4.0 h1:4IU2WS7AumrZ/40jfhf4QVDMsQwqA7VEHozFRrGARJA=
|
||||
|
|
|
@ -174,8 +174,6 @@ type ComplexityRoot struct {
|
|||
|
||||
type CheckinResolver interface {
|
||||
Service(ctx context.Context, obj *types.Checkin) (*types.Service, error)
|
||||
|
||||
Failures(ctx context.Context, obj *types.Checkin) ([]*types.Failure, error)
|
||||
}
|
||||
type CoreResolver interface {
|
||||
Footer(ctx context.Context, obj *types.Core) (string, error)
|
||||
|
@ -216,8 +214,7 @@ type ServiceResolver interface {
|
|||
Permalink(ctx context.Context, obj *types.Service) (string, error)
|
||||
|
||||
Online24Hours(ctx context.Context, obj *types.Service) (float64, error)
|
||||
|
||||
Failures(ctx context.Context, obj *types.Service) ([]*types.Failure, error)
|
||||
AvgResponse(ctx context.Context, obj *types.Service) (string, error)
|
||||
}
|
||||
type UserResolver interface {
|
||||
Admin(ctx context.Context, obj *types.User) (bool, error)
|
||||
|
@ -1539,13 +1536,13 @@ func (ec *executionContext) _Checkin_failures(ctx context.Context, field graphql
|
|||
Object: "Checkin",
|
||||
Field: field,
|
||||
Args: nil,
|
||||
IsMethod: true,
|
||||
IsMethod: false,
|
||||
}
|
||||
ctx = graphql.WithResolverContext(ctx, rctx)
|
||||
ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx)
|
||||
resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) {
|
||||
ctx = rctx // use context from middleware stack in children
|
||||
return ec.resolvers.Checkin().Failures(rctx, obj)
|
||||
return obj.Failures, nil
|
||||
})
|
||||
if err != nil {
|
||||
ec.Error(ctx, err)
|
||||
|
@ -4326,13 +4323,13 @@ func (ec *executionContext) _Service_avg_response(ctx context.Context, field gra
|
|||
Object: "Service",
|
||||
Field: field,
|
||||
Args: nil,
|
||||
IsMethod: false,
|
||||
IsMethod: true,
|
||||
}
|
||||
ctx = graphql.WithResolverContext(ctx, rctx)
|
||||
ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx)
|
||||
resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) {
|
||||
ctx = rctx // use context from middleware stack in children
|
||||
return obj.AvgResponse, nil
|
||||
return ec.resolvers.Service().AvgResponse(rctx, obj)
|
||||
})
|
||||
if err != nil {
|
||||
ec.Error(ctx, err)
|
||||
|
@ -4437,13 +4434,13 @@ func (ec *executionContext) _Service_failures(ctx context.Context, field graphql
|
|||
Object: "Service",
|
||||
Field: field,
|
||||
Args: nil,
|
||||
IsMethod: true,
|
||||
IsMethod: false,
|
||||
}
|
||||
ctx = graphql.WithResolverContext(ctx, rctx)
|
||||
ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx)
|
||||
resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) {
|
||||
ctx = rctx // use context from middleware stack in children
|
||||
return ec.resolvers.Service().Failures(rctx, obj)
|
||||
return obj.Failures, nil
|
||||
})
|
||||
if err != nil {
|
||||
ec.Error(ctx, err)
|
||||
|
@ -6048,16 +6045,7 @@ func (ec *executionContext) _Checkin(ctx context.Context, sel ast.SelectionSet,
|
|||
atomic.AddUint32(&invalids, 1)
|
||||
}
|
||||
case "failures":
|
||||
field := field
|
||||
out.Concurrently(i, func() (res graphql.Marshaler) {
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
ec.Error(ctx, ec.Recover(ctx, r))
|
||||
}
|
||||
}()
|
||||
res = ec._Checkin_failures(ctx, field, obj)
|
||||
return res
|
||||
})
|
||||
out.Values[i] = ec._Checkin_failures(ctx, field, obj)
|
||||
case "hits":
|
||||
out.Values[i] = ec._Checkin_hits(ctx, field, obj)
|
||||
case "created_at":
|
||||
|
@ -6794,10 +6782,19 @@ func (ec *executionContext) _Service(ctx context.Context, sel ast.SelectionSet,
|
|||
return res
|
||||
})
|
||||
case "avg_response":
|
||||
out.Values[i] = ec._Service_avg_response(ctx, field, obj)
|
||||
if out.Values[i] == graphql.Null {
|
||||
atomic.AddUint32(&invalids, 1)
|
||||
}
|
||||
field := field
|
||||
out.Concurrently(i, func() (res graphql.Marshaler) {
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
ec.Error(ctx, ec.Recover(ctx, r))
|
||||
}
|
||||
}()
|
||||
res = ec._Service_avg_response(ctx, field, obj)
|
||||
if res == graphql.Null {
|
||||
atomic.AddUint32(&invalids, 1)
|
||||
}
|
||||
return res
|
||||
})
|
||||
case "status_code":
|
||||
out.Values[i] = ec._Service_status_code(ctx, field, obj)
|
||||
if out.Values[i] == graphql.Null {
|
||||
|
@ -6809,16 +6806,7 @@ func (ec *executionContext) _Service(ctx context.Context, sel ast.SelectionSet,
|
|||
atomic.AddUint32(&invalids, 1)
|
||||
}
|
||||
case "failures":
|
||||
field := field
|
||||
out.Concurrently(i, func() (res graphql.Marshaler) {
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
ec.Error(ctx, ec.Recover(ctx, r))
|
||||
}
|
||||
}()
|
||||
res = ec._Service_failures(ctx, field, obj)
|
||||
return res
|
||||
})
|
||||
out.Values[i] = ec._Service_failures(ctx, field, obj)
|
||||
case "created_at":
|
||||
out.Values[i] = ec._Service_created_at(ctx, field, obj)
|
||||
if out.Values[i] == graphql.Null {
|
||||
|
|
|
@ -0,0 +1,385 @@
|
|||
VERSION=$(shell cat version.txt)
|
||||
SIGN_KEY=B76D61FAA6DB759466E83D9964B9C6AAE2D55278
|
||||
BINARY_NAME=statping
|
||||
GOBUILD=go build -a
|
||||
GOVERSION=1.13.7
|
||||
XGO=xgo -go $(GOVERSION) --dest=build
|
||||
BUILDVERSION=-ldflags "-X main.VERSION=${VERSION} -X main.COMMIT=$(TRAVIS_COMMIT)"
|
||||
TRVIS_SECRET=lRqWSt5BoekFK6+padJF+b77YkGdispPXEUKNuD7/Hxb7yJMoI8T/n8xZrTHtCZPdjtpy7wIlJCezNoYEZB3l2GnD6Y1QEZEXF7MIxP7hwsB/uSc5/lgdGW0ZLvTBfv6lwI/GjQIklPBW/4xcKJtj4s1YBP7xvqyIb/lDN7TiOqAKF4gqRVVfsxvlkm7j4TiPCXtz17hYQfU8kKBbd+vd3PuZgdWqs//5RwKk3Ld8QR8zoo9xXQVC5NthiyVbHznzczBsHy2cRZZoWxyi7eJM1HrDw8Jn/ivJONIHNv3RgFVn2rAoKu1X8F6FyuvPO0D2hWC62mdO/e0kt4X0mn9/6xlLSKwrHir67UgNVQe3tvlH0xNKh+yNZqR5x9t0V54vNks6Pgbhas5EfLHoWn5cF4kbJzqkXeHjt1msrsqpA3HKbmtwwjJr4Slotfiu22mAhqLSOV+xWV+IxrcNnrEq/Pa+JAzU12Uyxs8swaLJGPRAlWnJwzL9HK5aOpN0sGTuSEsTwj0WxeMMRx25YEq3+LZOgwOy3fvezmeDnKuBZa6MVCoMMpx1CRxMqAOlTGZXHjj+ZPmqDUUBpzAsFSzIdVRgcnDlLy7YRiz3tVWa1G5S07l/VcBN7ZgvCwOWZ0QgOH0MxkoDfhrfoMhNO6MBFDTRKCEl4TroPEhcInmXU8=
|
||||
PUBLISH_BODY='{ "request": { "branch": "master", "message": "Homebrew update version v${VERSION}", "config": { "env": { "VERSION": "${VERSION}", "COMMIT": "$(TRAVIS_COMMIT)" } } } }'
|
||||
TRAVIS_BUILD_CMD='{ "request": { "branch": "master", "message": "Compile master for Statping v${VERSION}", "config": { "os": [ "linux" ], "language": "go", "go": [ "${GOVERSION}" ], "go_import_path": "github.com/hunterlong/statping", "install": true, "sudo": "required", "services": [ "docker" ], "env": { "VERSION": "${VERSION}", "secure": "${TRVIS_SECRET}" }, "matrix": { "allow_failures": [ { "go": "master" } ], "fast_finish": true }, "before_deploy": [ "git config --local user.name \"hunterlong\"", "git config --local user.email \"info@socialeck.com\"", "git tag v$(VERSION) --force"], "deploy": [ { "provider": "releases", "api_key": "$$TAG_TOKEN", "file_glob": true, "file": "build/*", "skip_cleanup": true, "on": {"branch": "master"} } ], "notifications": { "email": false }, "before_script": ["gem install sass"], "script": [ "travis_wait 30 docker pull crazymax/xgo:$(GOVERSION)", "make release" ], "after_success": [], "after_deploy": [ "make publish-homebrew" ] } } }'
|
||||
TEST_DIR=$(GOPATH)/src/github.com/hunterlong/statping
|
||||
PATH:=/usr/local/bin:$(GOPATH)/bin:$(PATH)
|
||||
|
||||
# build all arch's and release Statping
|
||||
release: dev-deps
|
||||
wget -O statping.gpg $(SIGN_URL)
|
||||
gpg --import statping.gpg
|
||||
make build-all
|
||||
|
||||
frontend:
|
||||
cd frontend && yarn serve
|
||||
|
||||
frontend-build:
|
||||
cd frontend && rm -rf dist && yarn build
|
||||
rm -rf source/dist && cp -r frontend/dist source/ && cp -r frontend/src/assets/scss source/dist/
|
||||
cp -r source/tmpl/*.* source/dist/
|
||||
|
||||
# build and push the images to docker hub
|
||||
docker: docker-build-all docker-publish-all
|
||||
|
||||
push-vue:
|
||||
docker build -t hunterlong/statping:vue .
|
||||
docker push hunterlong/statping:vue
|
||||
|
||||
# test all versions of Statping, golang testing and then cypress UI testing
|
||||
test-all: dev-deps test
|
||||
|
||||
# test all versions of Statping, golang testing and then cypress UI testing
|
||||
test-ui: dev-deps docker-build-dev cypress-test
|
||||
|
||||
# testing to be ran on travis ci
|
||||
travis-test: dev-deps cypress-install test coverage
|
||||
|
||||
# build and compile all arch's for Statping
|
||||
build-all: build-mac build-linux build-windows build-alpine compress
|
||||
|
||||
# build all docker tags
|
||||
docker-build-all: docker-build-latest
|
||||
|
||||
# push all docker tags built
|
||||
docker-publish-all: docker-push-latest
|
||||
|
||||
snapcraft: clean snapcraft-build snapcraft-release
|
||||
|
||||
# build Statping for local arch
|
||||
build: compile
|
||||
go mod vendor
|
||||
$(GOBUILD) $(BUILDVERSION) -o $(BINARY_NAME) -v ./cmd
|
||||
|
||||
# build Statping plugins
|
||||
build-plugin:
|
||||
$(GOBUILD) $(BUILDVERSION) -buildmode=plugin -o ./dev/plugin/example.so -v ./dev/plugin
|
||||
|
||||
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
|
||||
STATPING_DIR=$(TEST_DIR) go test -v -p=1 $(BUILDVERSION) -coverprofile=coverage.out ./plugin
|
||||
|
||||
# build Statping debug app
|
||||
build-debug: compile
|
||||
$(GOBUILD) $(BUILDVERSION) -tags debug -o $(BINARY_NAME) -v ./cmd
|
||||
|
||||
# install Statping for local arch and move binary to gopath/src/bin/statping
|
||||
install: build
|
||||
mv $(BINARY_NAME) $(GOPATH)/bin/$(BINARY_NAME)
|
||||
$(GOPATH)/bin/$(BINARY_NAME) version
|
||||
|
||||
# run Statping from local arch
|
||||
run: build
|
||||
./$(BINARY_NAME) --ip 0.0.0.0 --port 8080
|
||||
|
||||
# run Statping with Delve for debugging
|
||||
rundlv:
|
||||
lsof -ti:8080 | xargs kill
|
||||
DB_CONN=sqlite DB_HOST=localhost DB_DATABASE=sqlite DB_PASS=none DB_USER=none GO_ENV=test \
|
||||
dlv --listen=:2345 --headless=true --api-version=2 --accept-multiclient exec ./statping
|
||||
|
||||
killdlv:
|
||||
lsof -ti:2345 | xargs kill
|
||||
|
||||
builddlv:
|
||||
$(GOBUILD) -gcflags "all=-N -l" -o ./$(BINARY_NAME) -v ./cmd
|
||||
|
||||
watch:
|
||||
find . -print | grep -i '.*\.\(go\|gohtml\)' | justrun -v -c \
|
||||
'go build -v -gcflags "all=-N -l" -o statping ./cmd && make rundlv &' \
|
||||
-delay 10s -stdin \
|
||||
-i="Makefile,statping,statup.db,statup.db-journal,handlers/graphql/generated.go"
|
||||
|
||||
# compile assets using SASS and Rice. compiles scss -> css, and run rice embed-go
|
||||
compile: frontend-build generate
|
||||
cd source && rice embed-go
|
||||
|
||||
# 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 Statping golang tetsing files
|
||||
test: clean compile install build-plugin
|
||||
STATPING_DIR=$(TEST_DIR) go test -v -p=1 $(BUILDVERSION) -coverprofile=coverage.out ./...
|
||||
gocov convert coverage.out > coverage.json
|
||||
|
||||
test-api:
|
||||
DB_CONN=sqlite DB_HOST=localhost DB_DATABASE=sqlite DB_PASS=none DB_USER=none statping &
|
||||
sleep 300 && newman run source/tmpl/postman.json -e dev/postman_environment.json --delay-request 500
|
||||
|
||||
# report coverage to Coveralls
|
||||
coverage:
|
||||
$(GOPATH)/bin/goveralls -coverprofile=coverage.out -service=travis -repotoken $(COVERALLS)
|
||||
|
||||
# generate documentation for Statping functions
|
||||
docs:
|
||||
rm -f dev/README.md
|
||||
printf "# Statping Dev Documentation\n" > dev/README.md
|
||||
printf "This readme is automatically generated from the Golang documentation. [](https://godoc.org/github.com/hunterlong/statping)\n\n" > dev/README.md
|
||||
godocdown github.com/hunterlong/statping >> dev/README.md
|
||||
godocdown github.com/hunterlong/statping/cmd >> dev/README.md
|
||||
godocdown github.com/hunterlong/statping/core >> dev/README.md
|
||||
godocdown github.com/hunterlong/statping/handlers >> dev/README.md
|
||||
godocdown github.com/hunterlong/statping/notifiers >> dev/README.md
|
||||
godocdown github.com/hunterlong/statping/plugin >> dev/README.md
|
||||
godocdown github.com/hunterlong/statping/source >> dev/README.md
|
||||
godocdown github.com/hunterlong/statping/types >> dev/README.md
|
||||
godocdown github.com/hunterlong/statping/utils >> dev/README.md
|
||||
gocov-html coverage.json > dev/COVERAGE.html
|
||||
revive -formatter stylish > dev/LINT.md
|
||||
|
||||
#
|
||||
# Build binary for Statping
|
||||
#
|
||||
|
||||
# build Statping for Mac, 64 and 32 bit
|
||||
build-mac: compile
|
||||
mkdir build
|
||||
$(XGO) $(BUILDVERSION) --targets=darwin/amd64,darwin/386 ./cmd
|
||||
|
||||
# build Statping for Linux 64, 32 bit, arm6/arm7
|
||||
build-linux: compile
|
||||
$(XGO) $(BUILDVERSION) --targets=linux/amd64,linux/386,linux/arm-7,linux/arm-6,linux/arm64 ./cmd
|
||||
|
||||
# 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
|
||||
$(XGO) --targets=linux/amd64 -ldflags="-X main.VERSION=${VERSION} -X main.COMMIT=$(TRAVIS_COMMIT) -linkmode external -extldflags -static" -out alpine ./cmd
|
||||
|
||||
#
|
||||
# Docker Makefile commands
|
||||
#
|
||||
|
||||
docker-test:
|
||||
docker-compose -f docker-compose.test.yml -p statping build
|
||||
docker-compose -f docker-compose.test.yml -p statping up -d
|
||||
docker logs -f statping_sut_1
|
||||
docker wait statping_sut_1
|
||||
|
||||
# build :latest docker tag
|
||||
docker-build-latest:
|
||||
docker build --build-arg VERSION=${VERSION} -t hunterlong/statping:latest --no-cache -f Dockerfile .
|
||||
docker tag hunterlong/statping:latest hunterlong/statping:v${VERSION}
|
||||
|
||||
# build :dev docker tag
|
||||
docker-build-dev:
|
||||
docker build --build-arg VERSION=${VERSION} -t hunterlong/statping:latest --no-cache -f Dockerfile .
|
||||
docker tag hunterlong/statping:dev hunterlong/statping:dev-v${VERSION}
|
||||
|
||||
# build Cypress UI testing :cypress docker tag
|
||||
docker-build-cypress: clean
|
||||
GOPATH=$(GOPATH) xgo -out statping -go $(GOVERSION) -ldflags "-X main.VERSION=${VERSION} -X main.COMMIT=$(TRAVIS_COMMIT)" --targets=linux/amd64 ./cmd
|
||||
docker build -t hunterlong/statping:cypress -f dev/Dockerfile-cypress .
|
||||
rm -f statping
|
||||
|
||||
# run hunterlong/statping:latest docker image
|
||||
docker-run: docker-build-latest
|
||||
docker run -it -p 8080:8080 hunterlong/statping:latest
|
||||
|
||||
# run hunterlong/statping:dev docker image
|
||||
docker-run-dev: docker-build-dev
|
||||
docker run -t -p 8080:8080 hunterlong/statping:dev
|
||||
|
||||
# run Cypress UI testing, hunterlong/statping:cypress docker image
|
||||
docker-run-cypress: docker-build-cypress
|
||||
docker run -t hunterlong/statping:cypress
|
||||
|
||||
# push the :base and :base-v{VERSION} tag to Docker hub
|
||||
docker-push-base:
|
||||
docker tag hunterlong/statping:base hunterlong/statping:base-v${VERSION}
|
||||
docker push hunterlong/statping:base
|
||||
docker push hunterlong/statping:base-v${VERSION}
|
||||
|
||||
# push the :dev tag to Docker hub
|
||||
docker-push-dev:
|
||||
docker push hunterlong/statping:dev
|
||||
docker push hunterlong/statping:dev-v${VERSION}
|
||||
|
||||
# push the :cypress tag to Docker hub
|
||||
docker-push-cypress:
|
||||
docker push hunterlong/statping:cypress
|
||||
|
||||
# push the :latest tag to Docker hub
|
||||
docker-push-latest:
|
||||
docker tag hunterlong/statping hunterlong/statping:dev
|
||||
docker push hunterlong/statping:latest
|
||||
docker push hunterlong/statping:dev
|
||||
docker push hunterlong/statping:v${VERSION}
|
||||
|
||||
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)
|
||||
databases:
|
||||
docker run --name statping_postgres -p 5432:5432 -e POSTGRES_PASSWORD=password123 -e POSTGRES_USER=root -e POSTGRES_DB=root -d postgres
|
||||
docker run --name statping_mysql -p 3306:3306 -e MYSQL_ROOT_PASSWORD=password123 -e MYSQL_DATABASE=root -d mysql
|
||||
sleep 30
|
||||
|
||||
# install all required golang dependecies
|
||||
dev-deps:
|
||||
go get github.com/stretchr/testify/assert
|
||||
go get golang.org/x/tools/cmd/cover
|
||||
go get github.com/mattn/goveralls
|
||||
go install github.com/mattn/goveralls
|
||||
go get github.com/rendon/testcli
|
||||
go get github.com/robertkrimen/godocdown/godocdown
|
||||
go get github.com/crazy-max/xgo
|
||||
go get github.com/GeertJohan/go.rice
|
||||
go get github.com/GeertJohan/go.rice/rice
|
||||
go install github.com/GeertJohan/go.rice/rice
|
||||
go get github.com/axw/gocov/gocov
|
||||
go get github.com/matm/gocov-html
|
||||
go get github.com/fatih/structs
|
||||
go get github.com/ararog/timeago
|
||||
go get gopkg.in/natefinch/lumberjack.v2
|
||||
go get golang.org/x/crypto/bcrypt
|
||||
|
||||
# remove files for a clean compile/build
|
||||
clean:
|
||||
rm -rf ./{logs,assets,plugins,*.db,config.yml,.sass-cache,config.yml,statping,build,.sass-cache,index.html,vendor}
|
||||
rm -rf cmd/{logs,assets,plugins,*.db,config.yml,.sass-cache,*.log,*.html,*.json}
|
||||
rm -rf core/{logs,assets,plugins,*.db,config.yml,.sass-cache,*.log}
|
||||
rm -rf handlers/{logs,assets,plugins,*.db,config.yml,.sass-cache,*.log}
|
||||
rm -rf notifiers/{logs,assets,plugins,*.db,config.yml,.sass-cache,*.log}
|
||||
rm -rf source/{logs,assets,plugins,*.db,config.yml,.sass-cache,*.log}
|
||||
rm -rf types/{logs,assets,plugins,*.db,config.yml,.sass-cache,*.log}
|
||||
rm -rf utils/{logs,assets,plugins,*.db,config.yml,.sass-cache,*.log}
|
||||
rm -rf dev/{logs,assets,plugins,*.db,config.yml,.sass-cache,*.log,test/app,plugin/*.so}
|
||||
rm -rf {parts,prime,snap,stage}
|
||||
rm -rf dev/test/cypress/videos
|
||||
rm -f coverage.* sass
|
||||
rm -f source/rice-box.go
|
||||
rm -rf **/*.db-journal
|
||||
rm -rf *.snap
|
||||
find . -name "*.out" -type f -delete
|
||||
find . -name "*.cpu" -type f -delete
|
||||
find . -name "*.mem" -type f -delete
|
||||
rm -rf {build,tmp}
|
||||
|
||||
# tag version using git
|
||||
tag:
|
||||
git tag v${VERSION} --force
|
||||
|
||||
generate:
|
||||
cd source && go generate
|
||||
cd handlers/graphql && go generate
|
||||
|
||||
# compress built binaries into tar.gz and zip formats
|
||||
compress:
|
||||
cd build && mv alpine-linux-amd64 $(BINARY_NAME)
|
||||
cd build && gpg --default-key $(SIGN_KEY) --batch --detach-sign --output statping.asc --armor $(BINARY_NAME)
|
||||
cd build && tar -czvf $(BINARY_NAME)-linux-alpine.tar.gz $(BINARY_NAME) statping.asc && rm -f $(BINARY_NAME) statping.asc
|
||||
cd build && mv cmd-darwin-10.6-amd64 $(BINARY_NAME)
|
||||
cd build && gpg --default-key $(SIGN_KEY) --batch --detach-sign --output statping.asc --armor $(BINARY_NAME)
|
||||
cd build && tar -czvf $(BINARY_NAME)-osx-x64.tar.gz $(BINARY_NAME) statping.asc && rm -f $(BINARY_NAME) statping.asc
|
||||
cd build && mv cmd-darwin-10.6-386 $(BINARY_NAME)
|
||||
cd build && gpg --default-key $(SIGN_KEY) --batch --detach-sign --output statping.asc --armor $(BINARY_NAME)
|
||||
cd build && tar -czvf $(BINARY_NAME)-osx-x32.tar.gz $(BINARY_NAME) statping.asc && rm -f $(BINARY_NAME) statping.asc
|
||||
cd build && mv cmd-linux-amd64 $(BINARY_NAME)
|
||||
cd build && gpg --default-key $(SIGN_KEY) --batch --detach-sign --output statping.asc --armor $(BINARY_NAME)
|
||||
cd build && tar -czvf $(BINARY_NAME)-linux-x64.tar.gz $(BINARY_NAME) statping.asc && rm -f $(BINARY_NAME) statping.asc
|
||||
cd build && mv cmd-linux-386 $(BINARY_NAME)
|
||||
cd build && gpg --default-key $(SIGN_KEY) --batch --detach-sign --output statping.asc --armor $(BINARY_NAME)
|
||||
cd build && tar -czvf $(BINARY_NAME)-linux-x32.tar.gz $(BINARY_NAME) statping.asc && rm -f $(BINARY_NAME) statping.asc
|
||||
cd build && mv cmd-windows-6.0-amd64.exe $(BINARY_NAME).exe
|
||||
cd build && gpg --default-key $(SIGN_KEY) --batch --detach-sign --output statping.asc --armor $(BINARY_NAME).exe
|
||||
cd build && zip $(BINARY_NAME)-windows-x64.zip $(BINARY_NAME).exe statping.asc && rm -f $(BINARY_NAME).exe statping.asc
|
||||
cd build && mv cmd-linux-arm-7 $(BINARY_NAME)
|
||||
cd build && gpg --default-key $(SIGN_KEY) --batch --detach-sign --output statping.asc --armor $(BINARY_NAME)
|
||||
cd build && tar -czvf $(BINARY_NAME)-linux-arm7.tar.gz $(BINARY_NAME) statping.asc && rm -f $(BINARY_NAME) statping.asc
|
||||
cd build && mv cmd-linux-arm-6 $(BINARY_NAME)
|
||||
cd build && gpg --default-key $(SIGN_KEY) --batch --detach-sign --output statping.asc --armor $(BINARY_NAME)
|
||||
cd build && tar -czvf $(BINARY_NAME)-linux-arm6.tar.gz $(BINARY_NAME) statping.asc && rm -f $(BINARY_NAME) statping.asc
|
||||
cd build && mv cmd-linux-arm64 $(BINARY_NAME)
|
||||
cd build && gpg --default-key $(SIGN_KEY) --batch --detach-sign --output statping.asc --armor $(BINARY_NAME)
|
||||
cd build && tar -czvf $(BINARY_NAME)-linux-arm64.tar.gz $(BINARY_NAME) statping.asc && rm -f $(BINARY_NAME) statping.asc
|
||||
|
||||
# push the :dev docker tag using curl
|
||||
publish-dev:
|
||||
curl -H "Content-Type: application/json" --data '{"docker_tag": "dev"}' -X POST $(DOCKER)
|
||||
|
||||
# update the homebrew application to latest for mac
|
||||
publish-homebrew:
|
||||
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-statping/requests
|
||||
|
||||
# install NPM reuqirements for cypress testing
|
||||
cypress-install:
|
||||
cd dev/test && npm install
|
||||
|
||||
# run Cypress UI testing
|
||||
cypress-test: clean cypress-install
|
||||
cd dev/test && npm test
|
||||
|
||||
upload_to_s3:
|
||||
aws s3 cp ./source/css $(ASSETS_BKT) --recursive --exclude "*" --include "*.css"
|
||||
aws s3 cp ./source/js $(ASSETS_BKT) --recursive --exclude "*" --include "*.js"
|
||||
aws s3 cp ./source/font $(ASSETS_BKT) --recursive --exclude "*" --include "*.eot" --include "*.svg" --include "*.woff" --include "*.woff2" --include "*.ttf" --include "*.css"
|
||||
aws s3 cp ./source/scss $(ASSETS_BKT) --recursive --exclude "*" --include "*.scss"
|
||||
aws s3 cp ./install.sh $(ASSETS_BKT)
|
||||
|
||||
travis_s3_creds:
|
||||
mkdir -p ~/.aws
|
||||
echo "[default]\naws_access_key_id = ${AWS_ACCESS_KEY_ID}\naws_secret_access_key = ${AWS_SECRET_ACCESS_KEY}" > ~/.aws/credentials
|
||||
|
||||
# build Statping using a travis ci trigger
|
||||
travis-build: travis_s3_creds upload_to_s3
|
||||
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%2Fstatping/requests
|
||||
curl -H "Content-Type: application/json" --data '{"docker_tag": "latest"}' -X POST $(DOCKER)
|
||||
|
||||
snapcraft-build: build-all
|
||||
PWD=$(shell pwd)
|
||||
cp build/$(BINARY_NAME)-linux-x64.tar.gz build/$(BINARY_NAME)-linux.tar.gz
|
||||
snapcraft clean statping -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 statping -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 statping -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 statping -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 statping_${VERSION}_arm64.snap --release stable
|
||||
snapcraft push statping_${VERSION}_i386.snap --release stable
|
||||
snapcraft push statping_${VERSION}_armhf.snap --release stable
|
||||
|
||||
sign-all:
|
||||
gpg --default-key $SIGN_KEY --detach-sign --armor statpinger
|
||||
|
||||
valid-sign:
|
||||
gpg --verify statping.asc
|
||||
|
||||
# install xgo and pull the xgo docker image
|
||||
xgo-install: clean
|
||||
go get github.com/crazy-max/xgo
|
||||
docker pull crazy-max/xgo:${GOVERSION}
|
||||
|
||||
heroku:
|
||||
git push heroku master
|
||||
heroku container:push web
|
||||
heroku container:release web
|
||||
|
||||
checkall:
|
||||
golangci-lint run ./...
|
||||
|
||||
.PHONY: all build build-all build-alpine test-all test test-api docker frontend
|
||||
.SILENT: travis_s3_creds
|
Loading…
Reference in New Issue