From 70cb8c5092a9dea20c27efad78d29493bb90aba9 Mon Sep 17 00:00:00 2001 From: initialencounter <2911583893@qq.com> Date: Sat, 13 Apr 2024 02:38:14 +0800 Subject: [PATCH] initial commit --- .github/workflows/base-docker-publish.yml | 109 +++++++++++++++++++++ .github/workflows/docker-publish.yml | 112 ++++++++++++++++++++++ Dockerfile | 46 ++++----- README.md | 35 +++++++ base/Dockerfile | 30 ++++++ base/base | 0 config.txt | 17 ++++ entrypoint.sh | 97 +++++++++++++++++++ get_artifacts.sh | 18 ++++ 9 files changed, 441 insertions(+), 23 deletions(-) create mode 100644 .github/workflows/base-docker-publish.yml create mode 100644 .github/workflows/docker-publish.yml create mode 100644 base/Dockerfile create mode 100644 base/base create mode 100644 config.txt create mode 100644 entrypoint.sh create mode 100644 get_artifacts.sh diff --git a/.github/workflows/base-docker-publish.yml b/.github/workflows/base-docker-publish.yml new file mode 100644 index 0000000..5789f5f --- /dev/null +++ b/.github/workflows/base-docker-publish.yml @@ -0,0 +1,109 @@ +name: base + +on: + workflow_dispatch: + +env: + REGISTRY_IMAGE: mlikiowa/napcat-docker + +jobs: + build: + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + platform: + - linux/amd64 + - linux/arm64 + steps: + - + name: Prepare + run: | + platform=${{ matrix.platform }} + echo "PLATFORM_PAIR=${platform//\//-}" >> $GITHUB_ENV + - + name: Checkout + uses: actions/checkout@v4 + - + name: Docker meta + id: meta + uses: docker/metadata-action@v5 + with: + images: ${{ env.REGISTRY_IMAGE }} + tags: | + type=raw,value=base,enable=${{ github.ref == format('refs/heads/{0}', 'main') }} + - + name: Set up QEMU + uses: docker/setup-qemu-action@v3 + - + name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + - + name: Login to Docker Hub + uses: docker/login-action@v3 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + - + name: Build and push by digest + id: build + uses: docker/build-push-action@v5 + with: + context: ./base/. + platforms: ${{ matrix.platform }} + labels: ${{ steps.meta.outputs.labels }} + outputs: type=image,name=${{ env.REGISTRY_IMAGE }},push-by-digest=true,name-canonical=true,push=true + - + name: Export digest + run: | + mkdir -p /tmp/digests + digest="${{ steps.build.outputs.digest }}" + touch "/tmp/digests/${digest#sha256:}" + - + name: Upload digest + uses: actions/upload-artifact@v4 + with: + name: digests-${{ env.PLATFORM_PAIR }} + path: /tmp/digests/* + if-no-files-found: error + retention-days: 1 + + merge: + runs-on: ubuntu-latest + needs: + - build + steps: + - + name: Download digests + uses: actions/download-artifact@v4 + with: + path: /tmp/digests + pattern: digests-* + merge-multiple: true + - + name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + - + name: Docker meta + id: meta + uses: docker/metadata-action@v5 + with: + images: ${{ env.REGISTRY_IMAGE }} + tags: | + type=raw,value=base,enable=${{ github.ref == format('refs/heads/{0}', 'main') }} + - + name: Login to Docker Hub + uses: docker/login-action@v3 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + - + name: Create manifest list and push + working-directory: /tmp/digests + run: | + docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \ + $(printf '${{ env.REGISTRY_IMAGE }}@sha256:%s ' *) + - + name: Inspect image + run: | + docker buildx imagetools inspect ${{ env.REGISTRY_IMAGE }}:${{ steps.meta.outputs.version }} \ No newline at end of file diff --git a/.github/workflows/docker-publish.yml b/.github/workflows/docker-publish.yml new file mode 100644 index 0000000..8eaf326 --- /dev/null +++ b/.github/workflows/docker-publish.yml @@ -0,0 +1,112 @@ +name: ci + +on: + workflow_dispatch: + # push: + # branches: + # - "main" + +env: + REGISTRY_IMAGE: mlikiowa/napcat-docker + +jobs: + build: + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + platform: + - linux/amd64 + - linux/arm64 + steps: + - + name: Prepare + run: | + platform=${{ matrix.platform }} + echo "PLATFORM_PAIR=${platform//\//-}" >> $GITHUB_ENV + - + name: Checkout + uses: actions/checkout@v4 + - + name: Docker meta + id: meta + uses: docker/metadata-action@v5 + with: + images: ${{ env.REGISTRY_IMAGE }} + tags: | + type=raw,value=latest,enable=${{ github.ref == format('refs/heads/{0}', 'main') }} + - + name: Set up QEMU + uses: docker/setup-qemu-action@v3 + - + name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + - + name: Login to Docker Hub + uses: docker/login-action@v3 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + - + name: Build and push by digest + id: build + uses: docker/build-push-action@v5 + with: + context: . + platforms: ${{ matrix.platform }} + labels: ${{ steps.meta.outputs.labels }} + outputs: type=image,name=${{ env.REGISTRY_IMAGE }},push-by-digest=true,name-canonical=true,push=true + - + name: Export digest + run: | + mkdir -p /tmp/digests + digest="${{ steps.build.outputs.digest }}" + touch "/tmp/digests/${digest#sha256:}" + - + name: Upload digest + uses: actions/upload-artifact@v4 + with: + name: digests-${{ env.PLATFORM_PAIR }} + path: /tmp/digests/* + if-no-files-found: error + retention-days: 1 + + merge: + runs-on: ubuntu-latest + needs: + - build + steps: + - + name: Download digests + uses: actions/download-artifact@v4 + with: + path: /tmp/digests + pattern: digests-* + merge-multiple: true + - + name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + - + name: Docker meta + id: meta + uses: docker/metadata-action@v5 + with: + images: ${{ env.REGISTRY_IMAGE }} + tags: | + type=raw,value=latest,enable=${{ github.ref == format('refs/heads/{0}', 'main') }} + - + name: Login to Docker Hub + uses: docker/login-action@v3 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + - + name: Create manifest list and push + working-directory: /tmp/digests + run: | + docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \ + $(printf '${{ env.REGISTRY_IMAGE }}@sha256:%s ' *) + - + name: Inspect image + run: | + docker buildx imagetools inspect ${{ env.REGISTRY_IMAGE }}:${{ steps.meta.outputs.version }} \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 416289f..bb6e9e6 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,25 +1,25 @@ -FROM ubuntu:22.04 +FROM initialencounter/napcat:base -ENV DEBIAN_FRONTEND=noninteractive -ENV VNC_PASSWD=vncpasswd +COPY NapCat.linux.x64.zip /tmp/NapCat.linux.x64.zip +COPY config.txt entrypoint.sh /root/ + +# 安装Linux QQ +RUN curl -o /root/linuxqq.deb https://dldir1.qq.com/qqfile/qq/QQNT/Linux/QQ_3.2.7_240410_amd64_01.deb && \ + dpkg -i --force-depends /root/linuxqq.deb && rm /root/linuxqq.deb && \ + + # 安装 napcat + unzip /tmp/NapCat.linux.x64.zip -d /root/ && \ + rm /tmp/NapCat.linux.x64.zip && \ + + chmod +x /root/napcat.sh && \ + chmod +x /root/entrypoint.sh && \ + + echo "[supervisord]" > /etc/supervisord.conf && \ + echo "nodaemon=true" >> /etc/supervisord.conf && \ + echo "[program:napcat]" >> /etc/supervisord.conf && \ + echo "command=COMMAND" >> /etc/supervisord.conf + +WORKDIR "/root" + +ENTRYPOINT ["/root/entrypoint.sh"] -RUN apt-get update && apt-get install -y \ - openbox \ - xorg \ - dbus-user-session \ - curl \ - unzip \ - xvfb \ - supervisor \ - libnotify4 \ - libnss3 \ - xdg-utils \ - libsecret-1-0 \ - ffmpeg \ - libgbm1 \ - libasound2 \ - fonts-wqy-zenhei \ - git \ - gnutls-bin && \ - apt-get clean --no-install-recommends && \ - rm -rf /var/lib/apt/lists/* && \ diff --git a/README.md b/README.md index 1133683..0f1630e 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,37 @@ # NapCat-Docker NapCat-Docker + + +## 正向 WS + +```shell +docker run \ +-e ACCOUNT=<机器人qq> \ +-d -p 3001:3001 \ +-e WS_ENABLE=true \ +--name napcat \ +mlikiowa/napcat-docker:latest +``` + + +## 反向 WS + +```shell +docker run -d \ +-e ACCOUNT=<机器人qq> \ +-e WSR_ENABLE=true \ +-e WS_URLS="http://localhost:5140/onebot" +--name napcat \ +mlikiowa/napcat-docker:latest +``` + + +## HTTP +```shell +docker run \ +-e ACCOUNT=<机器人qq> \ +-d -p 3000:3000 \ +-e HTTP_ENABLE=true \ +--name napcat \ +mlikiowa/napcat-docker:latest +``` \ No newline at end of file diff --git a/base/Dockerfile b/base/Dockerfile new file mode 100644 index 0000000..e9cb720 --- /dev/null +++ b/base/Dockerfile @@ -0,0 +1,30 @@ +FROM ubuntu:22.04 + +# 设置环境变量 +ENV DEBIAN_FRONTEND=noninteractive + +# 安装必要的软件包 +RUN apt-get update && apt-get install -y \ + libnss3 \ + libnotify4 \ + libsecret-1-0 \ + libgbm1 \ + libasound2 \ + fonts-wqy-zenhei \ + gnutls-bin \ + libglib2.0-dev \ + libdbus-1-3 \ + libgtk-3-0 \ + libxss1 \ + libxtst6 \ + libatspi2.0-0 \ + libx11-xcb1 \ + unzip \ + curl \ + supervisor && \ + apt autoremove -y && \ + apt clean && \ + rm -rf \ + /var/lib/apt/lists/* \ + /tmp/* \ + /var/tmp/* diff --git a/base/base b/base/base new file mode 100644 index 0000000..e69de29 diff --git a/config.txt b/config.txt new file mode 100644 index 0000000..7612e0c --- /dev/null +++ b/config.txt @@ -0,0 +1,17 @@ +{ + "httpPort": HTTP_PORT, + "httpPostUrls": ["HTTP_URLS"], + "httpSecret": "", + "wsPort": WS_PORT, + "wsReverseUrls": ["WS_URLS"], + "enableHttp": HTTP_ENABLE, + "enableHttpPost": HTTP_POST_ENABLE, + "enableWs": WS_ENABLE, + "enableWsReverse": WSR_ENABLE, + "messagePostFormat": "array", + "reportSelfMessage": RSM_ENABLE, + "debug": DEBUG_ENABLE, + "enableLocalFile2Url": F2U_ENABLE, + "heartInterval": HEART, + "token": "TOKEN" +} \ No newline at end of file diff --git a/entrypoint.sh b/entrypoint.sh new file mode 100644 index 0000000..5dd8330 --- /dev/null +++ b/entrypoint.sh @@ -0,0 +1,97 @@ +#!/bin/bash + +sed -i "s|COMMAND|bash /root/napcat.sh -q $ACCOUNT|" /etc/supervisord.conf + +CONFIG_PATH=/root/config/onebot11_$ACCOUNT.json +# 容器首次启动时执行 +if [ ! -f "$CONFIG_PATH" ]; then + cp -f /root/config.txt $CONFIG_PATH + + + if [ "$HTTP_PORT" ]; then + sed -i "s/HTTP_PORT/$HTTP_PORT/" $CONFIG_PATH + else + sed -i "s/HTTP_PORT/3000/" $CONFIG_PATH + fi + + if [ "$HTTP_URLS" ]; then + sed -i "s|HTTP_URLS|$HTTP_URLS|" $CONFIG_PATH + else + sed -i "s/\"HTTP_URLS\"/\"\"/" $CONFIG_PATH + fi + + if [ "$WS_PORT" ]; then + sed -i "s/WS_PORT/$WS_PORT/" $CONFIG_PATH + else + sed -i "s/WS_PORT/3001/" $CONFIG_PATH + fi + + if [ "$HTTP_ENABLE" ]; then + sed -i "s/HTTP_ENABLE/$HTTP_ENABLE/" $CONFIG_PATH + else + sed -i "s/HTTP_ENABLE/false/" $CONFIG_PATH + fi + + if [ "$HTTP_POST_ENABLE" ]; then + sed -i "s/HTTP_POST_ENABLE/$HTTP_POST_ENABLE/" $CONFIG_PATH + else + sed -i "s/HTTP_POST_ENABLE/false/" $CONFIG_PATH + fi + + if [ "$WS_ENABLE" ]; then + sed -i "s/WS_ENABLE/$WS_ENABLE/" $CONFIG_PATH + else + sed -i "s/WS_ENABLE/false/" $CONFIG_PATH + fi + + if [ "$WSR_ENABLE" ]; then + sed -i "s/WSR_ENABLE/$WSR_ENABLE/" $CONFIG_PATH + else + sed -i "s/WSR_ENABLE/false/" $CONFIG_PATH + fi + + if [ "WS_URLS" ]; then + sed -i "s/WS_URLS/$WS_URLS/" $CONFIG_PATH + else + sed -i "s/\"WS_URLS\"/\"\"/" $CONFIG_PATH + fi + + if [ "$HEART" ]; then + sed -i "s/HEART/$HEART/" $CONFIG_PATH + else + sed -i "s/HEART/60000/" $CONFIG_PATH + fi + + if [ "$TOKEN" ]; then + sed -i "s|TOKEN|$TOKEN|" $CONFIG_PATH + else + sed -i "s/\"TOKEN\"/\"\"/" $CONFIG_PATH + fi + + if [ "$F2U_ENABLE" ]; then + sed -i "s/F2U_ENABLE/$F2U_ENABLE/" $CONFIG_PATH + else + sed -i "s/F2U_ENABLE/false/" $CONFIG_PATH + fi + + if [ "$DEBUG_ENABLE" ]; then + sed -i "s/DEBUG_ENABLE/$DEBUG_ENABLE/" $CONFIG_PATH + else + sed -i "s/DEBUG_ENABLE/false/" $CONFIG_PATH + fi + + if [ "$LOG_ENABLE" ]; then + sed -i "s/LOG_ENABLE/$LOG_ENABLE/" $CONFIG_PATH + else + sed -i "s/LOG_ENABLE/false/" $CONFIG_PATH + fi + + if [ "$RSM_ENABLE" ]; then + sed -i "s/RSM_ENABLE/$RSM_ENABLE/" $CONFIG_PATH + else + sed -i "s/RSM_ENABLE/false/" $CONFIG_PATH + fi +fi + +bash /root/napcat.sh -q $ACCOUNT & +exec supervisord \ No newline at end of file diff --git a/get_artifacts.sh b/get_artifacts.sh new file mode 100644 index 0000000..341ee0a --- /dev/null +++ b/get_artifacts.sh @@ -0,0 +1,18 @@ +#!/bin/bash + +# 设置仓库信息 +repository="NapNeko/NapCat.Build" +run_id="8662095740" +artifact_name="NapCat.linux.x64" +token="" + +# 设置输出目录 +output_dir="." + +# 获取artifact ID +artifact_id=$(curl -s -X GET -H "Authorization: token $token" "https://api.github.com/repos/$repository/actions/runs/$run_id/artifacts" | jq -r ".artifacts[] | select(.name == \"$artifact_name\") | .id") + +# 下载artifact +curl -s -X GET -H "Authorization: token $token" -L "https://api.github.com/repos/$repository/actions/artifacts/$artifact_id/zip" -o "$output_dir/$artifact_name.zip" + +echo "编译产物已保存到$output_dir/$artifact_name.zip"