From ee07c55b362d23ccdec04b799dd898b399ce0b69 Mon Sep 17 00:00:00 2001 From: Gergely Radics Date: Thu, 21 Aug 2025 13:52:53 +0200 Subject: [PATCH 1/2] feat: added working docker compose with build container --- .env.example | 3 +++ .gitignore | 2 +- README.md | 12 ++++++++++-- docker-compose.yml | 10 ++++++++++ docker/Dockerfile-bot | 15 +++++++++++++++ 5 files changed, 39 insertions(+), 3 deletions(-) create mode 100644 .env.example create mode 100644 docker-compose.yml create mode 100644 docker/Dockerfile-bot diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..aca5108 --- /dev/null +++ b/.env.example @@ -0,0 +1,3 @@ +# This is the API key for Google Gemini, which you can obtain from the Google Cloud Console +GEMINI_API_KEY= +ADDR=:8080 diff --git a/.gitignore b/.gitignore index 0df9dec..4e4dcd2 100644 --- a/.gitignore +++ b/.gitignore @@ -27,4 +27,4 @@ go.work.sum history-gemini/* !history-gemini/.gitkeep bot-context/* -!bot-context/.gitkeep \ No newline at end of file +!bot-context/.gitkeep diff --git a/README.md b/README.md index 50402da..6b1cfbc 100644 --- a/README.md +++ b/README.md @@ -38,9 +38,10 @@ Required env variable(s): Optional env variable(s): - `ADDR` - Listen address for the server (Default: `:8080`) -- `GEMINI_MODEL` - Model to use (Default: `gemini-2.5-flash-preview-04-17`) +- `GEMINI_MODEL` - Model to use (Default: `gemini-2.5-flash`) - `MCP_SERVERS` - MCP HTTP stream server for external function calls (Eg.: `http://localhost:8081/sse`), this could be a comma separated list for multiple servers - `SEARCH_ENABLE` - Allow to use Google search for the AI service (Default: `false`, it won't work together with MCP servers) +- `HISTORY_SUMMARY` - After how many messages the history should be summarized (Default: `20`, `0` means no summary, both model and user messages counts) All the history will be stored under the `history-gemini` folder. @@ -83,6 +84,14 @@ If you have a user id, you can use it in the call. curl -v -H "X-User-ID: someuserid1" -X POST http://127.0.0.1:8080/message -d "message=Hi there" ``` +### Use docker + +There is a provided docker compose file. +First make a copy of the `.env.example` file and rename it to `.env` and set your Gemini api key, then you can run the following command to start the server: +``` +docker-compose up +``` + ### Client examples @@ -132,7 +141,6 @@ Optional env variables: - `GRAPHQL_URL` - GraphQL base url (Default: `https://graph.facebook.com/v22.0`) - `ADDR` - Server listening address (Default: `:8082`) - `AI_SERVICE` - AI service (the server-bot's) address (Default: `http://127.0.0.1:8080`) -- `HISTORY_SUMMARY` - After how many messages the history should be summarized (Default: `20`, `0` means no summary, both model and user messages counts) Then you can start chatting with the bot via sending a message to the page. (If you configured an MCP in the AI service it will be called too.) diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..fdd727c --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,10 @@ +# docker-compose.yml +version: '3.4' +services: + bot: + build: + context: . + dockerfile: docker/Dockerfile-bot + target: production + env_file: + - .env diff --git a/docker/Dockerfile-bot b/docker/Dockerfile-bot new file mode 100644 index 0000000..de95db2 --- /dev/null +++ b/docker/Dockerfile-bot @@ -0,0 +1,15 @@ +FROM golang:1.25 AS build + +WORKDIR /go/src/app +COPY . . + +RUN go mod download +RUN CGO_ENABLED=0 go build -o /go/bin/server-bot -ldflags '-w -s' cmd/server-bot/main.go + + +FROM gcr.io/distroless/static as production +COPY --from=build /go/bin/server-bot /server-bot +COPY --from=build /go/src/app/history-gemini /history-gemini +COPY --from=build /go/src/app/bot-context /bot-context +COPY --from=build /go/src/app/personality.json /personality.json +ENTRYPOINT ["/server-bot"] From b1792083f51fc3a0c360b00752e07ca10a45c588 Mon Sep 17 00:00:00 2001 From: Gergely Radics Date: Thu, 21 Aug 2025 14:24:13 +0200 Subject: [PATCH 2/2] feat: added telegram client in docker --- .env.example | 5 ++++- cmd/server-bot/main.go | 3 ++- docker-compose.yml | 19 +++++++++++++++++++ docker/Dockerfile-bot | 11 ++++++----- docker/Dockerfile-client-telegram | 12 ++++++++++++ 5 files changed, 43 insertions(+), 7 deletions(-) create mode 100644 docker/Dockerfile-client-telegram diff --git a/.env.example b/.env.example index aca5108..cf4b8e9 100644 --- a/.env.example +++ b/.env.example @@ -1,3 +1,6 @@ -# This is the API key for Google Gemini, which you can obtain from the Google Cloud Console +# Bot config GEMINI_API_KEY= ADDR=:8080 + +# Telegram client config +BOT_TOKEN= diff --git a/cmd/server-bot/main.go b/cmd/server-bot/main.go index 648429d..03e9362 100644 --- a/cmd/server-bot/main.go +++ b/cmd/server-bot/main.go @@ -24,7 +24,8 @@ import ( func main() { logger := slog.New(slog.NewJSONHandler(os.Stdout, &slog.HandlerOptions{ - Level: slog.LevelDebug, // TODO: set to configurable level + // Level: slog.LevelDebug, // TODO: set to configurable level + Level: slog.LevelInfo, })) addr := os.Getenv("ADDR") diff --git a/docker-compose.yml b/docker-compose.yml index fdd727c..0c74cb1 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -8,3 +8,22 @@ services: target: production env_file: - .env + ports: + - "8080:8080" + volumes: + - bot-data:/app + + client-telegram: + build: + context: . + dockerfile: docker/Dockerfile-client-telegram + target: production + environment: + AI_SERVICE: http://bot:8080 + env_file: + - .env + depends_on: + - bot + +volumes: + bot-data: \ No newline at end of file diff --git a/docker/Dockerfile-bot b/docker/Dockerfile-bot index de95db2..5983600 100644 --- a/docker/Dockerfile-bot +++ b/docker/Dockerfile-bot @@ -8,8 +8,9 @@ RUN CGO_ENABLED=0 go build -o /go/bin/server-bot -ldflags '-w -s' cmd/server-bot FROM gcr.io/distroless/static as production -COPY --from=build /go/bin/server-bot /server-bot -COPY --from=build /go/src/app/history-gemini /history-gemini -COPY --from=build /go/src/app/bot-context /bot-context -COPY --from=build /go/src/app/personality.json /personality.json -ENTRYPOINT ["/server-bot"] +WORKDIR /app +COPY --from=build /go/bin/server-bot server-bot +COPY --from=build /go/src/app/history-gemini history-gemini +COPY --from=build /go/src/app/bot-context bot-context +COPY --from=build /go/src/app/personality.json personality.json +ENTRYPOINT ["./server-bot"] diff --git a/docker/Dockerfile-client-telegram b/docker/Dockerfile-client-telegram new file mode 100644 index 0000000..59dced4 --- /dev/null +++ b/docker/Dockerfile-client-telegram @@ -0,0 +1,12 @@ +FROM golang:1.25 AS build + +WORKDIR /go/src/app +COPY . . + +RUN go mod download +RUN CGO_ENABLED=0 go build -o /go/bin/client-telegram -ldflags '-w -s' cmd/client-telegram/main.go + + +FROM gcr.io/distroless/static as production +COPY --from=build /go/bin/client-telegram /client-telegram +ENTRYPOINT ["/client-telegram"]