Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CMakeLists error on building in docker #625

Open
b166er opened this issue Aug 11, 2024 · 3 comments
Open

CMakeLists error on building in docker #625

b166er opened this issue Aug 11, 2024 · 3 comments

Comments

@b166er
Copy link

b166er commented Aug 11, 2024

Steps to reproduce:

mkdir /tmp/test
git clone https://github.com/tdlib/telegram-bot-api.git /tmp/test/
cd /tmp/test/telegram-bot-api
docker run --rm -it -w /app -v $PWD:/app ubuntu:latest bash
apt update
apt install make git zlib1g-dev libssl-dev gperf cmake g++
mkdir build
cd build
cmake -DCMAKE_BUILD_TYPE=Release ..

Output:

CMake Deprecation Warning at CMakeLists.txt:1 (cmake_minimum_required):
  Compatibility with CMake < 3.5 will be removed from a future version of
  CMake.

  Update the VERSION argument <min> value or use a ...<max> suffix to tell
  CMake that the project does not need compatibility with older versions.


CMake Error at CMakeLists.txt:16 (add_subdirectory):
  The source directory

    /usr/src/app/td

  does not contain a CMakeLists.txt file.


CMake Error at CMakeLists.txt:40 (include):
  include could not find requested file:

    PreventInSourceBuild


CMake Error at CMakeLists.txt:41 (prevent_in_source_build):
  Unknown CMake command "prevent_in_source_build".


-- Configuring incomplete, errors occurred!
@levlam
Copy link
Contributor

levlam commented Aug 11, 2024

You are running cmake from /usr/src/app/td as specified by thr error.

@levlam
Copy link
Contributor

levlam commented Aug 11, 2024

You should use https://tdlib.github.io/telegram-bot-api/build.html to build the Bot API server.

@b166er
Copy link
Author

b166er commented Aug 11, 2024

Thanks for the hint! I followed the instructions and tried it without root permissions as recommended, and that was the solution. without root, I found a missing write permission on the root directory. after adding chmod 777 to the /app directory (in the docker container), the build process completed successfully.

update: I found the main reason! in the first attempt I did manually "git clone" (without copy from instruction-site) on the host system (outside of docker container) to then build in the docker container, and in the git-clone I forgot the recursive parameter (like on instruction-site), so the submodule in the td folder was not pulled!

For those who want to run in Docker, here is my Dockerfile example

./my-Dockerfile

# Base layer with dependencies and building
FROM ubuntu AS base

COPY ./telegram-source /app
WORKDIR /app
RUN DEBIAN_FRONTEND=noninteractive && ln -fs /usr/share/zoneinfo/Europe/Berlin /etc/localtime \
    && apt update && apt -y upgrade \
    && apt -y install make zlib1g-dev libssl-dev gperf cmake g++ \
    && rm -rf build && mkdir build data && cd build \
    && cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX:PATH=.. .. \
    && cmake --build . --target install


# top layer with custom entrypoint (env-catcher)
FROM base AS telegram

COPY ./my-entrypoint.sh /app/bin/entrypoint.sh
RUN chmod 755 /app/bin/entrypoint.sh

ENTRYPOINT [ "/app/bin/entrypoint.sh" ]

./my-entrypoint.sh

#!/bin/bash

PREFIX_LOCAL=${LOCAL:+"--local"}
PREFIX_API_ID=${API_ID:+"--api-id="}
PREFIX_API_HASH=${API_HASH:+"--api-hash="}
PREFIX_PORT=${PORT:+"--http-port="}
PREFIX_STAT_PORT=${STAT_PORT:+"--http-stat-port="}
PREFIX_DIR=${DIR:+"--dir="}
PREFIX_TEMP_DIR=${TEMP_DIR:+"--temp-dir="}
PREFIX_FILTER=${FILTER:+"--filter="}
PREFIX_MAX_WEBHOOK_CONNECTIONS=${MAX_WEBHOOK_CONNECTIONS:+"--max-webhook-connections="}
PREFIX_IP_ADDRESS=${IP_ADDRESS:+"--http-ip-address="}
PREFIX_STAT_IP_ADDRESS=${STAT_IP_ADDRESS:+"--http-stat-ip-address="}
PREFIX_LOG=${LOG:+"--log="}
PREFIX_VERBOSITY=${VERBOSITY:+"--verbosity="}
PREFIX_MEMORY_VERBOSITY=${MEMORY_VERBOSITY:+"--memory-verbosity="}
PREFIX_LOG_MAX_FILE_SIZE=${LOG_MAX_FILE_SIZE:+"--log-max-file-size="}
PREFIX_USERNAME=${USERNAME:+"--username="}
PREFIX_GROUPNAME=${GROUPNAME:+"--groupname="}
PREFIX_MAX_CONNECTIONS=${MAX_CONNECTIONS:+"--max-connections="}
PREFIX_CPU_AFFINTY=${CPU_AFFINTY:+"--cpu-affinity="}
PREFIX_MAIN_THREAD_AFFINTY=${MAIN_THREAD_AFFINTY:+"--main-thread-affinity="}
PREFIX_PROXY=${PROXY:+"--proxy="}

PARAM_LOCAL="${PREFIX_LOCAL}"
PARAM_API_ID="${PREFIX_API_ID}${API_ID}"
PARAM_API_HASH="${PREFIX_API_HASH}${API_HASH}"
PARAM_PORT="${PREFIX_PORT}${PORT}"
PARAM_STAT_PORT="${PREFIX_STAT_PORT}${STAT_PORT}"
PARAM_DIR="${PREFIX_DIR}${DIR}"
PARAM_TEMP_DIR="${PREFIX_TEMP_DIR}${TEMP_DIR}"
PARAM_FILTER="${PREFIX_FILTER}${FILTER}"
PARAM_MAX_WEBHOOK_CONNECTIONS="${PREFIX_MAX_WEBHOOK_CONNECTIONS}${MAX_WEBHOOK_CONNECTIONS}"
PARAM_IP_ADDRESS="${PREFIX_IP_ADDRESS}${IP_ADDRESS}"
PARAM_STAT_IP_ADDRESS="${PREFIX_STAT_IP_ADDRESS}${STAT_IP_ADDRESS}"
PARAM_LOG="${PREFIX_LOG}${LOG}"
PARAM_VERBOSITY="${PREFIX_VERBOSITY}${VERBOSITY}"
PARAM_MEMORY_VERBOSITY="${PREFIX_MEMORY_VERBOSITY}${MEMORY_VERBOSITY}"
PARAM_LOG_MAX_FILE_SIZE="${PREFIX_LOG_MAX_FILE_SIZE}${LOG_MAX_FILE_SIZE}"
PARAM_USERNAME="${PREFIX_USERNAME}${USERNAME}"
PARAM_GROUPNAME="${PREFIX_GROUPNAME}${GROUPNAME}"
PARAM_MAX_CONNECTIONS="${PREFIX_MAX_CONNECTIONS}${MAX_CONNECTIONS}"
PARAM_CPU_AFFINTY="${PREFIX_CPU_AFFINTY}${CPU_AFFINTY}"
PARAM_MAIN_THREAD_AFFINTY="${PREFIX_MAIN_THREAD_AFFINTY}${MAIN_THREAD_AFFINTY}"
PARAM_PROXY="${PREFIX_PROXY}${PROXY}"


/app/bin/telegram-bot-api ${PARAM_API_ID} ${PARAM_API_HASH} ${PARAM_LOCAL} ${PARAM_PORT} ${PARAM_STAT_PORT} ${PARAM_DIR} ${PARAM_TEMP_DIR} ${PARAM_FILTER} ${PARAM_MAX_WEBHOOK_CONNECTIONS} ${PARAM_IP_ADDRESS} ${PARAM_STAT_IP_ADDRESS} ${PARAM_LOG} ${PARAM_VERBOSITY} ${PARAM_MEMORY_VERBOSITY} ${PARAM_LOG_MAX_FILE_SIZE} ${PARAM_USERNAME} ${PARAM_GROUPNAME} ${PARAM_MAX_CONNECTIONS} ${PARAM_CPU_AFFINTY} ${PARAM_MAIN_THREAD_AFFINTY} ${PARAM_PROXY}

./docker-compose.yml

services:
  telegram:
    container_name: telegram
    hostname: telegram
    build:
      context: .
      dockerfile: my-Dockerfile
    restart: unless-stopped
    volumes:
      - /srv/services/telegram-data:/app/data
    environment:
      LOCAL: 1
      API_ID: 123456
      API_HASH: 'xxxxxxxxxxxxxxxxxxxxxxxxx'
      PORT: 18081
      STAT_PORT: 18082
      DIR: '/app/data'
      TEMP_DIR: /app/data/tmp
      LOG: /app/data/telegram.log
      VERBOSITY: 1
    ports:
      - "18081:18081/tcp"
      - "18082:18082/tcp"

docker compose up -d and you will get a ready-builded and already running telegram-bot-api process.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants