renamer
This commit is contained in:
parent
ecfa2216f4
commit
7f9ccf86e3
@ -1,53 +0,0 @@
|
||||
include:
|
||||
- project: "devops/pena-continuous-integration"
|
||||
file: "/templates/docker/build-template.gitlab-ci.yml"
|
||||
- project: "devops/pena-continuous-integration"
|
||||
file: "/templates/docker/deploy-template.gitlab-ci.yml"
|
||||
- project: "devops/pena-continuous-integration"
|
||||
file: "/templates/docker/golint.gitlab-ci.yml"
|
||||
- project: "devops/pena-continuous-integration"
|
||||
file: "/templates/docker/service-discovery.gitlab-ci.yml"
|
||||
|
||||
stages:
|
||||
- lint
|
||||
- build
|
||||
- deploy
|
||||
- service-discovery
|
||||
|
||||
lint:
|
||||
extends: .golint_template
|
||||
|
||||
lint:
|
||||
extends: .golint_template
|
||||
|
||||
build-app:
|
||||
stage: build
|
||||
extends: .build_template
|
||||
rules:
|
||||
- if: "$CI_COMMIT_BRANCH == $STAGING_BRANCH || $CI_COMMIT_BRANCH == $PRODUCTION_BRANCH"
|
||||
script:
|
||||
- docker build -t $CI_REGISTRY_IMAGE/$CI_COMMIT_BRANCH-core:$CI_COMMIT_REF_SLUG.$CI_PIPELINE_ID --build-arg GITLAB_TOKEN=$GITLAB_TOKEN $CI_PROJECT_DIR
|
||||
- docker push $CI_REGISTRY_IMAGE/$CI_COMMIT_BRANCH-core:$CI_COMMIT_REF_SLUG.$CI_PIPELINE_ID
|
||||
|
||||
deploy-staging:
|
||||
stage: deploy
|
||||
tags:
|
||||
- staging
|
||||
extends: .deploy_template
|
||||
rules:
|
||||
- if: "$CI_COMMIT_BRANCH == $STAGING_BRANCH"
|
||||
after_script:
|
||||
- docker ps -a
|
||||
|
||||
deploy-prod:
|
||||
stage: deploy
|
||||
tags:
|
||||
- prod
|
||||
extends: .deploy_template
|
||||
rules:
|
||||
- if: "$CI_COMMIT_BRANCH == $PRODUCTION_BRANCH"
|
||||
after_script:
|
||||
- ls
|
||||
|
||||
service-discovery:
|
||||
extends: .sd_artefacts_template
|
@ -1,14 +1,11 @@
|
||||
FROM penahub.gitlab.yandexcloud.net:5050/devops/dockerhub-backup/golang as build
|
||||
FROM gitea.pena/penadevops/container-images/golang:main as build
|
||||
WORKDIR /app
|
||||
RUN apk add git
|
||||
COPY . .
|
||||
ARG GITLAB_TOKEN
|
||||
ENV GOPRIVATE=penahub.gitlab.yandexcloud.net/backend/penahub_common
|
||||
RUN git config --global url."https://buildToken:glpat-axA8ttckx3aPf_xd2Dym@penahub.gitlab.yandexcloud.net/".insteadOf "https://penahub.gitlab.yandexcloud.net/"
|
||||
RUN go mod download
|
||||
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o core
|
||||
|
||||
FROM penahub.gitlab.yandexcloud.net:5050/devops/dockerhub-backup/alpine as prod
|
||||
FROM gitea.pena/penadevops/container-images/alpine:main
|
||||
COPY --from=build /app/core .
|
||||
COPY --from=build /app/schema /schema
|
||||
EXPOSE 1488
|
||||
|
@ -1,10 +1,8 @@
|
||||
version: "3"
|
||||
|
||||
tasks:
|
||||
update-linter:
|
||||
cmds:
|
||||
- go get -u penahub.gitlab.yandexcloud.net/devops/linters/golang.git
|
||||
- go get -u gitea.pena/PenaSide/linters-golang
|
||||
lint:
|
||||
cmds:
|
||||
- task: update-linter
|
||||
- cmd: golangci-lint run -v -c $(go list -f '{{"{{"}}.Dir{{"}}"}}' -m penahub.gitlab.yandexcloud.net/devops/linters/golang.git)/.golangci.yml
|
||||
- cmd: golangci-lint run -v -c $(go list -f '{{"{{"}}.Dir{{"}}"}}' -m gitea.pena/PenaSide/linters-golang)/.golangci.yml
|
||||
|
259
app/app.go
Normal file
259
app/app.go
Normal file
@ -0,0 +1,259 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/go-redis/redis/v8"
|
||||
"github.com/gofiber/fiber/v2"
|
||||
"github.com/skeris/appInit"
|
||||
"go.uber.org/zap"
|
||||
"gitea.pena/PenaSide/hlog"
|
||||
"go.uber.org/zap/zapcore"
|
||||
"gitea.pena/PenaSide/common/log_mw"
|
||||
"gitea.pena/PenaSide/common/privilege"
|
||||
"gitea.pena/SQuiz/common/dal"
|
||||
"gitea.pena/SQuiz/common/healthchecks"
|
||||
"gitea.pena/SQuiz/common/middleware"
|
||||
"gitea.pena/SQuiz/common/model"
|
||||
"gitea.pena/SQuiz/core/brokers"
|
||||
"gitea.pena/SQuiz/core/clients/auth"
|
||||
//"gitea.pena/SQuiz/core/clients/telegram"
|
||||
"gitea.pena/SQuiz/core/initialize"
|
||||
"gitea.pena/SQuiz/core/models"
|
||||
"gitea.pena/SQuiz/core/server"
|
||||
"gitea.pena/SQuiz/core/service"
|
||||
"gitea.pena/SQuiz/core/tools"
|
||||
//"gitea.pena/SQuiz/core/workers"
|
||||
"gitea.pena/PenaSide/trashlog/wrappers/zaptrashlog"
|
||||
"time"
|
||||
)
|
||||
|
||||
type App struct {
|
||||
logger *zap.Logger
|
||||
err chan error
|
||||
}
|
||||
|
||||
func (a App) GetLogger() *zap.Logger {
|
||||
return a.logger
|
||||
}
|
||||
|
||||
func (a App) GetErr() chan error {
|
||||
return a.err
|
||||
}
|
||||
|
||||
var (
|
||||
errInvalidOptions = errors.New("invalid options")
|
||||
)
|
||||
|
||||
var zapOptions = []zap.Option{
|
||||
zap.AddCaller(),
|
||||
zap.AddCallerSkip(2),
|
||||
zap.AddStacktrace(zap.ErrorLevel),
|
||||
}
|
||||
|
||||
var _ appInit.CommonApp = (*App)(nil)
|
||||
|
||||
type Options struct {
|
||||
LoggerProdMode bool `env:"IS_PROD_LOG" default:"false"`
|
||||
IsProd bool `env:"IS_PROD" default:"false"`
|
||||
NumberPort string `env:"PORT" default:"1488"`
|
||||
CrtFile string `env:"CRT" default:"server.crt"`
|
||||
KeyFile string `env:"KEY" default:"server.key"`
|
||||
PostgresCredentials string `env:"PG_CRED" default:"host=localhost port=35432 user=squiz password=Redalert2 dbname=squiz sslmode=disable"`
|
||||
HubAdminUrl string `env:"HUB_ADMIN_URL" default:"http://localhost:8001/"`
|
||||
ServiceName string `env:"SERVICE_NAME" default:"squiz"`
|
||||
AuthServiceURL string `env:"AUTH_URL" default:"http://localhost:8000/"`
|
||||
GrpcHost string `env:"GRPC_HOST" default:"localhost"`
|
||||
GrpcPort string `env:"GRPC_PORT" default:"9000"`
|
||||
KafkaBrokers string `env:"KAFKA_BROKERS" default:"localhost:9092"`
|
||||
KafkaTopic string `env:"KAFKA_TOPIC" default:"test-topic"`
|
||||
KafkaGroup string `env:"KAFKA_GROUP" default:"mailnotifier"`
|
||||
TrashLogHost string `env:"TRASH_LOG_HOST" default:"localhost:7113"`
|
||||
ModuleLogger string `env:"MODULE_LOGGER" default:"core-local"`
|
||||
ClickHouseCred string `env:"CLICK_HOUSE_CRED" default:"tcp://10.8.0.15:9000/default?sslmode=disable"`
|
||||
RedisHost string `env:"REDIS_HOST" default:"localhost:6379"`
|
||||
RedisPassword string `env:"REDIS_PASSWORD" default:"admin"`
|
||||
RedisDB uint64 `env:"REDIS_DB" default:"2"`
|
||||
S3Prefix string `env:"S3_PREFIX"`
|
||||
}
|
||||
|
||||
func New(ctx context.Context, opts interface{}, ver appInit.Version) (appInit.CommonApp, error) {
|
||||
var (
|
||||
err, workerErr error
|
||||
zapLogger *zap.Logger
|
||||
errChan = make(chan error)
|
||||
options Options
|
||||
ok bool
|
||||
)
|
||||
|
||||
if options, ok = opts.(Options); !ok {
|
||||
return App{}, errInvalidOptions
|
||||
}
|
||||
|
||||
if options.LoggerProdMode {
|
||||
zapLogger, err = zap.NewProduction(zapOptions...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
} else {
|
||||
zapLogger, err = zap.NewDevelopment(zapOptions...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
zapLogger = zapLogger.With(
|
||||
zap.String("SvcCommit", ver.Commit),
|
||||
zap.String("SvcVersion", ver.Release),
|
||||
zap.String("SvcBuildTime", ver.BuildTime),
|
||||
)
|
||||
|
||||
clickHouseLogger, err := zaptrashlog.NewCore(ctx, zap.InfoLevel, options.TrashLogHost, ver.Release, ver.Commit, time.Now().Unix())
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
loggerForHlog := zapLogger.WithOptions(zap.WrapCore(func(core zapcore.Core) zapcore.Core {
|
||||
return zapcore.NewTee(core, clickHouseLogger)
|
||||
}))
|
||||
|
||||
loggerHlog := hlog.New(loggerForHlog).Module(options.ModuleLogger)
|
||||
loggerHlog.With(models.AllFields{})
|
||||
loggerHlog.Emit(InfoSvcStarted{})
|
||||
|
||||
authClient := auth.NewAuthClient(options.AuthServiceURL)
|
||||
|
||||
pgdal, err := dal.New(ctx, options.PostgresCredentials, nil)
|
||||
if err != nil {
|
||||
fmt.Println("NEW", err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
chDal, err := dal.NewClickHouseDAL(ctx, options.ClickHouseCred)
|
||||
if err != nil {
|
||||
fmt.Println("failed init clickhouse", err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
kafkaClient, err := initialize.KafkaInit(ctx, initialize.KafkaDeps{
|
||||
KafkaGroup: options.KafkaGroup,
|
||||
KafkaBrokers: options.KafkaBrokers,
|
||||
KafkaTopic: options.KafkaTopic,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
producer := brokers.NewProducer(brokers.ProducerDeps{
|
||||
KafkaClient: kafkaClient,
|
||||
Logger: zapLogger,
|
||||
})
|
||||
|
||||
redisClient := redis.NewClient(&redis.Options{
|
||||
Addr: options.RedisHost,
|
||||
Password: options.RedisPassword,
|
||||
DB: int(options.RedisDB),
|
||||
})
|
||||
err = redisClient.Ping(ctx).Err()
|
||||
if err != nil {
|
||||
panic(fmt.Sprintf("error ping to redis db %v", err))
|
||||
}
|
||||
|
||||
clientData := privilege.Client{
|
||||
URL: options.HubAdminUrl,
|
||||
ServiceName: options.ServiceName,
|
||||
Privileges: model.Privileges,
|
||||
}
|
||||
fiberClient := &fiber.Client{}
|
||||
privilegeController := privilege.NewPrivilege(clientData, fiberClient)
|
||||
go tools.PublishPrivilege(privilegeController, 10, 5*time.Minute)
|
||||
|
||||
// tgClient, err := telegram.NewTelegramClient(ctx, pgdal)
|
||||
// if err != nil {
|
||||
// panic(fmt.Sprintf("failed init tg clietns: %v", err))
|
||||
// }
|
||||
//
|
||||
// tgWC := workers.NewTgListenerWC(workers.Deps{
|
||||
// BotID: int64(6712573453), // todo убрать
|
||||
// Redis: redisClient,
|
||||
// Dal: pgdal,
|
||||
// TgClient: tgClient,
|
||||
// })
|
||||
//
|
||||
// go tgWC.Start(ctx)
|
||||
|
||||
// todo подумать над реализацией всего а то пока мне кажется что немного каша получается такой предикт что через некоторое время
|
||||
// сложно будет разобраться что есть где
|
||||
grpcControllers := initialize.InitRpcControllers(pgdal)
|
||||
grpc, err := server.NewGRPC(zapLogger)
|
||||
if err != nil {
|
||||
fmt.Println("error:", err)
|
||||
panic("err init grpc server")
|
||||
}
|
||||
grpc.Register(grpcControllers)
|
||||
go grpc.Run(server.DepsGrpcRun{
|
||||
Host: options.GrpcHost,
|
||||
Port: options.GrpcPort,
|
||||
})
|
||||
|
||||
app := fiber.New()
|
||||
app.Use(middleware.JWTAuth())
|
||||
app.Use(log_mw.ContextLogger(loggerHlog))
|
||||
app.Get("/liveness", healthchecks.Liveness)
|
||||
app.Get("/readiness", healthchecks.Readiness(&workerErr)) //todo parametrized readiness. should discuss ready reason
|
||||
|
||||
svc := service.New(service.Deps{
|
||||
Dal: pgdal,
|
||||
AuthClient: authClient,
|
||||
Producer: producer,
|
||||
ServiceName: options.ServiceName,
|
||||
ChDAL: chDal,
|
||||
// TelegramClient: tgClient,
|
||||
RedisClient: redisClient,
|
||||
S3Prefix: options.S3Prefix,
|
||||
})
|
||||
|
||||
svc.Register(app)
|
||||
|
||||
loggerHlog.Emit(InfoSvcReady{})
|
||||
|
||||
go func() {
|
||||
defer func() {
|
||||
if pgdal != nil {
|
||||
pgdal.Close()
|
||||
}
|
||||
if chDal != nil {
|
||||
if derr := chDal.Close(ctx); derr != nil {
|
||||
fmt.Printf("error closing clickhouse: %v", derr)
|
||||
}
|
||||
}
|
||||
err := grpc.Stop(ctx)
|
||||
err = app.Shutdown()
|
||||
loggerHlog.Emit(InfoSvcShutdown{Signal: err.Error()})
|
||||
}()
|
||||
|
||||
if options.IsProd {
|
||||
if err := app.ListenTLS(fmt.Sprintf(":%s", options.NumberPort), options.CrtFile, options.KeyFile); err != nil {
|
||||
loggerHlog.Emit(ErrorCanNotServe{
|
||||
Err: err,
|
||||
})
|
||||
errChan <- err
|
||||
}
|
||||
} else {
|
||||
if err := app.Listen(fmt.Sprintf(":%s", options.NumberPort)); err != nil {
|
||||
loggerHlog.Emit(ErrorCanNotServe{
|
||||
Err: err,
|
||||
})
|
||||
errChan <- err
|
||||
}
|
||||
}
|
||||
|
||||
errChan <- nil
|
||||
}()
|
||||
// todo implement helper func for service app type. such as server preparing, logger preparing, healthchecks and etc.
|
||||
return &App{
|
||||
logger: zapLogger,
|
||||
err: errChan,
|
||||
}, err
|
||||
}
|
5
go.sum
5
go.sum
@ -19,8 +19,6 @@ github.com/andybalholm/brotli v1.1.1/go.mod h1:05ib4cKhjx3OQYUY22hTVd34Bc8upXjOL
|
||||
github.com/benbjohnson/clock v1.1.0/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZxNJlLklBHA=
|
||||
github.com/bkaradzic/go-lz4 v1.0.0 h1:RXc4wYsyz985CkXXeX04y4VnZFGG8Rd43pRaHsOXAKk=
|
||||
github.com/bkaradzic/go-lz4 v1.0.0/go.mod h1:0YdlkowM3VswSROI7qDxhRvJ3sLhlFrRRwjwegp5jy4=
|
||||
github.com/caarlos0/env/v8 v8.0.0 h1:POhxHhSpuxrLMIdvTGARuZqR4Jjm8AYmoi/JKlcScs0=
|
||||
github.com/caarlos0/env/v8 v8.0.0/go.mod h1:7K4wMY9bH0esiXSSHlfHLX5xKGQMnkH5Fk4TDSSSzfo=
|
||||
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
|
||||
github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs=
|
||||
github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
|
||||
@ -30,7 +28,6 @@ github.com/cloudflare/golz4 v0.0.0-20150217214814-ef862a3cdc58/go.mod h1:EOBUe0h
|
||||
github.com/cloudflare/golz4 v0.0.0-20240916140612-caecf3c00c06 h1:6aQNgrBLzcUBaJHQjMk4X+jDo9rQtu5E0XNLhRV6pOk=
|
||||
github.com/cloudflare/golz4 v0.0.0-20240916140612-caecf3c00c06/go.mod h1:EOBUe0h4xcZ5GoxqC5SDxFQ8gwyZPKQoEzownBlhI80=
|
||||
github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc=
|
||||
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
|
||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
@ -96,7 +93,6 @@ github.com/klauspost/cpuid/v2 v2.2.9 h1:66ze0taIn2H33fBvCkXuv9BmCwDfafmiIVpKV9kK
|
||||
github.com/klauspost/cpuid/v2 v2.2.9/go.mod h1:rqkxqrZ1EhYM9G+hXH7YdowN5R5RGN6NK4QwQ3WMXF8=
|
||||
github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
|
||||
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
|
||||
github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
|
||||
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
|
||||
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
|
||||
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
|
||||
@ -143,7 +139,6 @@ github.com/pierrec/lz4/v4 v4.1.22 h1:cKFw6uJDK+/gfw5BcDL0JL5aBsAFdsIT18eRtLj7VIU
|
||||
github.com/pierrec/lz4/v4 v4.1.22/go.mod h1:gZWDp/Ze/IJXGXf23ltt2EXimqmTUXEy0GFuRQyBid4=
|
||||
github.com/pioz/faker v1.7.3 h1:Tez8Emuq0UN+/d6mo3a9m/9ZZ/zdfJk0c5RtRatrceM=
|
||||
github.com/pioz/faker v1.7.3/go.mod h1:xSpay5w/oz1a6+ww0M3vfpe40pSIykeUPeWEc3TvVlc=
|
||||
github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA=
|
||||
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
||||
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
|
||||
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
||||
|
16
initialize/rpc_controllers.go
Normal file
16
initialize/rpc_controllers.go
Normal file
@ -0,0 +1,16 @@
|
||||
package initialize
|
||||
|
||||
import (
|
||||
"gitea.pena/SQuiz/common/dal"
|
||||
"gitea.pena/SQuiz/core/rpc_service"
|
||||
)
|
||||
|
||||
type RpcRegister struct {
|
||||
MailNotify *rpc_service.MailNotify
|
||||
}
|
||||
|
||||
func InitRpcControllers(dal *dal.DAL) *RpcRegister {
|
||||
return &RpcRegister{
|
||||
MailNotify: rpc_service.NewMailNotify(dal),
|
||||
}
|
||||
}
|
@ -11,6 +11,7 @@ import (
|
||||
"github.com/gofiber/fiber/v2"
|
||||
"time"
|
||||
"unicode/utf8"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
type Deps struct {
|
||||
|
@ -146,6 +146,7 @@ func (r *Telegram) SettingTgCode(ctx *fiber.Ctx) error {
|
||||
if req.Code == "" || req.Signature == "" {
|
||||
return ctx.Status(fiber.StatusBadRequest).SendString("empty required fields")
|
||||
}
|
||||
|
||||
// data, ok := s.telegramClient.GetFromMap(req.Signature)
|
||||
// if !ok {
|
||||
// return ctx.Status(fiber.StatusBadRequest).SendString("Invalid id, don't have data")
|
||||
|
11
main.go
Normal file
11
main.go
Normal file
@ -0,0 +1,11 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/skeris/appInit"
|
||||
"gitea.pena/SQuiz/core/app"
|
||||
_ "gitea.pena/PenaSide/linters-golang/pkg/dummy"
|
||||
)
|
||||
|
||||
func main() {
|
||||
appInit.Initialize(app.New, app.Options{})
|
||||
}
|
0
service/service.go
Normal file
0
service/service.go
Normal file
Loading…
Reference in New Issue
Block a user