From 4eeb6924d2d6fca4f89c78fea460c820024e150e Mon Sep 17 00:00:00 2001 From: Dmitry Date: Mon, 13 Apr 2026 15:00:39 +0300 Subject: [PATCH] initial commit --- .gitea/workflows/docker.yml | 79 +++++++++++++++++++++++++++++++++++++ .gitignore | 1 + build/Dockerfile | 70 ++++++++++++++++++++++++++++++++ docker-compose.yml | 10 +++++ 4 files changed, 160 insertions(+) create mode 100644 .gitea/workflows/docker.yml create mode 100644 .gitignore create mode 100644 build/Dockerfile create mode 100644 docker-compose.yml diff --git a/.gitea/workflows/docker.yml b/.gitea/workflows/docker.yml new file mode 100644 index 0000000..0e95b8a --- /dev/null +++ b/.gitea/workflows/docker.yml @@ -0,0 +1,79 @@ +name: Docker Image CI + +on: + push: + branches: + - master + tags: + - v* + pull_request: + branches: + - master + workflow_dispatch: + +permissions: + packages: write + contents: read + +jobs: + test: + runs-on: cth-ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Build image + uses: docker/build-push-action@v4 + with: + context: . + push: false + tags: gitea.b4tman.ru/${{ gitea.repository }}:test + push: + needs: test + runs-on: cth-ubuntu-latest + if: github.event_name != 'pull_request' + steps: + - uses: actions/checkout@v4 + + - name: Docker meta + id: meta + uses: docker/metadata-action@v5 + with: + images: | + gitea.b4tman.ru/${{ gitea.repository }} + flavor: | + latest=${{ github.ref == 'refs/heads/master' }} + tags: | + type=ref,event=branch + type=ref,event=pr + type=semver,pattern={{version}} + type=semver,pattern={{major}}.{{minor}} + + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Login to gitea + uses: docker/login-action@v3 + with: + registry: gitea.b4tman.ru + username: ${{ gitea.repository_owner }} + password: ${{ secrets.PKGS_TOKEN }} + + - name: Build and push image + uses: docker/build-push-action@v4 + with: + context: . + push: true + #platforms: linux/amd64,linux/arm64 + platforms: linux/amd64 + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..03bd412 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +*.env diff --git a/build/Dockerfile b/build/Dockerfile new file mode 100644 index 0000000..b72b2f1 --- /dev/null +++ b/build/Dockerfile @@ -0,0 +1,70 @@ +FROM alpine:3.23.3 AS builder + +# based on https://bigmike.help/ru/devops/034/ +# https://tdlib.github.io/telegram-bot-api/build.html?os=Linux + +ARG TELEGRAM_BOT_API_REF=master + +RUN apk add --no-cache \ + alpine-sdk \ + linux-headers \ + git \ + zlib-dev \ + openssl-dev \ + gperf \ + cmake \ + curl \ + ca-certificates \ + musl-dev \ + make \ + pkgconfig \ + autoconf \ + automake \ + libtool + +RUN git clone --recursive https://github.com/tdlib/telegram-bot-api.git /src --depth 1 --branch ${TELEGRAM_BOT_API_REF} + +WORKDIR /src + +RUN set -x && \ + rm -rf build && \ + mkdir /src/build && \ + cd /src/build && \ + nproc=$(n=$(nproc) ; max_n=6 ; echo $(( n <= max_n ? n : max_n )) ) && \ + cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/usr/local .. && \ + cmake --build . --target telegram-bot-api -j"$nproc" && \ + strip /src/build/telegram-bot-api + + +FROM alpine:3.23.3 + +RUN apk add --no-cache \ + libstdc++ \ + curl \ + ca-certificates \ + tzdata \ + libssl3 \ + zlib + +RUN set -x && \ + mkdir -p /var/lib/telegram-bot-api && \ + deluser telegram-bot-api 2>/dev/null; delgroup telegram-bot-api 2>/dev/null; \ + addgroup -S telegram-bot-api -g 5555 && adduser -S -u 5555 -G telegram-bot-api -g telegram-bot-api -H -D -s /bin/false -h /var/lib/telegram-bot-api telegram-bot-api + +COPY --from=builder /src/build/telegram-bot-api /usr/local/bin/telegram-bot-api + +EXPOSE 8081 + +ENV HEALTH_PORT=8081 +HEALTHCHECK --interval=30s --timeout=3s --start-period=10s --retries=3 \ + CMD curl -fsS "http://127.0.0.1:${HEALTH_PORT}/" >/dev/null || exit 1 + +USER telegram-bot-api +WORKDIR /var/lib/telegram-bot-api + +VOLUME /var/lib/telegram-bot-api + +# Параметры (api-id, api-hash, порты, директории) передаются через docker-compose: +# command: ["--api-id=...", "--api-hash=...", "--http-port=8081", "--dir=/var/lib/telegram-bot-api"] +ENTRYPOINT ["/usr/local/bin/telegram-bot-api"] + diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..f42b757 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,10 @@ +--- +services: + tg-bot-api: + build: build + restart: no + logging: + driver: json-file + options: + max-file: '5' + max-size: 10m