-
Notifications
You must be signed in to change notification settings - Fork 0
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 #9 from getz-devs/dev
App v1.0 - ready and passed
- Loading branch information
Showing
63 changed files
with
4,908 additions
and
30 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 |
---|---|---|
|
@@ -23,3 +23,4 @@ go.work.sum | |
|
||
# env gitignore | ||
/config/searcher/local.yaml | ||
/config/searcher-agent/local.yaml |
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,57 @@ | ||
package main | ||
|
||
import ( | ||
"github.com/getz-devs/librakeeper-server/internal/searcher-agent/app" | ||
"github.com/getz-devs/librakeeper-server/internal/searcher-agent/config" | ||
mongostorage "github.com/getz-devs/librakeeper-server/internal/searcher-agent/storage/mongo" | ||
"github.com/getz-devs/librakeeper-server/lib/prettylog" | ||
"log/slog" | ||
"os" | ||
"os/signal" | ||
"syscall" | ||
) | ||
|
||
func main() { | ||
//err := scrapISBNFindBook("9785206000344") | ||
//if err != nil { | ||
// panic(err) | ||
//} | ||
|
||
//const rabbitUrl = "amqp://guest:[email protected]:5672/" | ||
|
||
cfg := config.MustLoad() | ||
|
||
log := prettylog.SetupLogger(cfg.Env) | ||
|
||
log.Info("starting ...", | ||
slog.String("env", cfg.Env), | ||
slog.Any("config", cfg), | ||
) | ||
|
||
databaseMongoConfig := mongostorage.DatabaseMongoConfig{ | ||
ConnectUrl: cfg.DatabaseMongo.ConnectURL, | ||
Database: cfg.DatabaseMongo.DatabaseName, | ||
Collection: cfg.DatabaseMongo.CollectionName, | ||
} | ||
|
||
application := app.New(cfg.ConnectUrl, cfg.QueueName, databaseMongoConfig, log) | ||
go application.AppRabbit.MustRun() | ||
|
||
// --------------------------- Register stop signal --------------------------- | ||
stop := make(chan os.Signal, 1) | ||
signal.Notify(stop, syscall.SIGTERM, syscall.SIGINT) | ||
|
||
// --------------------------- Wait for stop signal --------------------------- | ||
sign := <-stop | ||
|
||
log.Info("shutting down ...", | ||
slog.String("signal", sign.String()), | ||
) | ||
|
||
application.AppRabbit.Close() | ||
application.Storage.Close() | ||
|
||
//application. | ||
|
||
log.Info("application fully stopped") | ||
} |
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,45 +1,57 @@ | ||
package main | ||
|
||
import ( | ||
"github.com/getz-devs/librakeeper-server/internal/searcher/app" | ||
"github.com/getz-devs/librakeeper-server/internal/searcher/config" | ||
"github.com/getz-devs/librakeeper-server/internal/searcher/rabbitProvider" | ||
mongostorage "github.com/getz-devs/librakeeper-server/internal/searcher/storage/mongo" | ||
"github.com/getz-devs/librakeeper-server/lib/prettylog" | ||
"log/slog" | ||
"os" | ||
) | ||
|
||
const ( | ||
envLocal = "local" | ||
envDev = "dev" | ||
envProd = "prod" | ||
"os/signal" | ||
"syscall" | ||
) | ||
|
||
func main() { | ||
cfg := config.MustLoad() | ||
|
||
log := setupLogger(cfg.Env) | ||
log := prettylog.SetupLogger(cfg.Env) | ||
|
||
log.Info("starting ...", | ||
log.Info("startingg ...", | ||
slog.String("env", cfg.Env), | ||
slog.Any("config", cfg), | ||
slog.Int("port", cfg.GRPC.Port), | ||
) | ||
} | ||
|
||
func setupLogger(env string) *slog.Logger { | ||
var log *slog.Logger | ||
|
||
switch env { | ||
case envLocal: | ||
log = slog.New(prettylog.NewHandler(&slog.HandlerOptions{ | ||
Level: slog.LevelInfo, | ||
AddSource: false, | ||
ReplaceAttr: nil, | ||
})) | ||
case envDev: | ||
log = slog.New(slog.NewJSONHandler(os.Stdout, &slog.HandlerOptions{Level: slog.LevelDebug})) | ||
case envProd: | ||
log = slog.New(slog.NewTextHandler(os.Stdout, &slog.HandlerOptions{Level: slog.LevelInfo})) | ||
databaseMongoConfig := mongostorage.DatabaseMongoConfig{ | ||
ConnectUrl: cfg.DatabaseMongo.ConnectURL, | ||
Database: cfg.DatabaseMongo.DatabaseName, | ||
Collection: cfg.DatabaseMongo.CollectionName, | ||
} | ||
|
||
return log | ||
rabbitConfig := rabbitProvider.RabbitConfig{ | ||
RabbitUrl: cfg.Rabbit.URL, | ||
QueueName: cfg.Rabbit.QueueName, | ||
} | ||
|
||
// --------------------------- Start Application server ----------------------- | ||
application := app.New(log, cfg.GRPC.Port, databaseMongoConfig, rabbitConfig) | ||
go application.GRPCSrv.MustRun() | ||
|
||
// --------------------------- Register stop signal --------------------------- | ||
stop := make(chan os.Signal, 1) | ||
signal.Notify(stop, syscall.SIGTERM, syscall.SIGINT) | ||
|
||
// --------------------------- Wait for stop signal --------------------------- | ||
sign := <-stop | ||
|
||
log.Info("shutting down ...", | ||
slog.String("signal", sign.String()), | ||
) | ||
|
||
application.GRPCSrv.Stop() | ||
|
||
application.Storage.Close() | ||
|
||
log.Info("application fully stopped") | ||
} |
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 @@ | ||
package main | ||
|
||
import ( | ||
"github.com/getz-devs/librakeeper-server/internal/server" | ||
"github.com/getz-devs/librakeeper-server/internal/server/config" | ||
"github.com/getz-devs/librakeeper-server/lib/prettylog" | ||
"log/slog" | ||
"os" | ||
) | ||
|
||
func main() { | ||
cfg := config.MustLoad() | ||
log := prettylog.SetupLogger(cfg.Env) | ||
log.Info("starting librakeeper server", slog.String("env", cfg.Env), slog.Int("port", cfg.Server.Port)) | ||
|
||
// Create and run the server | ||
if err := server.NewServer(cfg, log).Run(); err != nil { | ||
log.Error("server error", slog.Any("error", err)) | ||
os.Exit(1) | ||
} | ||
} |
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,9 @@ | ||
env: "local" | ||
|
||
queue_name: "searcher" | ||
connect_url: "amqp://test:test@rabbitmq/" | ||
|
||
database_mongo: | ||
connect_url: "mongodb://mongodb/" | ||
database_name: "docker_searcher" | ||
collection_name_books: "books" |
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,9 @@ | ||
env: "local" | ||
|
||
queue_name: "searcher" | ||
connect_url: "amqp://guest:[email protected]:5672/" | ||
|
||
database_mongo: | ||
connect_url: "mongodb://192.168.1.199:27017/" | ||
database_name: "TempData" | ||
collection_name_books: "books" |
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,13 @@ | ||
env: "local" | ||
|
||
grpc: | ||
port: 8081 | ||
|
||
database_mongo: | ||
connect_url: "mongodb://mongodb/" | ||
database_name: "docker_searcher" | ||
collection_name_books: "books" | ||
|
||
rabbit: | ||
url: "amqp://test:test@rabbitmq/" | ||
queue_name: "searcher" |
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 @@ | ||
env: "local" | ||
|
||
storage_path: "./storage/sso.db" | ||
grpc: | ||
port: 44044 | ||
timeout: 10h | ||
|
||
database_mongo: | ||
connect_url: "mongodb://192.168.1.199:27017/" | ||
database_name: "TempData" | ||
collection_name_books: "books" | ||
|
||
rabbit: | ||
url: "amqp://guest:[email protected]:5672/" | ||
queue_name: "searcher" |
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,11 @@ | ||
server: | ||
allowed_origins: | ||
- https://libra.example.com | ||
- http://localhost:3000 | ||
|
||
database: | ||
uri: mongodb://user:[email protected]:1234 | ||
name: database_name | ||
|
||
auth: | ||
config_path: firebase.json |
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,17 @@ | ||
env: "local" | ||
|
||
server: | ||
port: 8080 | ||
allowed_origins: | ||
- https://libra.potat.dev | ||
- http://localhost:3000 | ||
|
||
database: | ||
uri: mongodb://mongodb/ | ||
name: docker_server | ||
|
||
auth: | ||
config_path: /config/secret.json | ||
|
||
grpc: | ||
addr: searcher:8081 |
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,38 @@ | ||
# Исключаем сборочные артефакты | ||
**/*.exe | ||
**/*.exe~ | ||
**/*.dll | ||
**/*.so | ||
**/*.dylib | ||
**/*.test | ||
**/*.out | ||
|
||
# Исключаем временные файлы редактора | ||
**/*~ | ||
**/*.swp | ||
**/*.swo | ||
**/*.swn | ||
*.log | ||
|
||
# Исключаем директории | ||
.git | ||
.gitignore | ||
node_modules | ||
vendor | ||
|
||
# Исключаем файлы конфигурации и кэш | ||
.env | ||
*.env | ||
.cache | ||
|
||
# Исключаем Dockerfile, docker-compose.yml и все внутри docker, чтобы избежать копирования самого файла .dockerignore | ||
docker/ | ||
Dockerfile* | ||
|
||
# Исключаем бинарные файлы, если они есть в корне | ||
searcher | ||
searcher-agent | ||
server | ||
|
||
# Исключаем файлы тестов | ||
tests/ |
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 @@ | ||
# Используем официальный образ Golang | ||
FROM golang:1.22-alpine AS builder | ||
|
||
# Устанавливаем рабочую директорию внутри контейнера | ||
WORKDIR /app | ||
|
||
# Копируем весь проект (вверх на два уровня от текущей директории docker) | ||
COPY ../.. . | ||
|
||
# Загружаем зависимости | ||
RUN go mod download | ||
|
||
# Сборка бинарника для searcher | ||
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o searcher cmd/searcher/main.go | ||
|
||
# Создаем минимальный образ для запуска | ||
FROM alpine:latest | ||
|
||
# Устанавливаем рабочую директорию внутри контейнера | ||
WORKDIR /root/ | ||
|
||
# Копируем собранный бинарник из этапа сборки | ||
COPY --from=builder /app/searcher . | ||
|
||
# Копируем конфигурационные файлы | ||
COPY --from=builder /app/config/searcher /config | ||
|
||
EXPOSE 8081 | ||
|
||
# Устанавливаем команду по умолчанию для запуска | ||
CMD ["./searcher"] |
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,29 @@ | ||
# Используем официальный образ Golang | ||
FROM golang:1.22-alpine AS builder | ||
|
||
# Устанавливаем рабочую директорию внутри контейнера | ||
WORKDIR /app | ||
|
||
# Копируем весь проект (вверх на два уровня от текущей директории docker) | ||
COPY ../.. . | ||
|
||
# Загружаем зависимости | ||
RUN go mod download | ||
|
||
# Сборка бинарника для searcher-agent | ||
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o searcher-agent cmd/searcher-agent/main.go | ||
|
||
# Создаем минимальный образ для запуска | ||
FROM alpine:latest | ||
|
||
# Устанавливаем рабочую директорию внутри контейнера | ||
WORKDIR /root/ | ||
|
||
# Копируем собранный бинарник из этапа сборки | ||
COPY --from=builder /app/searcher-agent . | ||
|
||
# Копируем конфигурационные файлы | ||
COPY --from=builder /app/config/searcher-agent /config | ||
|
||
# Устанавливаем команду по умолчанию для запуска | ||
CMD ["./searcher-agent"] |
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,30 @@ | ||
# Используем официальный образ Golang | ||
FROM golang:1.22-alpine AS builder | ||
|
||
# Устанавливаем рабочую директорию внутри контейнера | ||
WORKDIR /app | ||
|
||
# Копируем весь проект (вверх на два уровня от текущей директории docker) | ||
COPY ../.. . | ||
|
||
# Загружаем зависимости | ||
RUN go mod download | ||
|
||
# Сборка бинарника для server | ||
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o server cmd/server/main.go | ||
|
||
# Создаем минимальный образ для запуска | ||
FROM alpine:latest | ||
|
||
# Устанавливаем рабочую директорию внутри контейнера | ||
WORKDIR /root/ | ||
|
||
# Копируем собранный бинарник из этапа сборки | ||
COPY --from=builder /app/server . | ||
|
||
# Копируем конфигурационные файлы | ||
COPY --from=builder /app/config/server /config | ||
|
||
EXPOSE 8080 | ||
# Устанавливаем команду по умолчанию для запуска | ||
CMD ["./server"] |
Oops, something went wrong.