-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from vouch-opensource/init
initial code
- Loading branch information
Showing
18 changed files
with
1,723 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
dist | ||
bin | ||
.bin |
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,31 @@ | ||
ARG GO_VERSION=1.17 | ||
|
||
# FIRST STAGE: build | ||
FROM golang:${GO_VERSION}-alpine AS builder | ||
|
||
# force the go compiler to use modules | ||
ENV GO111MODULE=on | ||
|
||
# install dependencies rewuire to build | ||
RUN apk add --update make git gcc libc-dev | ||
|
||
WORKDIR /app | ||
|
||
# download dependencies | ||
COPY ./go.mod ./go.sum ./ | ||
RUN go mod download | ||
|
||
COPY ./ ./ | ||
|
||
# compile binary | ||
RUN make build | ||
|
||
# FINAL STAGE: run application | ||
FROM alpine:latest | ||
|
||
# dev env always default | ||
ENV ENV=development | ||
|
||
COPY --from=builder /app /app | ||
|
||
ENTRYPOINT ["/app/bin/containerd-healthcheck"] |
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,62 @@ | ||
BIN_NAME = containerd-healthcheck | ||
IMAGE_NAME = vouchio/containerd-healthcheck | ||
ROOT_DIR = $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST)))) | ||
BIN_DIR = $(ROOT_DIR)/bin | ||
BIN_PATH = $(ROOT_DIR)/bin/$(BIN_NAME) | ||
CMD_PATH = $(ROOT_DIR)/cmd/$(BIN_NAME) | ||
VERSION = $(shell cat $(ROOT_DIR)/VERSION) | ||
GIT_BRANCH = $(shell git rev-parse --abbrev-ref HEAD) | ||
GIT_COMMIT = $(shell git rev-parse HEAD) | ||
BUILD_DATE = $(shell date +'%Y-%m-%dT%H:%M:%SZ') | ||
LDFLAGS = "-X main.commit=$(GIT_COMMIT) -X main.version=$(VERSION) -X main.date=$(BUILD_DATE)" | ||
PORT = "9891" | ||
ENV = development | ||
|
||
export PATH := $(PATH):$(ROOT_DIR)/.bin | ||
|
||
.PHONY: tidy | ||
tidy: | ||
@(go mod tidy) | ||
|
||
.PHONY: setup | ||
setup: tidy | ||
@(./scripts/install-go-release.sh "goreleaser/goreleaser") | ||
|
||
.PHONY: build | ||
build: | ||
@(echo "-> Compiling packages") | ||
GOOS=linux go build -ldflags $(LDFLAGS) -o $(BIN_PATH) $(CMD_PATH)/main.go | ||
@(echo "-> Binary created at '$(BIN_PATH)'") | ||
|
||
.PHONY: run | ||
run: | ||
@($(BIN_PATH) --addr ":$(PORT)" --env $(ENV)) | ||
|
||
.PHONY: docker-build | ||
docker-build: | ||
@(docker build -t $(IMAGE_NAME):$(VERSION) .) | ||
|
||
.PHONY: docker-push | ||
docker-push: | ||
@(docker push $(IMAGE_NAME):$(VERSION)) | ||
|
||
.PHONY: docker-run | ||
docker-run: | ||
@(docker run -p 8080:$(PORT) -e "ENV=$(ENV)" -it $(BIN_NAME):latest) | ||
|
||
.PHONY: release | ||
release: | ||
ifeq ($(GIT_BRANCH),master) | ||
@(echo "-> Creating tag '$(VERSION)'") | ||
@(git tag $(VERSION)) | ||
@(echo "-> Pushing tag '$(VERSION)'") | ||
@(git push origin $(VERSION)) | ||
@(echo "-> Releasing to remote repository") | ||
@(goreleaser --rm-dist) | ||
else | ||
@echo "You need to be in branch master" | ||
endif | ||
|
||
.PHONY: release-snapshot | ||
release-snapshot: | ||
@(goreleaser release --skip-publish --snapshot --rm-dist) |
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 @@ | ||
0.2 |
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,68 @@ | ||
package main | ||
|
||
import ( | ||
"containerdhealthcheck/internal/models" | ||
"containerdhealthcheck/internal/server" | ||
"fmt" | ||
"os" | ||
|
||
flag "github.com/spf13/pflag" | ||
|
||
cleanenv "github.com/ilyakaznacheev/cleanenv" | ||
"github.com/sirupsen/logrus" | ||
) | ||
|
||
var version, commit, date string | ||
|
||
func main() { | ||
|
||
var yamlConfig models.YAMLConfig | ||
|
||
// Config | ||
env := flag.StringP("env", "e", "development", "Application environment") | ||
addr := flag.StringP("addr", "a", ":9434", "HTTP address for prometheus endpoint") | ||
configPath := flag.StringP("config", "c", "config.yml", "Path to configuration file") | ||
// Version | ||
versionOpt := flag.BoolP("version", "v", false, "Print app version") | ||
|
||
flag.Parse() | ||
|
||
if *versionOpt { | ||
fmt.Println(version) | ||
os.Exit(0) | ||
} | ||
|
||
logger := logrus.New() | ||
logger.SetFormatter(&logrus.JSONFormatter{}) | ||
|
||
appBuildInfo := models.BuildInfo{ | ||
Version: version, | ||
Commit: commit, | ||
Date: date, | ||
} | ||
|
||
serverConfig := models.ServerConfig{ | ||
Env: *env, | ||
Addr: *addr, | ||
} | ||
|
||
// read configuration from the file and environment variables | ||
if err := cleanenv.ReadConfig(*configPath, &yamlConfig); err != nil { | ||
logger.Fatal(err) | ||
} | ||
|
||
err := cleanenv.ReadConfig(*configPath, &yamlConfig) | ||
|
||
if err != nil { | ||
logger.Fatal(err) | ||
} | ||
|
||
server, err := server.NewApp(serverConfig, yamlConfig, appBuildInfo, logger) | ||
|
||
if err != nil { | ||
logger.Fatal("unexpected error: ", err) | ||
} | ||
|
||
server.Run() | ||
|
||
} |
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,21 @@ | ||
--- | ||
containerd: | ||
socket: /run/containerd/containerd.sock | ||
namespace: services.linuxkit | ||
checks: | ||
- container_task: hello-world-api | ||
http: | ||
url: http://127.0.0.1:3000 | ||
expected_body: Hello | ||
timeout: 1 | ||
execution_period: 4 | ||
initial_delay: 10 | ||
restart_delay: 10 | ||
threshold: 3 | ||
- container_task: google | ||
http: | ||
url: https://www.google.com | ||
timeout: 1 | ||
execution_period: 2 | ||
initial_delay: 2 | ||
threshold: 3 |
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,15 @@ | ||
module containerdhealthcheck | ||
|
||
go 1.16 | ||
|
||
require ( | ||
contrib.go.opencensus.io/exporter/prometheus v0.4.0 | ||
github.com/AppsFlyer/go-sundheit v0.5.0 | ||
github.com/AppsFlyer/go-sundheit/opencensus v0.0.0-20210815135105-b87b5e51e25b | ||
github.com/containerd/containerd v1.5.5 | ||
github.com/ilyakaznacheev/cleanenv v1.2.5 | ||
github.com/prometheus/client_golang v1.11.0 | ||
github.com/sirupsen/logrus v1.8.1 | ||
github.com/spf13/pflag v1.0.5 | ||
go.opencensus.io v0.23.0 | ||
) |
Oops, something went wrong.