diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..881a58c --- /dev/null +++ b/Dockerfile @@ -0,0 +1,38 @@ +# multistage docker build +FROM messense/rust-musl-cross:aarch64-musl as builder +ENV SQLX_OFFLINE=true +WORKDIR /app + +# Install protoc +RUN apt-get update && apt-get install -y protobuf-compiler +# update rust toolchain +RUN rustup update + +# copy relevant source code +COPY ./chat ./chat +COPY ./protos ./protos + +# build and show build result +RUN cd chat && cargo build --release --target aarch64-unknown-linux-musl +RUN ls /app/chat/target/aarch64-unknown-linux-musl/release + +# final stage +FROM alpine:3.20 + +WORKDIR /app + +# Create a non-root user and group +RUN addgroup -S appgroup && adduser -S appuser -G appgroup + +# Set permissions for /app +RUN chown -R appuser:appgroup /app + +# Switch to the non-root user +USER appuser + +ARG APP_NAME +ARG APP_PORT + +COPY --from=builder /app/chat/target/aarch64-unknown-linux-musl/release/$APP_NAME /app/$APP_NAME + +EXPOSE $APP_PORT diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..57d13bf --- /dev/null +++ b/Makefile @@ -0,0 +1,19 @@ +DOCKER=podman +PWD=$(shell pwd) + + +build-docker: + $(DOCKER) build -t chat-server:latest --build-arg APP_NAME=chat-server --build-arg APP_PORT=6688 . + $(DOCKER) build -t notify-server:latest --build-arg APP_NAME=notify-server --build-arg APP_PORT=6687 . + $(DOCKER) build -t bot-server:latest --build-arg APP_NAME=bot --build-arg APP_PORT=6686 . + $(DOCKER) build -t analytics-server:latest --build-arg APP_NAME=analytics-server --build-arg APP_PORT=6690 . + +run-docker: kill-dockers + $(DOCKER) run --entrypoint /app/chat-server --env OPENAI_API_KEY=$(OPENAI_API_KEY) --name chat -d -p 6688:6688 --mount type=bind,source=$(PWD)/fixtures/chat.yml,target=/app/chat.yml,readonly localhost/chat-server:latest + $(DOCKER) run --entrypoint /app/notify-server --name notify -d -p 6687:6687 --mount type=bind,source=$(PWD)/fixtures/notify.yml,target=/app/notify.yml,readonly localhost/notify-server:latest + $(DOCKER) run --entrypoint /app/bot --env OPENAI_API_KEY=$(OPENAI_API_KEY) --name bot -d -p 6686:6686 --mount type=bind,source=$(PWD)/fixtures/bot.yml,target=/app/bot.yml,readonly localhost/bot-server:latest + $(DOCKER) run --entrypoint /app/analytics-server --name analytics -d -p 6690:6690 --mount type=bind,source=$(PWD)/fixtures/analytics.yml,target=/app/analytics.yml,readonly localhost/analytics-server:latest + +kill-dockers: + @$(DOCKER) kill $(shell $(DOCKER) ps -aq) || true + @$(DOCKER) container prune -f diff --git a/chatapp/buf.gen.yaml b/chatapp/buf.gen.yaml index b023a8a..6f55610 100644 --- a/chatapp/buf.gen.yaml +++ b/chatapp/buf.gen.yaml @@ -4,5 +4,5 @@ inputs: - directory: ../protos plugins: - local: protoc-gen-es - opt: target=ts + opt: target=js out: src/gen diff --git a/chatapp/src/gen/messages_pb.js b/chatapp/src/gen/messages_pb.js new file mode 100644 index 0000000..6888575 --- /dev/null +++ b/chatapp/src/gen/messages_pb.js @@ -0,0 +1,121 @@ +// @generated by protoc-gen-es v2.2.0 with parameter "target=js" +// @generated from file messages.proto (package analytics, syntax proto3) +/* eslint-disable */ + +import { enumDesc, fileDesc, messageDesc, tsEnum } from "@bufbuild/protobuf/codegenv1"; + +/** + * Describes the file messages.proto. + */ +export const file_messages = /*@__PURE__*/ + fileDesc("Cg5tZXNzYWdlcy5wcm90bxIJYW5hbHl0aWNzIr0ECg5BbmFseXRpY3NFdmVudBIoCgdjb250ZXh0GAEgASgLMhcuYW5hbHl0aWNzLkV2ZW50Q29udGV4dBItCglhcHBfc3RhcnQYCCABKAsyGC5hbmFseXRpY3MuQXBwU3RhcnRFdmVudEgAEisKCGFwcF9leGl0GAkgASgLMhcuYW5hbHl0aWNzLkFwcEV4aXRFdmVudEgAEi8KCnVzZXJfbG9naW4YCiABKAsyGS5hbmFseXRpY3MuVXNlckxvZ2luRXZlbnRIABIxCgt1c2VyX2xvZ291dBgLIAEoCzIaLmFuYWx5dGljcy5Vc2VyTG9nb3V0RXZl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FdmVudBIPCgdjaGF0X2lkGAEgASgJIisKD05hdmlnYXRpb25FdmVudBIMCgRmcm9tGAEgASgJEgoKAnRvGAIgASgJItkBCgxFdmVudENvbnRleHQSEQoJY2xpZW50X2lkGAEgASgJEhMKC2FwcF92ZXJzaW9uGAIgASgJEiUKBnN5c3RlbRgDIAEoCzIVLmFuYWx5dGljcy5TeXN0ZW1JbmZvEg8KB3VzZXJfaWQYBCABKAkSCgoCaXAYBSABKAkSEgoKdXNlcl9hZ2VudBgGIAEoCRIjCgNnZW8YByABKAsyFi5hbmFseXRpY3MuR2VvTG9jYXRpb24SEQoJY2xpZW50X3RzGAggASgDEhEKCXNlcnZlcl90cxgJIAEoAyJICgpTeXN0ZW1JbmZvEgoKAm9zGAEgASgJEgwKBGFyY2gYAiABKAkSDgoGbG9jYWxlGAMgASgJEhAKCHRpbWV6b25lGAQgASgJIjwKC0dlb0xvY2F0aW9uEg8KB2NvdW50cnkYASABKAkSDgoGcmVnaW9uGAIgASgJEgwKBGNpdHkYAyABKAliBnByb3RvMw"); + +/** + * Describes the message analytics.AnalyticsEvent. + * Use `create(AnalyticsEventSchema)` to create a new message. + */ +export const AnalyticsEventSchema = /*@__PURE__*/ + messageDesc(file_messages, 0); + +/** + * Describes the message analytics.AppStartEvent. + * Use `create(AppStartEventSchema)` to create a new message. + */ +export const AppStartEventSchema = /*@__PURE__*/ + messageDesc(file_messages, 1); + +/** + * Describes the message analytics.AppExitEvent. + * Use `create(AppExitEventSchema)` to create a new message. + */ +export const AppExitEventSchema = /*@__PURE__*/ + messageDesc(file_messages, 2); + +/** + * Describes the enum analytics.AppExitEvent.ExitCode. + */ +export const AppExitEvent_ExitCodeSchema = /*@__PURE__*/ + enumDesc(file_messages, 2, 0); + +/** + * @generated from enum analytics.AppExitEvent.ExitCode + */ +export const AppExitEvent_ExitCode = /*@__PURE__*/ + tsEnum(AppExitEvent_ExitCodeSchema); + +/** + * Describes the message analytics.UserLoginEvent. + * Use `create(UserLoginEventSchema)` to create a new message. + */ +export const UserLoginEventSchema = /*@__PURE__*/ + messageDesc(file_messages, 3); + +/** + * Describes the message analytics.UserLogoutEvent. + * Use `create(UserLogoutEventSchema)` to create a new message. + */ +export const UserLogoutEventSchema = /*@__PURE__*/ + messageDesc(file_messages, 4); + +/** + * Describes the message analytics.UserRegisterEvent. + * Use `create(UserRegisterEventSchema)` to create a new message. + */ +export const UserRegisterEventSchema = /*@__PURE__*/ + messageDesc(file_messages, 5); + +/** + * Describes the message analytics.ChatCreatedEvent. + * Use `create(ChatCreatedEventSchema)` to create a new message. + */ +export const ChatCreatedEventSchema = /*@__PURE__*/ + messageDesc(file_messages, 6); + +/** + * Describes the message analytics.MessageSentEvent. + * Use `create(MessageSentEventSchema)` to create a new message. + */ +export const MessageSentEventSchema = /*@__PURE__*/ + messageDesc(file_messages, 7); + +/** + * Describes the message analytics.ChatJoinedEvent. + * Use `create(ChatJoinedEventSchema)` to create a new message. + */ +export const ChatJoinedEventSchema = /*@__PURE__*/ + messageDesc(file_messages, 8); + +/** + * Describes the message analytics.ChatLeftEvent. + * Use `create(ChatLeftEventSchema)` to create a new message. + */ +export const ChatLeftEventSchema = /*@__PURE__*/ + messageDesc(file_messages, 9); + +/** + * Describes the message analytics.NavigationEvent. + * Use `create(NavigationEventSchema)` to create a new message. + */ +export const NavigationEventSchema = /*@__PURE__*/ + messageDesc(file_messages, 10); + +/** + * Describes the message analytics.EventContext. + * Use `create(EventContextSchema)` to create a new message. + */ +export const EventContextSchema = /*@__PURE__*/ + messageDesc(file_messages, 11); + +/** + * Describes the message analytics.SystemInfo. + * Use `create(SystemInfoSchema)` to create a new message. + */ +export const SystemInfoSchema = /*@__PURE__*/ + messageDesc(file_messages, 12); + +/** + * Describes the message analytics.GeoLocation. + * Use `create(GeoLocationSchema)` to create a new message. + */ +export const GeoLocationSchema = /*@__PURE__*/ + messageDesc(file_messages, 13); diff --git a/chatapp/src/gen/messages_pb.ts b/chatapp/src/gen/messages_pb.ts deleted file mode 100644 index fb8c051..0000000 --- a/chatapp/src/gen/messages_pb.ts +++ /dev/null @@ -1,506 +0,0 @@ -// @generated by protoc-gen-es v2.2.0 with parameter "target=ts" -// @generated from file messages.proto (package analytics, syntax proto3) -/* eslint-disable */ - -import type { GenEnum, GenFile, GenMessage } from "@bufbuild/protobuf/codegenv1"; -import { enumDesc, fileDesc, messageDesc } from "@bufbuild/protobuf/codegenv1"; -import type { Message } from "@bufbuild/protobuf"; - -/** - * Describes the file messages.proto. - */ -export const file_messages: GenFile = /*@__PURE__*/ - fileDesc("Cg5tZXNzYWdlcy5wcm90bxIJYW5hbHl0aWNzIr0ECg5BbmFseXRpY3NFdmVudBIoCgdjb250ZXh0GAEgASgLMhcuYW5hbHl0aWNzLkV2ZW50Q29udGV4dBItCglhcHBfc3RhcnQYCCABKAsyGC5hbmFseXRpY3MuQXBwU3RhcnRFdmVudEgAEisKCGFwcF9leGl0GAkgASgLMhcuYW5hbHl0aWNzLkFwcEV4aXRFdmVudEgAEi8KCnVzZXJfbG9naW4YCiABKAsyGS5hbmFseXRpY3MuVXNlckxvZ2luRXZlbnRIABIxCgt1c2VyX2xvZ291dBgLIAEoCzIaLmFuYWx5dGljcy5Vc2VyTG9nb3V0RXZlbnRIABI1Cg11c2VyX3JlZ2lzdGVyGAwgASgLMhwuYW5hbHl0aWNzLlVzZXJSZWdpc3RlckV2ZW50SAASMwoMY2hhdF9jcmVhdGVkGA0gASgLMhsuYW5hbHl0aWNzLkNoYXRDcmVhdGVkRXZlbnRIABIzCgxtZXNzYWdlX3NlbnQYDiABKAsyGy5hbmFseXRpY3MuTWVzc2FnZVNlbnRFdmVudEgAEjEKC2NoYXRfam9pbmVkGA8gASgLMhouYW5hbHl0aWNzLkNoYXRKb2luZWRFdmVudEgAEi0KCWNoYXRfbGVmdBgQIAEoCzIYLmFuYWx5dGljcy5DaGF0TGVmdEV2ZW50SAASMAoKbmF2aWdhdGlvbhgRIAEoCzIaLmFuYWx5dGljcy5OYXZpZ2F0aW9uRX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BGFyY2gYAiABKAkSDgoGbG9jYWxlGAMgASgJEhAKCHRpbWV6b25lGAQgASgJIjwKC0dlb0xvY2F0aW9uEg8KB2NvdW50cnkYASABKAkSDgoGcmVnaW9uGAIgASgJEgwKBGNpdHkYAyABKAliBnByb3RvMw"); - -/** - * / 用户事件 - * - * @generated from message analytics.AnalyticsEvent - */ -export type AnalyticsEvent = Message<"analytics.AnalyticsEvent"> & { - /** - * @generated from field: analytics.EventContext context = 1; - */ - context?: EventContext; - - /** - * @generated from oneof analytics.AnalyticsEvent.event_type - */ - eventType: { - /** - * @generated from field: analytics.AppStartEvent app_start = 8; - */ - value: AppStartEvent; - case: "appStart"; - } | { - /** - * @generated from field: analytics.AppExitEvent app_exit = 9; - */ - value: AppExitEvent; - case: "appExit"; - } | { - /** - * @generated from field: analytics.UserLoginEvent user_login = 10; - */ - value: UserLoginEvent; - case: "userLogin"; - } | { - /** - * @generated from field: analytics.UserLogoutEvent user_logout = 11; - */ - value: UserLogoutEvent; - case: "userLogout"; - } | { - /** - * @generated from field: analytics.UserRegisterEvent user_register = 12; - */ - value: UserRegisterEvent; - case: "userRegister"; - } | { - /** - * @generated from field: analytics.ChatCreatedEvent chat_created = 13; - */ - value: ChatCreatedEvent; - case: "chatCreated"; - } | { - /** - * @generated from field: analytics.MessageSentEvent message_sent = 14; - */ - value: MessageSentEvent; - case: "messageSent"; - } | { - /** - * @generated from field: analytics.ChatJoinedEvent chat_joined = 15; - */ - value: ChatJoinedEvent; - case: "chatJoined"; - } | { - /** - * @generated from field: analytics.ChatLeftEvent chat_left = 16; - */ - value: ChatLeftEvent; - case: "chatLeft"; - } | { - /** - * @generated from field: analytics.NavigationEvent navigation = 17; - */ - value: NavigationEvent; - case: "navigation"; - } | { case: undefined; value?: undefined }; -}; - -/** - * Describes the message analytics.AnalyticsEvent. - * Use `create(AnalyticsEventSchema)` to create a new message. - */ -export const AnalyticsEventSchema: GenMessage = /*@__PURE__*/ - messageDesc(file_messages, 0); - -/** - * / 应用启动事件 - * - * @generated from message analytics.AppStartEvent - */ -export type AppStartEvent = Message<"analytics.AppStartEvent"> & { -}; - -/** - * Describes the message analytics.AppStartEvent. - * Use `create(AppStartEventSchema)` to create a new message. - */ -export const AppStartEventSchema: GenMessage = /*@__PURE__*/ - messageDesc(file_messages, 1); - -/** - * / 应用退出事件 - * - * @generated from message analytics.AppExitEvent - */ -export type AppExitEvent = Message<"analytics.AppExitEvent"> & { - /** - * @generated from field: analytics.AppExitEvent.ExitCode exit_code = 1; - */ - exitCode: AppExitEvent_ExitCode; -}; - -/** - * Describes the message analytics.AppExitEvent. - * Use `create(AppExitEventSchema)` to create a new message. - */ -export const AppExitEventSchema: GenMessage = /*@__PURE__*/ - messageDesc(file_messages, 2); - -/** - * @generated from enum analytics.AppExitEvent.ExitCode - */ -export enum AppExitEvent_ExitCode { - /** - * @generated from enum value: EXIT_CODE_UNSPECIFIED = 0; - */ - UNSPECIFIED = 0, - - /** - * @generated from enum value: EXIT_CODE_SUCCESS = 1; - */ - SUCCESS = 1, - - /** - * @generated from enum value: EXIT_CODE_FAILURE = 2; - */ - FAILURE = 2, -} - -/** - * Describes the enum analytics.AppExitEvent.ExitCode. - */ -export const AppExitEvent_ExitCodeSchema: GenEnum = /*@__PURE__*/ - enumDesc(file_messages, 2, 0); - -/** - * / 用户登录事件 - * - * @generated from message analytics.UserLoginEvent - */ -export type UserLoginEvent = Message<"analytics.UserLoginEvent"> & { - /** - * / 用户邮箱(Email 是 PII,需要脱敏) - * - * @generated from field: string email = 1; - */ - email: string; -}; - -/** - * Describes the message analytics.UserLoginEvent. - * Use `create(UserLoginEventSchema)` to create a new message. - */ -export const UserLoginEventSchema: GenMessage = /*@__PURE__*/ - messageDesc(file_messages, 3); - -/** - * / 用户登出事件 - * - * @generated from message analytics.UserLogoutEvent - */ -export type UserLogoutEvent = Message<"analytics.UserLogoutEvent"> & { - /** - * / 用户邮箱(Email 是 PII,需要脱敏) - * - * @generated from field: string email = 1; - */ - email: string; -}; - -/** - * Describes the message analytics.UserLogoutEvent. - * Use `create(UserLogoutEventSchema)` to create a new message. - */ -export const UserLogoutEventSchema: GenMessage = /*@__PURE__*/ - messageDesc(file_messages, 4); - -/** - * / 用户注册事件 - * - * @generated from message analytics.UserRegisterEvent - */ -export type UserRegisterEvent = Message<"analytics.UserRegisterEvent"> & { - /** - * / 用户邮箱(Email 是 PII,需要脱敏) - * - * @generated from field: string email = 1; - */ - email: string; - - /** - * / 工作空间 ID - * - * @generated from field: string workspace_id = 2; - */ - workspaceId: string; -}; - -/** - * Describes the message analytics.UserRegisterEvent. - * Use `create(UserRegisterEventSchema)` to create a new message. - */ -export const UserRegisterEventSchema: GenMessage = /*@__PURE__*/ - messageDesc(file_messages, 5); - -/** - * / chat 创建事件 - * - * @generated from message analytics.ChatCreatedEvent - */ -export type ChatCreatedEvent = Message<"analytics.ChatCreatedEvent"> & { - /** - * / 工作空间 ID - * - * @generated from field: string workspace_id = 1; - */ - workspaceId: string; -}; - -/** - * Describes the message analytics.ChatCreatedEvent. - * Use `create(ChatCreatedEventSchema)` to create a new message. - */ -export const ChatCreatedEventSchema: GenMessage = /*@__PURE__*/ - messageDesc(file_messages, 6); - -/** - * / 消息发送事件 - * - * @generated from message analytics.MessageSentEvent - */ -export type MessageSentEvent = Message<"analytics.MessageSentEvent"> & { - /** - * / chat ID - * - * @generated from field: string chat_id = 1; - */ - chatId: string; - - /** - * / 消息类型 - * - * @generated from field: string type = 2; - */ - type: string; - - /** - * / 消息大小 - * - * @generated from field: int32 size = 3; - */ - size: number; - - /** - * / 附件数量 - * - * @generated from field: int32 total_files = 4; - */ - totalFiles: number; -}; - -/** - * Describes the message analytics.MessageSentEvent. - * Use `create(MessageSentEventSchema)` to create a new message. - */ -export const MessageSentEventSchema: GenMessage = /*@__PURE__*/ - messageDesc(file_messages, 7); - -/** - * / 加入聊天事件 - * - * @generated from message analytics.ChatJoinedEvent - */ -export type ChatJoinedEvent = Message<"analytics.ChatJoinedEvent"> & { - /** - * / chat ID - * - * @generated from field: string chat_id = 1; - */ - chatId: string; -}; - -/** - * Describes the message analytics.ChatJoinedEvent. - * Use `create(ChatJoinedEventSchema)` to create a new message. - */ -export const ChatJoinedEventSchema: GenMessage = /*@__PURE__*/ - messageDesc(file_messages, 8); - -/** - * / 离开聊天事件 - * - * @generated from message analytics.ChatLeftEvent - */ -export type ChatLeftEvent = Message<"analytics.ChatLeftEvent"> & { - /** - * / chat ID - * - * @generated from field: string chat_id = 1; - */ - chatId: string; -}; - -/** - * Describes the message analytics.ChatLeftEvent. - * Use `create(ChatLeftEventSchema)` to create a new message. - */ -export const ChatLeftEventSchema: GenMessage = /*@__PURE__*/ - messageDesc(file_messages, 9); - -/** - * / 页面切换事件 - * - * @generated from message analytics.NavigationEvent - */ -export type NavigationEvent = Message<"analytics.NavigationEvent"> & { - /** - * / 当前页面 - * - * @generated from field: string from = 1; - */ - from: string; - - /** - * / 目标页面 - * - * @generated from field: string to = 2; - */ - to: string; -}; - -/** - * Describes the message analytics.NavigationEvent. - * Use `create(NavigationEventSchema)` to create a new message. - */ -export const NavigationEventSchema: GenMessage = /*@__PURE__*/ - messageDesc(file_messages, 10); - -/** - * / 事件上下文 - * - * @generated from message analytics.EventContext - */ -export type EventContext = Message<"analytics.EventContext"> & { - /** - * / 客户端 ID - * - * @generated from field: string client_id = 1; - */ - clientId: string; - - /** - * / 应用版本 - * - * @generated from field: string app_version = 2; - */ - appVersion: string; - - /** - * / 系统信息 - * - * @generated from field: analytics.SystemInfo system = 3; - */ - system?: SystemInfo; - - /** - * / 用户 ID - * - * @generated from field: string user_id = 4; - */ - userId: string; - - /** - * / 客户端 IP - * - * @generated from field: string ip = 5; - */ - ip: string; - - /** - * / 用户代理 - * - * @generated from field: string user_agent = 6; - */ - userAgent: string; - - /** - * / 地理位置 - * - * @generated from field: analytics.GeoLocation geo = 7; - */ - geo?: GeoLocation; - - /** - * / 客户端时间戳 - * - * @generated from field: int64 client_ts = 8; - */ - clientTs: bigint; - - /** - * / 服务器时间戳 - * - * @generated from field: int64 server_ts = 9; - */ - serverTs: bigint; -}; - -/** - * Describes the message analytics.EventContext. - * Use `create(EventContextSchema)` to create a new message. - */ -export const EventContextSchema: GenMessage = /*@__PURE__*/ - messageDesc(file_messages, 11); - -/** - * / 系统信息 - * - * @generated from message analytics.SystemInfo - */ -export type SystemInfo = Message<"analytics.SystemInfo"> & { - /** - * / 操作系统 - * - * @generated from field: string os = 1; - */ - os: string; - - /** - * / 系统架构 - * - * @generated from field: string arch = 2; - */ - arch: string; - - /** - * / 用户语言 - * - * @generated from field: string locale = 3; - */ - locale: string; - - /** - * / 用户时区 - * - * @generated from field: string timezone = 4; - */ - timezone: string; -}; - -/** - * Describes the message analytics.SystemInfo. - * Use `create(SystemInfoSchema)` to create a new message. - */ -export const SystemInfoSchema: GenMessage = /*@__PURE__*/ - messageDesc(file_messages, 12); - -/** - * @generated from message analytics.GeoLocation - */ -export type GeoLocation = Message<"analytics.GeoLocation"> & { - /** - * @generated from field: string country = 1; - */ - country: string; - - /** - * @generated from field: string region = 2; - */ - region: string; - - /** - * @generated from field: string city = 3; - */ - city: string; -}; - -/** - * Describes the message analytics.GeoLocation. - * Use `create(GeoLocationSchema)` to create a new message. - */ -export const GeoLocationSchema: GenMessage = /*@__PURE__*/ - messageDesc(file_messages, 13); diff --git a/chatapp/src/utils.js b/chatapp/src/utils.js index f6192bb..95c8d9b 100644 --- a/chatapp/src/utils.js +++ b/chatapp/src/utils.js @@ -6,7 +6,10 @@ const SSE_URL = 'http://localhost:6687/events'; let config = null; try { if (invoke) { - config = await invoke('get_config'); + invoke('get_config').then((c) => { + config = c; + console.log('config:', c); + }); } } catch (error) { console.warn('failed to get config: fallback'); diff --git a/fixtures/analytics.yml b/fixtures/analytics.yml new file mode 100644 index 0000000..9789543 --- /dev/null +++ b/fixtures/analytics.yml @@ -0,0 +1,13 @@ +server: + port: 6690 + # clickhouse + db_url: http://host.containers.internal:8123 + db_user: default + db_password: ~ + db_name: analytics + base_dir: /tmp/analytics_server +auth: + pk: | + -----BEGIN PUBLIC KEY----- + MCowBQYDK2VwAyEAfM+lwNHj6TRJ3EGP38lIJcOo9Dlt2u2JzcwWMbu7jQY= + -----END PUBLIC KEY----- diff --git a/fixtures/bot.yml b/fixtures/bot.yml new file mode 100644 index 0000000..e2d2a0b --- /dev/null +++ b/fixtures/bot.yml @@ -0,0 +1,3 @@ +server: + port: 6686 + db_url: postgres://postgres:postgres@host.containers.internal:5432/chat diff --git a/fixtures/chat.yml b/fixtures/chat.yml new file mode 100644 index 0000000..99d149e --- /dev/null +++ b/fixtures/chat.yml @@ -0,0 +1,13 @@ +server: + port: 6688 + db_url: postgres://postgres:postgres@host.containers.internal:5432/chat + base_dir: /tmp/chat_server +auth: + sk: | + -----BEGIN PRIVATE KEY----- + MC4CAQAwBQYDK2VwBCIEIDnxJGEJGoW+mNKHn4vRY1V6BQ3MglSQSuZ8featmyC4 + -----END PRIVATE KEY----- + pk: | + -----BEGIN PUBLIC KEY----- + MCowBQYDK2VwAyEAfM+lwNHj6TRJ3EGP38lIJcOo9Dlt2u2JzcwWMbu7jQY= + -----END PUBLIC KEY----- diff --git a/fixtures/notify.yml b/fixtures/notify.yml new file mode 100644 index 0000000..000f9c8 --- /dev/null +++ b/fixtures/notify.yml @@ -0,0 +1,8 @@ +server: + port: 6687 + db_url: postgres://postgres:postgres@host.containers.internal:5432/chat +auth: + pk: | + -----BEGIN PUBLIC KEY----- + MCowBQYDK2VwAyEAfM+lwNHj6TRJ3EGP38lIJcOo9Dlt2u2JzcwWMbu7jQY= + -----END PUBLIC KEY-----