From f89f3bfed1bfe0b1faae9147c4c04562bf431ee6 Mon Sep 17 00:00:00 2001 From: whyour Date: Sun, 23 Jul 2023 22:13:55 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=20debian=20apt=20=E5=91=BD?= =?UTF-8?q?=E4=BB=A4=EF=BC=8C=E6=94=AF=E6=8C=81=20qinglong=20=E5=91=BD?= =?UTF-8?q?=E4=BB=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/build_docker_image.yml | 6 +- .npmignore | 20 +++++ back/config/index.ts | 7 +- back/data/dependence.ts | 2 +- back/loaders/initFile.ts | 7 +- docker/Dockerfile | 7 +- package.json | 18 ++++- shell/share.sh | 5 ++ shell/start.sh | 98 ++++++++++++++++++++++++ 9 files changed, 163 insertions(+), 7 deletions(-) create mode 100644 .npmignore create mode 100644 shell/start.sh diff --git a/.github/workflows/build_docker_image.yml b/.github/workflows/build_docker_image.yml index fa84f369..8c171de5 100644 --- a/.github/workflows/build_docker_image.yml +++ b/.github/workflows/build_docker_image.yml @@ -57,6 +57,11 @@ jobs: pnpm install --frozen-lockfile pnpm build:front pnpm build:back + + - name: publich npm package + run: | + echo "//registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }}" >> ~/.npmrc + npm publish - name: copy to static repo env: @@ -141,7 +146,6 @@ jobs: type=semver,pattern={{version}} type=semver,pattern={{major}}.{{minor}} type=semver,pattern={{major}} - type=raw,value=latest,enable=${{ github.ref == format('refs/heads/{0}', 'master') }} - name: Set up QEMU uses: docker/setup-qemu-action@v2 diff --git a/.npmignore b/.npmignore new file mode 100644 index 00000000..233d8d04 --- /dev/null +++ b/.npmignore @@ -0,0 +1,20 @@ +.github/ +.vscode/ +.history/ +back/ +cli/ +data/ +src/ +static/**/*.js.map +static/**/*.gz +.editorconfig +.gitignore +.prettierignore +.prettierrc +.umirc.ts +nodemon.json +pnpm-lock.yaml +tsconfig.back.json +tsconfig.json +typings.d.ts +.env \ No newline at end of file diff --git a/back/config/index.ts b/back/config/index.ts index 3c7ac0d8..d072da94 100644 --- a/back/config/index.ts +++ b/back/config/index.ts @@ -19,9 +19,14 @@ const lastVersionFile = `https://qn.whyour.cn/version.yaml`; const rootPath = process.env.QL_DIR as string; const envFound = dotenv.config({ path: path.join(rootPath, '.env') }); -const dataPath = path.join(rootPath, 'data/'); +let dataPath = path.join(rootPath, 'data/'); const shellPath = path.join(rootPath, 'shell/'); const tmpPath = path.join(rootPath, '.tmp/'); + +if (process.env.QL_DATA_DIR) { + dataPath = process.env.QL_DATA_DIR; +} + const samplePath = path.join(rootPath, 'sample/'); const configPath = path.join(dataPath, 'config/'); const scriptPath = path.join(dataPath, 'scripts/'); diff --git a/back/data/dependence.ts b/back/data/dependence.ts index 5fc838a2..0f1a1529 100644 --- a/back/data/dependence.ts +++ b/back/data/dependence.ts @@ -49,7 +49,7 @@ export enum InstallDependenceCommandTypes { export enum GetDependenceCommandTypes { 'pnpm ls -g ', 'pip3 show --disable-pip-version-check', - 'apk info -es', + 'apt info', } export enum versionDependenceCommandTypes { diff --git a/back/loaders/initFile.ts b/back/loaders/initFile.ts index ec0e03d8..84d64ceb 100644 --- a/back/loaders/initFile.ts +++ b/back/loaders/initFile.ts @@ -6,7 +6,12 @@ import Logger from './logger'; import { fileExist } from '../config/util'; const rootPath = process.env.QL_DIR as string; -const dataPath = path.join(rootPath, 'data/'); +let dataPath = path.join(rootPath, 'data/'); + +if (process.env.QL_DATA_DIR) { + dataPath = process.env.QL_DATA_DIR; +} + const configPath = path.join(dataPath, 'config/'); const scriptPath = path.join(dataPath, 'scripts/'); const logPath = path.join(dataPath, 'log/'); diff --git a/docker/Dockerfile b/docker/Dockerfile index 23d8fa8c..ba2589fb 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -1,6 +1,6 @@ FROM node:18-slim as nodebuilder -FROM python:3.10-slim as builder +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/ @@ -12,7 +12,7 @@ RUN set -x && \ cd /tmp/build && \ pnpm --registry https://registry.npmmirror.com install --prod -FROM python:3.10-slim +FROM python:3.10-slim-bullseye ARG QL_MAINTAINER="whyour" LABEL maintainer="${QL_MAINTAINER}" @@ -38,6 +38,9 @@ RUN set -x && \ apt install --no-install-recommends -y git \ curl \ wget \ + tzdata \ + perl \ + openssl \ nginx \ jq \ procps \ diff --git a/package.json b/package.json index 34cfc943..8f3ca639 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,16 @@ { - "private": true, + "name": "@whyour/qinglong", + "version": "0.7.6", + "description": "Timed task management platform supporting Python3, JavaScript, Shell, Typescript", + "repository": { + "type": "git", + "url": "https://github.com/whyour/qinglong.git" + }, + "author": "whyour", + "license": "Apache License 2.0", + "bugs": { + "url": "https://github.com/whyour/qinglong/issues" + }, "scripts": { "start": "concurrently -n w: npm:start:*", "start:front": "max dev", @@ -28,6 +39,11 @@ "prettier --parser=typescript --write" ] }, + "bin": { + "ql": "shell/update.sh", + "task": "shell/task.sh", + "qinglong": "shell/start.sh" + }, "pnpm": { "peerDependencyRules": { "ignoreMissing": [ diff --git a/shell/share.sh b/shell/share.sh index 843731e3..9267c1cd 100755 --- a/shell/share.sh +++ b/shell/share.sh @@ -4,6 +4,11 @@ dir_root=$QL_DIR dir_tmp=$dir_root/.tmp dir_data=$dir_root/data + +if [[ $QL_DATA_DIR ]]; then + dir_data=$QL_DATA_DIR +fi + dir_shell=$dir_root/shell dir_sample=$dir_root/sample dir_static=$dir_root/static diff --git a/shell/start.sh b/shell/start.sh new file mode 100644 index 00000000..7ad43e90 --- /dev/null +++ b/shell/start.sh @@ -0,0 +1,98 @@ +#!/usr/bin/env bash + +# 前置依赖 nodejs、npm +set -e +set -x + +if [[ ! $QL_DIR ]]; then + npm_dir=$(npm root -g) + pnpm_dir=$(pnpm root -g) + if [[ -d "$npm_dir/@whyour/qinglong" ]]; then + QL_DIR="$npm_dir/@whyour/qinglong" + elif [[ -d "$pnpm_dir/@whyour/qinglong" ]]; then + QL_DIR="$pnpm_dir/@whyour/qinglong" + else + echo -e "未找到 qinglong 模块,请先执行 npm i -g @whyour/qinglong 安装" + fi + + if [[ $QL_DIR ]]; then + echo -e "请先设置 export QL_DIR=$QL_DIR,环境变量,并添加到系统环境变量,然后再次执行命令 qinglong 启动服务" + fi + + exit 1 +fi + +if [[ ! $QL_DATA_DIR ]]; then + echo -e "请先设置数据存储目录 export QL_DATA_DIR 环境变量,目录必须以斜杠开头的绝对路径,并添加到系统环境变量" + exit 1 +fi + +# 安装依赖 +os_name=$(source /etc/os-release && echo "$ID") + +if [[ $os_name == 'alpine' ]]; then + apk update + apk add -f bash \ + coreutils \ + git \ + curl \ + wget \ + tzdata \ + perl \ + openssl \ + jq \ + nginx \ + openssh \ + procps \ + netcat-openbsd +elif [[ $os_name == 'debian' ]] || [[ $os_name == 'ubuntu' ]]; then + apt update + apt install -y git curl wget tzdata perl openssl jq nginx procps netcat +elif [[ $os_name == 'centos' ]]; then + yum update + yum install -y epel-release git curl wget tzdata perl openssl jq nginx procps netcat +else + echo -e "暂不支持此系统部署 $os_name" + exit 1 +fi + +npm install -g pnpm@8.3.1 +cd && pnpm config set registry https://registry.npmmirror.com +pnpm add -g pm2 tsx + +cd ${QL_DIR} +cp -f .env.example .env +chmod 777 ${QL_DIR}/shell/*.sh + +. ${QL_DIR}/shell/share.sh + +make_dir /etc/nginx/conf.d +make_dir /run/nginx +init_nginx +fix_config + +pm2 l &>/dev/null + +patch_version +if [[ $PipMirror ]]; then + pip3 config set global.index-url $PipMirror +fi +current_npm_registry=$(cd && pnpm config get registry) +is_equal_registry=$(echo $current_npm_registry | grep "${NpmMirror}") +if [[ "$is_equal_registry" == "" ]]; then + cd && pnpm config set registry $NpmMirror + pnpm install -g +fi +update_depend + +reload_pm2 + +nginx -s reload 2>/dev/null || nginx -c /etc/nginx/nginx.conf + +if [[ $AutoStartBot == true ]]; then + nohup ql -l bot >$dir_log/bot.log 2>&1 & +fi + +if [[ $EnableExtraShell == true ]]; then + nohup ql -l extra >$dir_log/extra.log 2>&1 & +fi