From bdc8ef52e99b10a1bcc07f744da5d5914355595d Mon Sep 17 00:00:00 2001 From: levlam Date: Sat, 7 Nov 2020 19:31:00 +0300 Subject: [PATCH 01/10] Fix possible CE. --- telegram-bot-api/Client.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/telegram-bot-api/Client.h b/telegram-bot-api/Client.h index 2abf934..b748fbb 100644 --- a/telegram-bot-api/Client.h +++ b/telegram-bot-api/Client.h @@ -386,11 +386,11 @@ class Client : public WebhookActor::Callback { static td::Result get_required_string_arg(const Query *query, Slice field_name); - static int64 get_message_id(const Query *query, Slice field_name = "message_id"); + static int64 get_message_id(const Query *query, Slice field_name = Slice("message_id")); - static td::Result get_inline_message_id(const Query *query, Slice field_name = "inline_message_id"); + static td::Result get_inline_message_id(const Query *query, Slice field_name = Slice("inline_message_id")); - static td::Result get_user_id(const Query *query, Slice field_name = "user_id"); + static td::Result get_user_id(const Query *query, Slice field_name = Slice("user_id")); int64 extract_yet_unsent_message_query_id(int64 chat_id, int64 message_id, bool *is_reply_to_message_deleted); From 94846848b7b1c9db380825123997e49fbe3ebd58 Mon Sep 17 00:00:00 2001 From: levlam Date: Sat, 7 Nov 2020 19:34:08 +0300 Subject: [PATCH 02/10] Make Client.start_up private. --- telegram-bot-api/Client.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/telegram-bot-api/Client.h b/telegram-bot-api/Client.h index b748fbb..eb1ecff 100644 --- a/telegram-bot-api/Client.h +++ b/telegram-bot-api/Client.h @@ -41,8 +41,6 @@ class Client : public WebhookActor::Callback { Client(td::ActorShared<> parent, const td::string &bot_token, bool is_test_dc, td::int64 tqueue_id, std::shared_ptr parameters, td::ActorId stat_actor); - void start_up() override; - void send(PromisedQueryPtr query) override; void close(); @@ -517,6 +515,8 @@ class Client : public WebhookActor::Callback { void long_poll_wakeup(bool force_flag); + void start_up() override; + void raw_event(const td::Event::Raw &event) override; void loop() override; From fbb8b4ce377afb4065b0dc4d1becbf555948c3d4 Mon Sep 17 00:00:00 2001 From: levlam Date: Sun, 8 Nov 2020 12:10:27 +0300 Subject: [PATCH 03/10] Update TDLib. --- td | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/td b/td index ff0c727..b21d667 160000 --- a/td +++ b/td @@ -1 +1 @@ -Subproject commit ff0c727ee2129b66a2908e46edc3bc9f7774e834 +Subproject commit b21d667bdfb13df15f249896155f98f175a89657 From cbd974f850e4ed76346f8a4087b3370f8b96ae05 Mon Sep 17 00:00:00 2001 From: levlam Date: Sun, 8 Nov 2020 14:01:44 +0300 Subject: [PATCH 04/10] Update TDLib. --- CMakeLists.txt | 4 ++-- td | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 2d34610..7df120f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -48,7 +48,7 @@ if (CLANG OR GCC) endif() endif() -set(TG_HTTP_CLIENT_SOURCE +set(TELEGRAM_BOT_API_SOURCE telegram-bot-api/telegram-bot-api.cpp telegram-bot-api/Client.cpp @@ -70,7 +70,7 @@ set(TG_HTTP_CLIENT_SOURCE telegram-bot-api/WebhookActor.h ) -add_executable(telegram-bot-api ${TG_HTTP_CLIENT_SOURCE}) +add_executable(telegram-bot-api ${TELEGRAM_BOT_API_SOURCE}) target_include_directories(telegram-bot-api PRIVATE $) target_link_libraries(telegram-bot-api PRIVATE memprof tdactor tdcore tddb tdnet tdutils) diff --git a/td b/td index b21d667..f9a600c 160000 --- a/td +++ b/td @@ -1 +1 @@ -Subproject commit b21d667bdfb13df15f249896155f98f175a89657 +Subproject commit f9a600c401ba20af7e07ee60e12b1de28dd2e14c From d376aa22ecce961aed65d24988fef697fa226916 Mon Sep 17 00:00:00 2001 From: Andrea Cavalli Date: Sun, 8 Nov 2020 13:40:45 +0100 Subject: [PATCH 05/10] Update docker.yml, Dockerfile, and docker-entrypoint.sh --- .github/workflows/docker.yml | 50 ++++++++++++++++++++++++------------ Dockerfile | 5 ++-- docker-entrypoint.sh | 43 +++++++++++++++++++++++++++++++ 3 files changed, 80 insertions(+), 18 deletions(-) create mode 100755 docker-entrypoint.sh diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index 50b3c67..aff7d63 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -12,7 +12,8 @@ jobs: name: Build Image runs-on: ubuntu-latest env: - IMAGE_id: docker.pkg.github.com/${{ github.repository }}/${{ github.repository }} + REGISTRY: ghcr.io + IMAGE_TAG: ghcr.io/tdlight-team/tdlightbotapi steps: - name: Checkout current repo @@ -20,33 +21,50 @@ jobs: with: submodules: "recursive" - - name: Get Version + - name: Get version run: | - # get telegram bot api version - telegram_bot_api_version=$(git rev-parse --short HEAD) + # Get latest commit short hash + HASH_VERSION=$(git rev-parse --short HEAD) - # get tdlib version - tdlib_version=$(cd td && git rev-parse --short HEAD) + # Strip git ref prefix from version + VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,') + + # Strip "v" prefix from tag name + [[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION=$(echo $VERSION | sed -e 's/^v//') + + # Use Docker `latest` tag convention + [ "$VERSION" == "master" ] && VERSION=latest + + # Convert IMAGE_ID and VERSION to lowercase (repository name must be lowercase) + IMAGE_ID=$(echo "$IMAGE_ID" | awk '{print tolower($0)}') + HASH_VERSION=$(echo "$HASH_VERSION" | awk '{print tolower($0)}') + VERSION=$(echo "$VERSION" | awk '{print tolower($0)}') - # concat tdlib and telegram bot api version - version=$telegram_bot_api_version-$tdlib_version + # Store variable for future use + echo "HASH_VERSION=$HASH_VERSION" >> $GITHUB_ENV + echo "VERSION=$VERSION" >> $GITHUB_ENV - # store variable for future use - echo "version=$version" >> $GITHUB_ENV + # Print debug info + echo "hash version: $HASH_VERSION" + echo "version: $VERSION" - name: Build image run: | - IMAGE_ID=docker.pkg.github.com/${{ github.repository }}/${{ github.repository }} docker build \ - --tag tdlight-team/tdlight-telegram-bot-api:latest \ - --tag tdlight-team/tdlight-telegram-bot-api:$version \ + --cache-from $IMAGE_TAG:latest \ + --tag $IMAGE_TAG:$HASH_VERSION \ + --tag $IMAGE_TAG:$VERSION \ . - name: Login to registry run: | - echo "${{ secrets.GITHUB_ACCESS_TOKEN }}" | docker login docker.pkg.github.com -u ${{ github.actor }} --password-stdin - + echo "${{ secrets.GH_ACCESS_TOKEN }}" | docker login $REGISTRY -u ${{ github.actor }} --password-stdin - name: Push images run: | - docker push $IMAGE_ID:$version + docker push $IMAGE_TAG:$VERSION + docker push $IMAGE_TAG:$HASH_VERSION + + - name: Logout from registry + run: | + docker logout $REGISTRY diff --git a/Dockerfile b/Dockerfile index d3db905..63e1e44 100644 --- a/Dockerfile +++ b/Dockerfile @@ -17,10 +17,11 @@ RUN cmake --build . --target install -- FROM alpine:3.12.1 -RUN apk --no-cache add libstdc++ +RUN apk --no-cache add libstdc++ curl COPY --from=builder /usr/local/bin/telegram-bot-api /usr/local/bin/telegram-bot-api +COPY docker-entrypoint.sh /docker-entrypoint.sh HEALTHCHECK CMD curl -f http://localhost:8082/ || exit 1 -ENTRYPOINT ["/usr/local/bin/telegram-bot-api -s 8082"] +ENTRYPOINT ["/docker-entrypoint.sh"] diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh new file mode 100755 index 0000000..9b647d6 --- /dev/null +++ b/docker-entrypoint.sh @@ -0,0 +1,43 @@ +#!/bin/sh +set -e + +LOGS_DIR="/var/log/telegram-bot-api" +LOG_FILENAME="telegram-bot-api.log" +WORK_DIR="/etc/telegram-bot-api" +TEMP_DIR="/tmp/telegram-bot-api" + +if [ -n "${1}" ]; then + exec "${*}" +fi + +mkdir -p "${LOGS_DIR}" +mkdir -p "${WORK_DIR}" +mkdir -p "${TEMP_DIR}" + +DEFAULT_ARGS="--http-port 8081 --http-stat-port=8082 --dir=${WORK_DIR} --temp-dir=${TEMP_DIR} --log=${LOGS_DIR}/${LOG_FILENAME}" +CUSTOM_ARGS="" + +if [ -n "$TELEGRAM_FILTER" ]; then + CUSTOM_ARGS="${CUSTOM_ARGS} --filter=$TELEGRAM_FILTER" +fi +if [ -n "$TELEGRAM_MAX_WEBHOOK_CONNECTIONS" ]; then + CUSTOM_ARGS="${CUSTOM_ARGS} --max-webhook-connections=$TELEGRAM_MAX_WEBHOOK_CONNECTIONS" +fi +if [ -n "$TELEGRAM_VERBOSITY" ]; then + CUSTOM_ARGS="${CUSTOM_ARGS} --verbosity=$TELEGRAM_VERBOSITY" +fi +if [ -n "$TELEGRAM_MAX_CONNECTIONS" ]; then + CUSTOM_ARGS="${CUSTOM_ARGS} --max-connections=$TELEGRAM_MAX_CONNECTIONS" +fi +if [ -n "$TELEGRAM_PROXY" ]; then + CUSTOM_ARGS="${CUSTOM_ARGS} --proxy=$TELEGRAM_PROXY" +fi +if [ -n "$TELEGRAM_LOCAL" ]; then + CUSTOM_ARGS="${CUSTOM_ARGS} --local" +fi + +COMMAND="telegram-bot-api ${DEFAULT_ARGS}${CUSTOM_ARGS}" + +echo "$COMMAND" +# shellcheck disable=SC2086 +exec $COMMAND From 4a27b53890cd24ccda7c5bf5c88077d1ac9a0532 Mon Sep 17 00:00:00 2001 From: Andrea Cavalli Date: Sun, 8 Nov 2020 13:46:14 +0100 Subject: [PATCH 06/10] Update .gitmodules --- .gitmodules | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitmodules b/.gitmodules index 967585a..651fce0 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,3 @@ [submodule "td"] path = td - url = https://git.ignuranza.net/tdlight-team/tdlight.git + url = https://github.com/tdlight-team/tdlight.git From 5ca1c098bc79b7c2e6e16235c722949faec856b3 Mon Sep 17 00:00:00 2001 From: levlam Date: Sun, 8 Nov 2020 18:14:22 +0300 Subject: [PATCH 07/10] Remove useless check. --- telegram-bot-api/telegram-bot-api.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/telegram-bot-api/telegram-bot-api.cpp b/telegram-bot-api/telegram-bot-api.cpp index 9cd9d13..3502e21 100644 --- a/telegram-bot-api/telegram-bot-api.cpp +++ b/telegram-bot-api/telegram-bot-api.cpp @@ -192,8 +192,8 @@ int main(int argc, char *argv[]) { std::tie(rem, mod) = td::split(rem_mod, '/'); TRY_RESULT(rem_i, td::to_integer_safe(rem)); TRY_RESULT(mod_i, td::to_integer_safe(mod)); - if (rem_i < 0 || rem_i >= mod_i) { - return td::Status::Error("Wrong argument specified: ensure that 0 <= remainder < modulo"); + if (rem_i >= mod_i) { + return td::Status::Error("Wrong argument specified: ensure that remainder < modulo"); } token_range = {rem_i, mod_i}; return td::Status::OK(); From eafc9d2caa38813caccdf2d93a0fb9f026358009 Mon Sep 17 00:00:00 2001 From: levlam Date: Sun, 8 Nov 2020 18:53:28 +0300 Subject: [PATCH 08/10] Add CentOS to build instructions generator. --- build.html | 28 ++++++++++++++++++++++++---- td | 2 +- 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/build.html b/build.html index 82c4c38..5b81fe5 100644 --- a/build.html +++ b/build.html @@ -32,6 +32,8 @@ select.large { font-size: large; } g++ - +

@@ -252,7 +252,7 @@ function onOptionsChanged() { pre_text.push('Download and install gperf. Add the path to gperf.exe to the PATH environment variable.'); } if (os_linux && linux_distro === 'Other') { - var compiler = use_clang ? 'clang++ >= 3.4' : 'g++ >= 4.9.2'; + var compiler = use_clang ? 'clang >= 3.4' : 'g++ >= 4.9.2'; pre_text.push('Install Git, ' + compiler + ', make, CMake >= 3.0.2, OpenSSL-dev, zlib-dev, gperf using your package manager.'); } if (os_freebsd) { @@ -436,34 +436,6 @@ function onOptionsChanged() { commands.push('mkdir build'); commands.push('cd build'); - if (!use_msvc) { - var c_flags = []; - var cxx_flags = []; - - if (build_32bit) { - c_flags.push('-m32'); - cxx_flags.push('-m32'); - } else if (build_64bit) { - c_flags.push('-m64'); - cxx_flags.push('-m64'); - } - - if (os_linux) { - if (use_clang) { - cxx_flags.push('-stdlib=libc++'); - } else { - cxx_flags.push(''); - } - } - - if (c_flags.length) { - commands.push('export CFLAGS="' + c_flags.join(' ') + '"'); - } - if (cxx_flags.length) { - commands.push('export CXXFLAGS="' + cxx_flags.join(' ') + '"'); - } - } - cmake_init_options = getBacicCmakeInitOptions(); if (os_mac) { cmake_init_options.push('-DOPENSSL_ROOT_DIR=/usr/local/opt/openssl/'); @@ -478,7 +450,7 @@ function onOptionsChanged() { if (os_linux) { if (use_clang) { var clang_version_suffix = getClangVersionSuffix(); - prefix = 'CC=/usr/bin/clang' + clang_version_suffix + ' CXX=/usr/bin/clang++' + clang_version_suffix + ' '; + prefix = 'CXXFLAGS="-stdlib=libc++" CC=/usr/bin/clang' + clang_version_suffix + ' CXX=/usr/bin/clang++' + clang_version_suffix + ' '; } else if (linux_distro === 'Ubuntu 14') { prefix = 'CC=/usr/bin/gcc-4.9 CXX=/usr/bin/g++-4.9 '; } else if (linux_distro === 'CentOS 7') { diff --git a/td b/td index 7a0b884..1d75237 160000 --- a/td +++ b/td @@ -1 +1 @@ -Subproject commit 7a0b88441a980171624f4727fd5f52d9db078730 +Subproject commit 1d75237893c8a08d73ba95a7e76b8da517b8c1dc