From 07ea7baf9e50849521641cd2d608b31d7e59b4d9 Mon Sep 17 00:00:00 2001 From: whyour Date: Fri, 12 May 2023 14:18:22 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=20debian-slim=20=E5=9F=BA?= =?UTF-8?q?=E7=A1=80=E9=95=9C=E5=83=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/build_docker_image.yml | 7 +- back/data/dependence.ts | 4 +- back/services/cron.ts | 46 +++++------- docker/Dockerfile | 91 ++++++++++++------------ docker/docker-entrypoint.sh | 2 +- shell/bot.sh | 2 +- shell/otask.sh | 16 ----- shell/share.sh | 2 - 8 files changed, 73 insertions(+), 97 deletions(-) diff --git a/.github/workflows/build_docker_image.yml b/.github/workflows/build_docker_image.yml index b6cf08cf..fa84f369 100644 --- a/.github/workflows/build_docker_image.yml +++ b/.github/workflows/build_docker_image.yml @@ -5,6 +5,7 @@ on: branches: - 'master' - 'develop' + - 'debian' tags: - 'v*' # Push events to matching v*, i.e. v1.0, v20.15.10 schedule: @@ -157,14 +158,14 @@ jobs: QL_BRANCH=${{ github.ref_name }} SOURCE_COMMIT=${{ github.sha }} network: host - platforms: linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm64,linux/ppc64le,linux/s390x,linux/386 + platforms: linux/amd64,linux/arm/v7,linux/arm64,linux/ppc64le,linux/s390x context: . file: ./docker/Dockerfile push: true tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} - cache-from: type=registry,ref=whyour/qinglong:cache - cache-to: type=registry,ref=whyour/qinglong:cache,mode=max + cache-from: type=registry,ref=whyour/qinglong:cache-debian + cache-to: type=registry,ref=whyour/qinglong:cache-debian,mode=max - name: Image digest run: echo ${{ steps.docker_build.outputs.digest }} diff --git a/back/data/dependence.ts b/back/data/dependence.ts index 05526b78..5fc838a2 100644 --- a/back/data/dependence.ts +++ b/back/data/dependence.ts @@ -43,7 +43,7 @@ export enum DependenceTypes { export enum InstallDependenceCommandTypes { 'pnpm add -g', 'pip3 install --disable-pip-version-check --root-user-action=ignore', - 'apk add --no-check-certificate', + 'apt install -y', } export enum GetDependenceCommandTypes { @@ -61,7 +61,7 @@ export enum versionDependenceCommandTypes { export enum unInstallDependenceCommandTypes { 'pnpm remove -g', 'pip3 uninstall --disable-pip-version-check --root-user-action=ignore -y', - 'apk del', + 'apt remove', } export interface DependenceInstance diff --git a/back/services/cron.ts b/back/services/cron.ts index ef1eb025..a2d57682 100644 --- a/back/services/cron.ts +++ b/back/services/cron.ts @@ -30,11 +30,9 @@ export default class CronService { const tab = new Crontab(payload); tab.saved = false; const doc = await this.insert(tab); - if (this.isSixCron(doc)) { - await cronClient.addCron([ - { id: String(doc.id), schedule: doc.schedule!, command: doc.command }, - ]); - } + await cronClient.addCron([ + { id: String(doc.id), schedule: doc.schedule!, command: doc.command }, + ]); await this.set_crontab(); return doc; } @@ -51,18 +49,15 @@ export default class CronService { if (doc.isDisabled === 1) { return newDoc; } - if (this.isSixCron(doc)) { - await cronClient.delCron([String(newDoc.id)]); - } - if (this.isSixCron(newDoc)) { - await cronClient.addCron([ - { - id: String(newDoc.id), - schedule: newDoc.schedule!, - command: newDoc.command, - }, - ]); - } + + await cronClient.delCron([String(newDoc.id)]); + await cronClient.addCron([ + { + id: String(newDoc.id), + schedule: newDoc.schedule!, + command: newDoc.command, + }, + ]); await this.set_crontab(); return newDoc; } @@ -454,14 +449,12 @@ export default class CronService { public async enabled(ids: number[]) { await CrontabModel.update({ isDisabled: 0 }, { where: { id: ids } }); const docs = await CrontabModel.findAll({ where: { id: ids } }); - const sixCron = docs - .filter((x) => this.isSixCron(x)) - .map((doc) => ({ - id: String(doc.id), - schedule: doc.schedule!, - command: doc.command, - })); - await cronClient.addCron(sixCron); + const crons = docs.map((doc) => ({ + id: String(doc.id), + schedule: doc.schedule!, + command: doc.command, + })); + await cronClient.addCron(crons); await this.set_crontab(); } @@ -533,7 +526,6 @@ export default class CronService { this.logger.silly(crontab_string); fs.writeFileSync(config.crontabFile, crontab_string); - execSync(`crontab ${config.crontabFile}`); await CrontabModel.update({ saved: true }, { where: {} }); } @@ -576,7 +568,7 @@ export default class CronService { this.set_crontab(tabs); const sixCron = tabs.data - .filter((x) => this.isSixCron(x) && x.isDisabled !== 1) + .filter((x) => x.isDisabled !== 1) .map((doc) => ({ id: String(doc.id), schedule: doc.schedule!, diff --git a/docker/Dockerfile b/docker/Dockerfile index 539ea40e..23d8fa8c 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -1,13 +1,18 @@ -FROM python:3.10-alpine as builder -COPY package.json .npmrc pnpm-lock.yaml /tmp/build/ -RUN set -x \ - && apk update \ - && apk add nodejs npm git \ - && npm i -g pnpm@8.3.1 \ - && cd /tmp/build \ - && pnpm --registry https://registry.npmmirror.com install --prod +FROM node:18-slim as nodebuilder -FROM python:3.10-alpine +FROM python:3.10-slim as builder +COPY package.json .npmrc pnpm-lock.yaml /tmp/build/ +COPY --from=nodebuilder /usr/local/bin/node /usr/local/bin/ +COPY --from=nodebuilder /usr/local/lib/node_modules/. /usr/local/lib/node_modules/ +RUN set -x && \ + ln -s /usr/local/lib/node_modules/npm/bin/npm-cli.js /usr/local/bin/npm && \ + apt update && \ + apt install --no-install-recommends -y libatomic1 && \ + npm i -g pnpm@8.3.1 && \ + cd /tmp/build && \ + pnpm --registry https://registry.npmmirror.com install --prod + +FROM python:3.10-slim ARG QL_MAINTAINER="whyour" LABEL maintainer="${QL_MAINTAINER}" @@ -23,49 +28,45 @@ ENV PNPM_HOME=/root/.local/share/pnpm \ QL_DIR=/ql \ QL_BRANCH=${QL_BRANCH} -RUN set -x \ - && apk update -f \ - && apk upgrade \ - && apk --no-cache add -f bash \ - coreutils \ - git \ +COPY --from=nodebuilder /usr/local/bin/node /usr/local/bin/ +COPY --from=nodebuilder /usr/local/lib/node_modules/. /usr/local/lib/node_modules/ + +RUN set -x && \ + ln -s /usr/local/lib/node_modules/npm/bin/npm-cli.js /usr/local/bin/npm && \ + apt update && \ + apt upgrade -y && \ + apt install --no-install-recommends -y git \ curl \ wget \ - tzdata \ - perl \ - openssl \ nginx \ - nodejs \ jq \ - openssh \ procps \ - netcat-openbsd \ - npm \ - && rm -rf /var/cache/apk/* \ - && apk update \ - && ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime \ - && echo "Asia/Shanghai" > /etc/timezone \ - && git config --global user.email "qinglong@@users.noreply.github.com" \ - && git config --global user.name "qinglong" \ - && git config --global http.postBuffer 524288000 \ - && npm install -g pnpm@8.3.1 \ - && cd && pnpm config set registry https://registry.npmmirror.com \ - && pnpm add -g pm2 tsx \ - && rm -rf /root/.pnpm-store \ - && rm -rf /root/.local/share/pnpm/store \ - && rm -rf /root/.cache \ - && rm -rf /root/.npm + netcat \ + libatomic1 && \ + apt clean && \ + ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && \ + echo "Asia/Shanghai" >/etc/timezone && \ + git config --global user.email "qinglong@@users.noreply.github.com" && \ + git config --global user.name "qinglong" && \ + git config --global http.postBuffer 524288000 && \ + npm install -g pnpm@8.3.1 && \ + cd && pnpm config set registry https://registry.npmmirror.com && \ + pnpm add -g pm2 tsx && \ + rm -rf /root/.pnpm-store && \ + rm -rf /root/.local/share/pnpm/store && \ + rm -rf /root/.cache && \ + rm -rf /root/.npm ARG SOURCE_COMMIT -RUN git clone --depth=1 -b ${QL_BRANCH} ${QL_URL} ${QL_DIR} \ - && cd ${QL_DIR} \ - && cp -f .env.example .env \ - && chmod 777 ${QL_DIR}/shell/*.sh \ - && chmod 777 ${QL_DIR}/docker/*.sh \ - && git clone --depth=1 -b ${QL_BRANCH} https://github.com/${QL_MAINTAINER}/qinglong-static.git /static \ - && mkdir -p ${QL_DIR}/static \ - && cp -rf /static/* ${QL_DIR}/static \ - && rm -rf /static +RUN git clone --depth=1 -b ${QL_BRANCH} ${QL_URL} ${QL_DIR} && \ + cd ${QL_DIR} && \ + cp -f .env.example .env && \ + chmod 777 ${QL_DIR}/shell/*.sh && \ + chmod 777 ${QL_DIR}/docker/*.sh && \ + git clone --depth=1 -b ${QL_BRANCH} https://github.com/${QL_MAINTAINER}/qinglong-static.git /static && \ + mkdir -p ${QL_DIR}/static && \ + cp -rf /static/* ${QL_DIR}/static && \ + rm -rf /static COPY --from=builder /tmp/build/node_modules/. /ql/node_modules/ diff --git a/docker/docker-entrypoint.sh b/docker/docker-entrypoint.sh index 5e706c91..72569b5b 100755 --- a/docker/docker-entrypoint.sh +++ b/docker/docker-entrypoint.sh @@ -52,6 +52,6 @@ echo -e "############################################################\n" echo -e "容器启动成功..." echo -e "############################################################\n" -crond -f >/dev/null +tail -f /dev/null exec "$@" diff --git a/shell/bot.sh b/shell/bot.sh index d3a7ef3f..7706fc38 100755 --- a/shell/bot.sh +++ b/shell/bot.sh @@ -9,7 +9,7 @@ else fi echo -e "\n1、安装bot依赖...\n" -apk --no-cache add -f zlib-dev gcc jpeg-dev python3-dev musl-dev freetype-dev +apt install -y gcc python3-dev musl-dev echo -e "\nbot依赖安装成功...\n" echo -e "2、下载bot所需文件...\n" diff --git a/shell/otask.sh b/shell/otask.sh index 9ee3dafb..c240acaf 100755 --- a/shell/otask.sh +++ b/shell/otask.sh @@ -69,22 +69,6 @@ run_nohup() { nohup node $file_name &>$log_path & } -check_server() { - if [[ $cpu_warn ]] && [[ $mem_warn ]] && [[ $disk_warn ]]; then - local top_result=$(top -b -n 1) - cpu_use=$(echo "$top_result" | grep CPU | grep -v -E 'grep|PID' | awk '{print $2}' | cut -f 1 -d "%" | head -n 1) - - mem_free=$(free -m | grep "Mem" | awk '{print $3}' | head -n 1) - mem_total=$(free -m | grep "Mem" | awk '{print $2}' | head -n 1) - mem_use=$(printf "%d%%" $((mem_free * 100 / mem_total)) | cut -f 1 -d "%" | head -n 1) - - disk_use=$(df -P | grep /dev | grep -v -E '(tmp|boot|shm)' | awk '{print $5}' | cut -f 1 -d "%" | head -n 1) - if [[ $cpu_use -gt $cpu_warn ]] && [[ $cpu_warn ]] || [[ $mem_free -lt $mem_warn ]] || [[ $disk_use -gt $disk_warn ]]; then - local resource=$(echo "$top_result" | grep -v -E 'grep|Mem|idle|Load|tr' | awk '{$2="";$3="";$4="";$5="";$7="";print $0}' | head -n 10 | tr '\n' '|' | sed s/\|/\\\\n/g) - notify_api "服务器资源异常警告" "当前CPU占用 $cpu_use% 内存占用 $mem_use% 磁盘占用 $disk_use% \n资源占用详情 \n\n $resource" - fi - fi -} ## 正常运行单个脚本,$1:传入参数 run_normal() { diff --git a/shell/share.sh b/shell/share.sh index 52b4cab6..843731e3 100755 --- a/shell/share.sh +++ b/shell/share.sh @@ -429,8 +429,6 @@ handle_task_before() { echo -e "## 开始执行... $begin_time\n" - [[ $is_macos -eq 0 ]] && check_server - . $file_task_before "$@" }