-
-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3d487bf
commit 583e7b2
Showing
42 changed files
with
9,032 additions
and
1 deletion.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
SHELL = /bin/bash | ||
SERVICE_NAME = $(notdir $(CURDIR)) | ||
LATEST_TAG ?= vnext | ||
BRANCH_TAG ?= $(shell git rev-parse --abbrev-ref HEAD | sed 's/[^a-zA-Z0-9]/-/g') | ||
ifneq ($(BRANCH_TAG),main) | ||
LATEST_TAG = $(BRANCH_TAG) | ||
endif | ||
VERSION_TAG ?= $(LATEST_TAG)-$(shell git rev-parse --short=7 --verify HEAD) | ||
GOPATH ?= $(shell go env GOPATH) | ||
WORKING_DIRECTORY := $(shell pwd) | ||
REPOSITORY_DIRECTORY := $(shell cd .. && pwd) | ||
BUILD_COMMIT_DATE ?= $(shell date -u +%FT%TZ --date=@`git show --format='%ct' HEAD --quiet`) | ||
BUILD_SHORT_COMMIT ?= $(shell git show --format=%h HEAD --quiet) | ||
BUILD_DATE ?= $(shell date -u +%FT%TZ) | ||
BUILD_VERSION ?= $(shell git tag --sort version:refname | tail -1 | sed -e "s/^v//") | ||
|
||
default: build | ||
|
||
define build-docker-image | ||
cd .. && \ | ||
mkdir -p .tmp/docker/$(SERVICE_NAME) && \ | ||
awk '{gsub("@NAME@","$(SERVICE_NAME)")} {gsub("@DIRECTORY@","$(SERVICE_NAME)")} {print}' tools/docker/Dockerfile.in > .tmp/docker/$(SERVICE_NAME)/Dockerfile && \ | ||
docker build \ | ||
--network=host \ | ||
--tag ghcr.io/plgd-dev/hub/$(SERVICE_NAME):$(VERSION_TAG) \ | ||
--tag ghcr.io/plgd-dev/hub/$(SERVICE_NAME):$(LATEST_TAG) \ | ||
--tag ghcr.io/plgd-dev/hub/$(SERVICE_NAME):$(BRANCH_TAG) \ | ||
--build-arg COMMIT_DATE="$(BUILD_COMMIT_DATE)" \ | ||
--build-arg SHORT_COMMIT="$(BUILD_SHORT_COMMIT)" \ | ||
--build-arg DATE="$(BUILD_DATE)" \ | ||
--build-arg VERSION="$(BUILD_VERSION)" \ | ||
--target $(1) \ | ||
-f .tmp/docker/$(SERVICE_NAME)/Dockerfile \ | ||
. | ||
endef | ||
|
||
build-servicecontainer: | ||
$(call build-docker-image,service) | ||
|
||
build: build-servicecontainer | ||
|
||
push: build-servicecontainer | ||
docker push plgd/$(SERVICE_NAME):$(VERSION_TAG) | ||
docker push plgd/$(SERVICE_NAME):$(LATEST_TAG) | ||
|
||
GOOGLEAPIS_PATH := $(REPOSITORY_DIRECTORY)/dependency/googleapis | ||
GRPCGATEWAY_MODULE_PATH := $(shell go list -m -f '{{.Dir}}' github.com/grpc-ecosystem/grpc-gateway/v2 | head -1) | ||
|
||
proto/generate: | ||
protoc -I=. -I=$(REPOSITORY_DIRECTORY) -I=$(GOPATH)/src -I=$(GOOGLEAPIS_PATH) -I=$(GRPCGATEWAY_MODULE_PATH) --go_out=$(GOPATH)/src $(WORKING_DIRECTORY)/pb/service.proto | ||
protoc-go-inject-tag -remove_tag_comment -input=$(WORKING_DIRECTORY)/pb/service.pb.go | ||
protoc -I=. -I=$(REPOSITORY_DIRECTORY) -I=$(GOPATH)/src -I=$(GOOGLEAPIS_PATH) -I=$(GRPCGATEWAY_MODULE_PATH) --openapiv2_out=$(REPOSITORY_DIRECTORY) \ | ||
--openapiv2_opt logtostderr=true \ | ||
$(WORKING_DIRECTORY)/pb/service.proto | ||
protoc -I=. -I=$(REPOSITORY_DIRECTORY) -I=$(GOPATH)/src -I=$(GOOGLEAPIS_PATH) -I=$(GRPCGATEWAY_MODULE_PATH) --grpc-gateway_out=$(REPOSITORY_DIRECTORY) \ | ||
--grpc-gateway_opt logtostderr=true \ | ||
--grpc-gateway_opt paths=source_relative \ | ||
$(WORKING_DIRECTORY)/pb/service.proto | ||
protoc -I=. -I=$(REPOSITORY_DIRECTORY) -I=$(GOPATH)/src -I=$(GOOGLEAPIS_PATH) -I=$(GRPCGATEWAY_MODULE_PATH) --go-grpc_out=$(GOPATH)/src \ | ||
$(WORKING_DIRECTORY)/pb/service.proto | ||
protoc -I=. -I=$(REPOSITORY_DIRECTORY) -I=$(GOPATH)/src -I=$(GOOGLEAPIS_PATH) -I=$(GRPCGATEWAY_MODULE_PATH) --doc_out=$(WORKING_DIRECTORY)/pb --doc_opt=markdown,README.md $(WORKING_DIRECTORY)/pb/*.proto | ||
protoc -I=. -I=$(REPOSITORY_DIRECTORY) -I=$(GOPATH)/src -I=$(GOOGLEAPIS_PATH) -I=$(GRPCGATEWAY_MODULE_PATH) --doc_out=$(WORKING_DIRECTORY)/pb --doc_opt=html,doc.html $(WORKING_DIRECTORY)/pb/*.proto | ||
|
||
.PHONY: build-servicecontainer build push proto/generate |
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,48 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"github.com/plgd-dev/hub/v2/pkg/build" | ||
"github.com/plgd-dev/hub/v2/pkg/config" | ||
"github.com/plgd-dev/hub/v2/pkg/fsnotify" | ||
"github.com/plgd-dev/hub/v2/pkg/log" | ||
"github.com/plgd-dev/hub/v2/snippet-service/service" | ||
) | ||
|
||
func run(cfg service.Config, logger log.Logger) error { | ||
fileWatcher, err := fsnotify.NewWatcher(logger) | ||
if err != nil { | ||
return fmt.Errorf("cannot create file fileWatcher: %w", err) | ||
} | ||
defer func() { | ||
_ = fileWatcher.Close() | ||
}() | ||
|
||
s, err := service.New(context.Background(), cfg, fileWatcher, logger) | ||
if err != nil { | ||
return fmt.Errorf("cannot create service: %w", err) | ||
} | ||
err = s.Serve() | ||
if err != nil { | ||
return fmt.Errorf("cannot serve service: %w", err) | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func main() { | ||
var cfg service.Config | ||
if err := config.LoadAndValidateConfig(&cfg); err != nil { | ||
log.Fatalf("cannot load config: %v", err) | ||
} | ||
logger := log.NewLogger(cfg.Log) | ||
log.Set(logger) | ||
logger.Debugf("version: %v, buildDate: %v, buildRevision %v", build.Version, build.BuildDate, build.CommitHash) | ||
log.Infof("config: %v", cfg.String()) | ||
|
||
if err := run(cfg, logger); err != nil { | ||
log.Fatalf("cannot run service: %v", err) | ||
} | ||
} |
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,106 @@ | ||
hubID: "" | ||
log: | ||
level: info | ||
encoding: json | ||
stacktrace: | ||
enabled: false | ||
level: warn | ||
encoderConfig: | ||
timeEncoder: rfc3339nano | ||
apis: | ||
grpc: | ||
address: "0.0.0.0:9100" | ||
sendMsgSize: 4194304 | ||
recvMsgSize: 4194304 | ||
enforcementPolicy: | ||
minTime: 5s | ||
permitWithoutStream: true | ||
keepAlive: | ||
# 0s - means infinity | ||
maxConnectionIdle: 0s | ||
# 0s - means infinity | ||
maxConnectionAge: 0s | ||
# 0s - means infinity | ||
maxConnectionAgeGrace: 0s | ||
time: 2h | ||
timeout: 20s | ||
tls: | ||
caPool: "/secrets/public/rootca.crt" | ||
keyFile: "/secrets/private/cert.key" | ||
certFile: "/secrets/private/cert.crt" | ||
clientCertificateRequired: true | ||
authorization: | ||
ownerClaim: "sub" | ||
authority: "" | ||
audience: "" | ||
http: | ||
maxIdleConns: 16 | ||
maxConnsPerHost: 32 | ||
maxIdleConnsPerHost: 16 | ||
idleConnTimeout: "30s" | ||
timeout: "10s" | ||
tls: | ||
caPool: "/secrets/public/rootca.crt" | ||
keyFile: "/secrets/private/cert.key" | ||
certFile: "/secrets/public/cert.crt" | ||
useSystemCAPool: false | ||
http: | ||
address: "0.0.0.0:9101" | ||
readTimeout: 8s | ||
readHeaderTimeout: 4s | ||
writeTimeout: 16s | ||
idleTimeout: 30s | ||
clients: | ||
storage: | ||
use: mongoDB | ||
mongoDB: | ||
uri: | ||
database: snippetService | ||
maxPoolSize: 16 | ||
maxConnIdleTime: 4m0s | ||
tls: | ||
caPool: "/secrets/public/rootca.crt" | ||
keyFile: "/secrets/private/cert.key" | ||
certFile: "/secrets/public/cert.crt" | ||
useSystemCAPool: false | ||
bulkWrite: | ||
timeout: 1m0s | ||
throttleTime: 500ms | ||
documentLimit: 1000 | ||
cqlDB: | ||
table: "snippets" | ||
hosts: [] | ||
port: 9142 | ||
numConnections: 16 | ||
connectTimeout: 10s | ||
useHostnameResolution: true | ||
reconnectionPolicy: | ||
constant: | ||
interval: 3s | ||
maxRetries: 3 | ||
keyspace: | ||
name: plgdhub | ||
create: true | ||
replication: | ||
class: SimpleStrategy | ||
replication_factor: 1 | ||
tls: | ||
caPool: "/secrets/public/rootca.crt" | ||
keyFile: "/secrets/private/cert.key" | ||
certFile: "/secrets/public/cert.crt" | ||
useSystemCAPool: false | ||
openTelemetryCollector: | ||
grpc: | ||
enabled: false | ||
address: "" | ||
sendMsgSize: 4194304 | ||
recvMsgSize: 4194304 | ||
keepAlive: | ||
time: 10s | ||
timeout: 20s | ||
permitWithoutStream: true | ||
tls: | ||
caPool: "/secrets/public/rootca.crt" | ||
keyFile: "/secrets/private/cert.key" | ||
certFile: "/secrets/public/cert.crt" | ||
useSystemCAPool: false |
Oops, something went wrong.