From dcd93f930d3dcf06f318959442c7c2768601a138 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 | 15 ++-- back/services/cron.ts | 35 ++++----- docker/310.Dockerfile | 90 ++++++++++++----------- docker/Dockerfile | 92 ++++++++++++------------ docker/docker-entrypoint.sh | 2 +- shell/bot.sh | 2 +- 6 files changed, 115 insertions(+), 121 deletions(-) diff --git a/.github/workflows/build_docker_image.yml b/.github/workflows/build_docker_image.yml index 23c98b1f..ecf6918a 100644 --- a/.github/workflows/build_docker_image.yml +++ b/.github/workflows/build_docker_image.yml @@ -5,8 +5,9 @@ on: paths-ignore: - "*.md" branches: - - "master" - - "develop" + - 'master' + - 'develop' + - 'debian' tags: - "v*" schedule: @@ -176,15 +177,14 @@ jobs: QL_BRANCH=${{ github.ref_name }} SOURCE_COMMIT=${{ github.sha }} network: host - # linux/s390x npm 暂不可用 - platforms: linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm64,linux/ppc64le,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: | @@ -242,8 +242,7 @@ jobs: QL_BRANCH=${{ github.ref_name }} SOURCE_COMMIT=${{ github.sha }} network: host - # linux/s390x npm 暂不可用 - platforms: linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm64,linux/ppc64le,linux/386 + platforms: linux/amd64,linux/arm/v7,linux/arm64,linux/ppc64le,linux/s390x context: . file: ./docker/310.Dockerfile push: true diff --git a/back/services/cron.ts b/back/services/cron.ts index 1d70660d..a5f14472 100644 --- a/back/services/cron.ts +++ b/back/services/cron.ts @@ -58,7 +58,7 @@ export default class CronService { return doc; } - if (this.isNodeCron(doc) && !this.isSpecialSchedule(doc.schedule)) { + if (!this.isSpecialSchedule(doc.schedule)) { await cronClient.addCron([ { name: doc.name || '', @@ -88,11 +88,9 @@ export default class CronService { return newDoc; } - if (this.isNodeCron(doc)) { - await cronClient.delCron([String(doc.id)]); - } + await cronClient.delCron([String(newDoc.id)]); - if (this.isNodeCron(newDoc) && !this.isSpecialSchedule(newDoc.schedule)) { + if (!this.isSpecialSchedule(newDoc.schedule)) { await cronClient.addCron([ { name: doc.name || '', @@ -532,20 +530,19 @@ 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.isNodeCron(x) && !this.isSpecialSchedule(x.schedule)) - .map((doc) => ({ - name: doc.name || '', - id: String(doc.id), - schedule: doc.schedule!, - command: this.makeCommand(doc), - extra_schedules: doc.extra_schedules || [], - })); + const crons = docs.map((doc) => ({ + name: doc.name || '', + id: String(doc.id), + schedule: doc.schedule!, + command: this.makeCommand(doc), + extra_schedules: doc.extra_schedules || [], + })); if (isDemoEnv()) { return; } - await cronClient.addCron(sixCron); + + await cronClient.addCron(crons); await this.setCrontab(); } @@ -638,7 +635,6 @@ export default class CronService { await writeFileWithLock(config.crontabFile, crontab_string); - execSync(`crontab ${config.crontabFile}`); await CrontabModel.update({ saved: true }, { where: {} }); } @@ -679,12 +675,7 @@ export default class CronService { public async autosave_crontab() { const tabs = await this.crontabs(); const regularCrons = tabs.data - .filter( - (x) => - x.isDisabled !== 1 && - this.isNodeCron(x) && - !this.isSpecialSchedule(x.schedule), - ) + .filter((x) => x.isDisabled !== 1 && !this.isSpecialSchedule(x.schedule)) .map((doc) => ({ name: doc.name || '', id: String(doc.id), diff --git a/docker/310.Dockerfile b/docker/310.Dockerfile index 8cd0f640..74aca74c 100644 --- a/docker/310.Dockerfile +++ b/docker/310.Dockerfile @@ -1,13 +1,18 @@ -FROM python:3.10-alpine3.18 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 pm2 ts-node \ - && cd /tmp/build \ - && pnpm install --prod +FROM node:20-slim AS nodebuilder -FROM python:3.10-alpine +FROM python:3.10-slim-bullseye 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 install --prod + +FROM python:3.10-slim-bullseye ARG QL_MAINTAINER="whyour" LABEL maintainer="${QL_MAINTAINER}" @@ -21,52 +26,47 @@ ENV QL_DIR=/ql \ SHELL=/bin/bash \ PS1="\u@\h:\w \$ " -VOLUME /ql/data - -EXPOSE 5700 +COPY --from=nodebuilder /usr/local/bin/node /usr/local/bin/ +COPY --from=nodebuilder /usr/local/lib/node_modules/. /usr/local/lib/node_modules/ -COPY --from=builder /usr/local/lib/node_modules/. /usr/local/lib/node_modules/ -COPY --from=builder /usr/local/bin/. /usr/local/bin/ - -RUN set -x \ - && apk update -f \ - && apk upgrade \ - && apk --no-cache add -f bash \ - coreutils \ - git \ +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 \ + openssh-client \ nginx \ - nodejs \ jq \ - openssh \ procps \ - netcat-openbsd \ + netcat \ unzip \ - 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 \ - && rm -rf /root/.cache \ - && ulimit -c 0 + 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 pm2 ts-node && \ + rm -rf /root/.cache && \ + rm -rf /root/.npm && \ + ulimit -c 0 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 ENV PNPM_HOME=${QL_DIR}/data/dep_cache/node \ PYTHON_HOME=${QL_DIR}/data/dep_cache/python3 \ @@ -87,3 +87,7 @@ HEALTHCHECK --interval=5s --timeout=2s --retries=20 \ CMD curl -sf --noproxy '*' http://127.0.0.1:5600/api/health || exit 1 ENTRYPOINT ["./docker/docker-entrypoint.sh"] + +VOLUME /ql/data + +EXPOSE 5700 diff --git a/docker/Dockerfile b/docker/Dockerfile index ae8d8cb1..d1a1d117 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -1,13 +1,18 @@ -FROM python:3.11-alpine3.18 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 pm2 ts-node \ - && cd /tmp/build \ - && pnpm install --prod +FROM node:20-slim AS nodebuilder -FROM python:3.11-alpine +FROM python:3.11-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 install --prod + +FROM python:3.11-slim ARG QL_MAINTAINER="whyour" LABEL maintainer="${QL_MAINTAINER}" @@ -21,52 +26,43 @@ ENV QL_DIR=/ql \ SHELL=/bin/bash \ PS1="\u@\h:\w \$ " -VOLUME /ql/data - -EXPOSE 5700 +COPY --from=nodebuilder /usr/local/bin/node /usr/local/bin/ +COPY --from=nodebuilder /usr/local/lib/node_modules/. /usr/local/lib/node_modules/ -COPY --from=builder /usr/local/lib/node_modules/. /usr/local/lib/node_modules/ -COPY --from=builder /usr/local/bin/. /usr/local/bin/ - -RUN set -x \ - && apk update -f \ - && apk upgrade \ - && apk --no-cache add -f bash \ - coreutils \ - git \ +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 \ + netcat \ unzip \ - 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 \ - && rm -rf /root/.cache \ - && ulimit -c 0 + 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 pm2 ts-node && \ + rm -rf /root/.cache && \ + rm -rf /root/.npm && \ + ulimit -c 0 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 ENV PNPM_HOME=${QL_DIR}/data/dep_cache/node \ PYTHON_HOME=${QL_DIR}/data/dep_cache/python3 \ @@ -87,3 +83,7 @@ HEALTHCHECK --interval=5s --timeout=2s --retries=20 \ CMD curl -sf --noproxy '*' http://127.0.0.1:5600/api/health || exit 1 ENTRYPOINT ["./docker/docker-entrypoint.sh"] + +VOLUME /ql/data + +EXPOSE 5700 diff --git a/docker/docker-entrypoint.sh b/docker/docker-entrypoint.sh index be275a27..9aacfce0 100755 --- a/docker/docker-entrypoint.sh +++ b/docker/docker-entrypoint.sh @@ -39,6 +39,6 @@ fi log_with_style "SUCCESS" "🎉 容器启动成功!" -crond -f >/dev/null +tail -f /dev/null exec "$@" diff --git a/shell/bot.sh b/shell/bot.sh index f30cad26..b32a5c49 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"