From f5952ff63ced5593a02c8de4ee1ffa82ecdd4659 Mon Sep 17 00:00:00 2001 From: IITII Date: Mon, 4 Dec 2023 16:37:38 +0800 Subject: [PATCH] feat: docker action support --- .github/workflows/docker.yml | 59 ++++++++++++++++++++++++++++++++ Dockerfile | 12 +++++++ docker-compose.yml | 65 ++++++++++++++++++++++++++++++++++++ 3 files changed, 136 insertions(+) create mode 100644 .github/workflows/docker.yml create mode 100644 Dockerfile create mode 100644 docker-compose.yml diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml new file mode 100644 index 0000000..04b6595 --- /dev/null +++ b/.github/workflows/docker.yml @@ -0,0 +1,59 @@ +name: dockerbuild +# https://github.com/marketplace/actions/build-and-push-docker-images#path-context +# https://docs.docker.com/build/ci/github-actions/ +# https://blog.isayme.org/posts/issues-55/ + + +on: + push: + branches: + - 'main' + workflow_dispatch: + repository_dispatch: + types: [webhook] + +env: + APP_NAME: tg_setu_bot + DOCKERHUB_REPO: sikii/tg_setu_bot + +jobs: + docker: + runs-on: ubuntu-latest + steps: + - + name: Checkout + uses: actions/checkout@v3 + - + name: Set up QEMU + uses: docker/setup-qemu-action@v2 + - + name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + - + name: Login to Docker Hub + uses: docker/login-action@v2 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + # 构建 Docker 并推送到 Docker hub + - name: Build and push + id: docker_build + uses: docker/build-push-action@v2 + with: + # 是否 docker push + push: true + # 生成多平台镜像, see https://github.com/docker-library/bashbrew/blob/v0.1.1/architecture/oci-platform.go + # platforms: | + # linux/amd64 + platforms: | + linux/amd64 + linux/arm/v6 + linux/arm/v7 + linux/arm64/v8 + # docker build arg, 注入 APP_NAME/APP_VERSION + build-args: | + APP_NAME=${{ env.APP_NAME }} + APP_VERSION=${{ env.APP_VERSION }} + # 生成两个 docker tag: ${APP_VERSION} 和 latest + tags: | + ${{ env.DOCKERHUB_REPO }}:latest diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..3354cde --- /dev/null +++ b/Dockerfile @@ -0,0 +1,12 @@ +FROM node:18-alpine + +LABEL maintainer="IITII " + +ADD . /app +#RUN mkdir +WORKDIR /app +VOLUME ["/app/db", "/app/tmp", "/app/logs"] + +RUN npm i + +CMD ["npm", "start"] diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..c84b1aa --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,65 @@ +version: "3" +services: + web: + image: sikii/tg_setu_bot:latest + restart: unless-stopped + network_mode: bridge + hostname: tg_setu_bot + container_name: tg_setu_bot + logging: + driver: json-file + options: + max-size: 1m + depends_on: + - redis + environment: + - TG_DEBUG=false + - TZ=Asia/Shanghai + # tg 机器人 token + - BOT_TOKEN=xxxxxxxx + # 订阅专用 token, 必填, 且加入到 forward channel 中 + - SUBSCRIBE_TOKEN= + # 图片专用 token, 支持多个token, 用逗号分隔 + - WORKERS_TOKEN= + # 管理员 ID + - ADMIN_ID= + # 配置后下载时自动转发消息到指定channel + - FORWARD_ID= + # 是否将搜索结果发送到订阅频道, 默认 false + - SEND_TO_SUB=false + # REDIS_URL + - REDIS_URL=redis://:review_pic@redis:6379 + # 同订阅检查间隔 hour, 默认 6h + # - CHECK_ALL=6 + # 检查间隔的随机范围, 默认 0.2 即 0.8 ~ 1.2 倍 + # - CHECK_RANDOM_RATE=0.2 + # redis 扫描周期 min, 默认 5min + # - CHECK_PERIOD=5 + # tg 机器人代理 + # - PROXY= + # 用户状态缓存文件 + # - DB_FILE= + # acgBox cookie + # - ACG_BOX_COOKIE= + # acgBox password + # - ACG_BOX_PASSWORD= + volumes: + - ./runs/db:/app/db + - ./runs/tmp:/app/tmp + - ./runs/logs:/app/logs + redis: + image: redis:alpine + restart: unless-stopped + network_mode: bridge + hostname: redis + container_name: redis + logging: + driver: json-file + options: + max-size: 1m + command: ["redis-server", "--requirepass review_pic"] + # 映射Redis默认端口 + # ports: + # - "6379:6379" + volumes: + - ./runs/redis_data:/data