-
Notifications
You must be signed in to change notification settings - Fork 690
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add: 将版本信息动态传入 add: 应用健康检查 update: Dockerfile, helm fix: go format, go vet修复 update: 文档
- Loading branch information
Showing
17 changed files
with
252 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,9 @@ | ||
.idea | ||
.git | ||
doc | ||
example | ||
logo | ||
tests | ||
.gitignore | ||
build.sh | ||
build.bat | ||
README.MD | ||
README.MD |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
pkgs = $(shell go list ./... | grep -v vendor/) | ||
|
||
DOCKER_IMAGE_NAME ?= feiyu563/prometheus-alert | ||
|
||
BRANCH ?= $(shell git rev-parse --abbrev-ref HEAD) | ||
BUILDDATE ?= $(shell date -I'seconds') | ||
BUILDUSER ?= $(shell whoami)@$(shell hostname) | ||
REVISION ?= $(shell git rev-parse HEAD) | ||
TAG_VERSION ?= $(shell git describe --tags --abbrev=0) | ||
|
||
VERSION_LDFLAGS := \ | ||
-X main.Version=$(TAG_VERSION) \ | ||
-X main.Revision=$(REVISION) \ | ||
-X main.BuildUser=$(BUILDUSER) \ | ||
-X main.BuildDate=$(BUILDDATE) | ||
|
||
all: format vet test build | ||
|
||
.PHONY: format | ||
format: | ||
@echo ">> formatting code" | ||
go fmt $(pkgs) | ||
|
||
.PHONY: vet | ||
vet: | ||
@echo ">> vetting code" | ||
go vet $(pkgs) | ||
|
||
.PHONY: test | ||
test: | ||
@echo ">> running short tests" | ||
go test -short $(pkgs) | ||
|
||
.PHONY: build | ||
build: | ||
@echo ">> building code" | ||
go mod vendor | ||
GO11MODULE=on GO111MODULE=on GOPROXY=https://goproxy.io \ | ||
go build -ldflags "$(VERSION_LDFLAGS)" -o PrometheusAlert | ||
|
||
.PHONY: docker | ||
docker: | ||
@echo ">> building docker image" | ||
docker build -t "$(DOCKER_IMAGE_NAME):$(TAG_VERSION)" . | ||
docker tag "$(DOCKER_IMAGE_NAME):$(TAG_VERSION)" "$(DOCKER_IMAGE_NAME):latest" | ||
|
||
.PHONY: docker-push | ||
docker-push: | ||
@echo ">> pushing docker image" | ||
docker push "$(DOCKER_IMAGE_NAME):$(TAG_VERSION)" | ||
docker push "$(DOCKER_IMAGE_NAME):latest" | ||
|
||
.PHONY: docker-test | ||
docker-test: | ||
@echo ">> testing docker image and PrometheusAlert's health" | ||
cmd/test_image.sh "$(DOCKER_IMAGE_NAME):$(TAG_VERSION)" 8080 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
#!/bin/bash | ||
set -eo pipefail | ||
|
||
docker_image=$1 | ||
port=$2 | ||
|
||
container_id='' | ||
|
||
wait_start() { | ||
for _ in {1..10}; do | ||
if /usr/bin/curl -s -m 5 -f "http://localhost:${port}/health"; then | ||
docker_cleanup | ||
exit 0 | ||
else | ||
sleep 1 | ||
fi | ||
done | ||
|
||
exit 1 | ||
} | ||
|
||
docker_start() { | ||
container_id=$(docker run --rm -d -p "${port}":"${port}" "${docker_image}") | ||
} | ||
|
||
docker_cleanup() { | ||
echo ">> cleaning up container" | ||
docker kill "${container_id}" | ||
} | ||
|
||
if [[ "$#" -ne 2 ]] ; then | ||
echo "Usage: $0 feiyu563/prometheus-alert 8080" >&2 | ||
exit 1 | ||
fi | ||
|
||
docker_start | ||
wait_start |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.