mirror of
https://github.com/whyour/qinglong.git
synced 2025-07-07 03:46:07 +08:00
缓存 node 和 python 依赖
This commit is contained in:
parent
8009634b44
commit
1befa1bb8c
|
@ -23,3 +23,5 @@ export const SAMPLE_FILES = [
|
||||||
target: 'data/scripts/notify.py',
|
target: 'data/scripts/notify.py',
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
|
export const PYTHON_INSTALL_DIR = process.env.PYTHON_HOME;
|
||||||
|
|
|
@ -8,9 +8,10 @@ import psTreeFun from 'pstree.remy';
|
||||||
import { promisify } from 'util';
|
import { promisify } from 'util';
|
||||||
import { load } from 'js-yaml';
|
import { load } from 'js-yaml';
|
||||||
import config from './index';
|
import config from './index';
|
||||||
import { TASK_COMMAND } from './const';
|
import { PYTHON_INSTALL_DIR, TASK_COMMAND } from './const';
|
||||||
import Logger from '../loaders/logger';
|
import Logger from '../loaders/logger';
|
||||||
import { writeFileWithLock } from '../shared/utils';
|
import { writeFileWithLock } from '../shared/utils';
|
||||||
|
import { DependenceTypes } from '../data/dependence';
|
||||||
|
|
||||||
export * from './share';
|
export * from './share';
|
||||||
|
|
||||||
|
@ -558,3 +559,34 @@ export async function setSystemTimezone(timezone: string): Promise<boolean> {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function getInstallCommand(type: DependenceTypes, name: string): string {
|
||||||
|
const baseCommands = {
|
||||||
|
[DependenceTypes.nodejs]: 'pnpm add -g',
|
||||||
|
[DependenceTypes.python3]:
|
||||||
|
'pip3 install --disable-pip-version-check --root-user-action=ignore',
|
||||||
|
[DependenceTypes.linux]: 'apk add --no-check-certificate',
|
||||||
|
};
|
||||||
|
|
||||||
|
let command = baseCommands[type];
|
||||||
|
|
||||||
|
if (type === DependenceTypes.python3 && PYTHON_INSTALL_DIR) {
|
||||||
|
command = `${command} --prefix=${PYTHON_INSTALL_DIR}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
return `${command} ${name.trim()}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getUninstallCommand(
|
||||||
|
type: DependenceTypes,
|
||||||
|
name: string,
|
||||||
|
): string {
|
||||||
|
const baseCommands = {
|
||||||
|
[DependenceTypes.nodejs]: 'pnpm remove -g',
|
||||||
|
[DependenceTypes.python3]:
|
||||||
|
'pip3 uninstall --disable-pip-version-check --root-user-action=ignore -y',
|
||||||
|
[DependenceTypes.linux]: 'apk del',
|
||||||
|
};
|
||||||
|
|
||||||
|
return `${baseCommands[type]} ${name.trim()}`;
|
||||||
|
}
|
||||||
|
|
|
@ -41,12 +41,6 @@ export enum DependenceTypes {
|
||||||
'linux',
|
'linux',
|
||||||
}
|
}
|
||||||
|
|
||||||
export enum InstallDependenceCommandTypes {
|
|
||||||
'pnpm add -g',
|
|
||||||
'pip3 install --disable-pip-version-check --root-user-action=ignore',
|
|
||||||
'apk add --no-check-certificate',
|
|
||||||
}
|
|
||||||
|
|
||||||
export enum GetDependenceCommandTypes {
|
export enum GetDependenceCommandTypes {
|
||||||
'pnpm ls -g ',
|
'pnpm ls -g ',
|
||||||
'pip3 show --disable-pip-version-check',
|
'pip3 show --disable-pip-version-check',
|
||||||
|
@ -59,12 +53,6 @@ export enum versionDependenceCommandTypes {
|
||||||
'=',
|
'=',
|
||||||
}
|
}
|
||||||
|
|
||||||
export enum unInstallDependenceCommandTypes {
|
|
||||||
'pnpm remove -g',
|
|
||||||
'pip3 uninstall --disable-pip-version-check --root-user-action=ignore -y',
|
|
||||||
'apk del',
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface DependenceInstance
|
export interface DependenceInstance
|
||||||
extends Model<Dependence, Dependence>,
|
extends Model<Dependence, Dependence>,
|
||||||
Dependence {}
|
Dependence {}
|
||||||
|
|
|
@ -3,10 +3,8 @@ import winston from 'winston';
|
||||||
import config from '../config';
|
import config from '../config';
|
||||||
import {
|
import {
|
||||||
Dependence,
|
Dependence,
|
||||||
InstallDependenceCommandTypes,
|
|
||||||
DependenceStatus,
|
DependenceStatus,
|
||||||
DependenceTypes,
|
DependenceTypes,
|
||||||
unInstallDependenceCommandTypes,
|
|
||||||
DependenceModel,
|
DependenceModel,
|
||||||
GetDependenceCommandTypes,
|
GetDependenceCommandTypes,
|
||||||
versionDependenceCommandTypes,
|
versionDependenceCommandTypes,
|
||||||
|
@ -19,6 +17,8 @@ import {
|
||||||
getPid,
|
getPid,
|
||||||
killTask,
|
killTask,
|
||||||
promiseExecSuccess,
|
promiseExecSuccess,
|
||||||
|
getInstallCommand,
|
||||||
|
getUninstallCommand,
|
||||||
} from '../config/util';
|
} from '../config/util';
|
||||||
import dayjs from 'dayjs';
|
import dayjs from 'dayjs';
|
||||||
import taskLimit from '../shared/pLimit';
|
import taskLimit from '../shared/pLimit';
|
||||||
|
@ -153,8 +153,8 @@ export default class DependenceService {
|
||||||
const docs = await DependenceModel.findAll({ where: { id: ids } });
|
const docs = await DependenceModel.findAll({ where: { id: ids } });
|
||||||
for (const doc of docs) {
|
for (const doc of docs) {
|
||||||
taskLimit.removeQueuedDependency(doc);
|
taskLimit.removeQueuedDependency(doc);
|
||||||
const depInstallCommand = InstallDependenceCommandTypes[doc.type];
|
const depInstallCommand = getInstallCommand(doc.type, doc.name);
|
||||||
const depUnInstallCommand = unInstallDependenceCommandTypes[doc.type];
|
const depUnInstallCommand = getUninstallCommand(doc.type, doc.name);
|
||||||
const installCmd = `${depInstallCommand} ${doc.name.trim()}`;
|
const installCmd = `${depInstallCommand} ${doc.name.trim()}`;
|
||||||
const unInstallCmd = `${depUnInstallCommand} ${doc.name.trim()}`;
|
const unInstallCmd = `${depUnInstallCommand} ${doc.name.trim()}`;
|
||||||
const pids = await Promise.all([
|
const pids = await Promise.all([
|
||||||
|
@ -226,11 +226,9 @@ export default class DependenceService {
|
||||||
? 'installDependence'
|
? 'installDependence'
|
||||||
: 'uninstallDependence';
|
: 'uninstallDependence';
|
||||||
let depName = dependency.name.trim();
|
let depName = dependency.name.trim();
|
||||||
const depRunCommand = (
|
const command = isInstall
|
||||||
isInstall
|
? getInstallCommand(dependency.type, depName)
|
||||||
? InstallDependenceCommandTypes
|
: getUninstallCommand(dependency.type, depName);
|
||||||
: unInstallDependenceCommandTypes
|
|
||||||
)[dependency.type];
|
|
||||||
const actionText = isInstall ? '安装' : '删除';
|
const actionText = isInstall ? '安装' : '删除';
|
||||||
const startTime = dayjs();
|
const startTime = dayjs();
|
||||||
|
|
||||||
|
@ -304,12 +302,9 @@ export default class DependenceService {
|
||||||
const proxyStr = dependenceProxyFileExist
|
const proxyStr = dependenceProxyFileExist
|
||||||
? `source ${config.dependenceProxyFile} &&`
|
? `source ${config.dependenceProxyFile} &&`
|
||||||
: '';
|
: '';
|
||||||
const cp = spawn(
|
const cp = spawn(`${proxyStr} ${command}`, {
|
||||||
`${proxyStr} ${depRunCommand} ${dependency.name.trim()}`,
|
shell: '/bin/bash',
|
||||||
{
|
});
|
||||||
shell: '/bin/bash',
|
|
||||||
},
|
|
||||||
);
|
|
||||||
|
|
||||||
cp.stdout.on('data', async (data) => {
|
cp.stdout.on('data', async (data) => {
|
||||||
this.sockService.sendMessage({
|
this.sockService.sendMessage({
|
||||||
|
|
|
@ -14,14 +14,13 @@ LABEL maintainer="${QL_MAINTAINER}"
|
||||||
ARG QL_URL=https://github.com/${QL_MAINTAINER}/qinglong.git
|
ARG QL_URL=https://github.com/${QL_MAINTAINER}/qinglong.git
|
||||||
ARG QL_BRANCH=develop
|
ARG QL_BRANCH=develop
|
||||||
|
|
||||||
ENV PNPM_HOME=/root/.local/share/pnpm \
|
ENV QL_DIR=/ql \
|
||||||
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/root/.local/share/pnpm:/root/.local/share/pnpm/global/5/node_modules \
|
QL_BRANCH=${QL_BRANCH} \
|
||||||
NODE_PATH=/usr/local/bin:/usr/local/pnpm-global/5/node_modules:/usr/local/lib/node_modules:/root/.local/share/pnpm/global/5/node_modules \
|
|
||||||
LANG=C.UTF-8 \
|
LANG=C.UTF-8 \
|
||||||
SHELL=/bin/bash \
|
SHELL=/bin/bash \
|
||||||
PS1="\u@\h:\w \$ " \
|
PS1="\u@\h:\w \$ " \
|
||||||
QL_DIR=/ql \
|
PYTHONPATH= \
|
||||||
QL_BRANCH=${QL_BRANCH}
|
PYTHON_SHORT_VERSION=
|
||||||
|
|
||||||
VOLUME /ql/data
|
VOLUME /ql/data
|
||||||
|
|
||||||
|
@ -56,11 +55,9 @@ RUN set -x \
|
||||||
&& git config --global user.email "qinglong@@users.noreply.github.com" \
|
&& git config --global user.email "qinglong@@users.noreply.github.com" \
|
||||||
&& git config --global user.name "qinglong" \
|
&& git config --global user.name "qinglong" \
|
||||||
&& git config --global http.postBuffer 524288000 \
|
&& git config --global http.postBuffer 524288000 \
|
||||||
&& rm -rf /root/.pnpm-store \
|
|
||||||
&& rm -rf /root/.local/share/pnpm/store \
|
|
||||||
&& rm -rf /root/.cache \
|
&& rm -rf /root/.cache \
|
||||||
&& ulimit -c 0 \
|
&& ulimit -c 0 \
|
||||||
&& pip3 install requests
|
&& PYTHON_SHORT_VERSION=$(echo ${PYTHON_VERSION} | cut -d. -f1,2)
|
||||||
|
|
||||||
ARG SOURCE_COMMIT
|
ARG SOURCE_COMMIT
|
||||||
RUN git clone --depth=1 -b ${QL_BRANCH} ${QL_URL} ${QL_DIR} \
|
RUN git clone --depth=1 -b ${QL_BRANCH} ${QL_URL} ${QL_DIR} \
|
||||||
|
@ -73,6 +70,17 @@ RUN git clone --depth=1 -b ${QL_BRANCH} ${QL_URL} ${QL_DIR} \
|
||||||
&& cp -rf /static/* ${QL_DIR}/static \
|
&& cp -rf /static/* ${QL_DIR}/static \
|
||||||
&& rm -rf /static
|
&& rm -rf /static
|
||||||
|
|
||||||
|
ENV PNPM_HOME=${QL_DIR}/data/dep_cache/node \
|
||||||
|
PYTHON_HOME=${QL_DIR}/data/dep_cache/python3 \
|
||||||
|
PYTHONUSERBASE=${QL_DIR}/data/dep_cache/python3
|
||||||
|
|
||||||
|
ENV PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:${PNPM_HOME} \
|
||||||
|
NODE_PATH=/usr/local/bin:/usr/local/lib/node_modules:${PNPM_HOME}/global/5/node_modules \
|
||||||
|
PIP_CACHE_DIR=${PYTHON_HOME}/pip \
|
||||||
|
PYTHONPATH=${PYTHON_HOME}:${PYTHON_HOME}/lib/python${PYTHON_SHORT_VERSION}:${PYTHON_HOME}/lib/python${PYTHON_SHORT_VERSION}/site-packages:${PYTHONPATH}
|
||||||
|
|
||||||
|
RUN pip3 install --prefix ${PYTHON_HOME} requests
|
||||||
|
|
||||||
COPY --from=builder /tmp/build/node_modules/. /ql/node_modules/
|
COPY --from=builder /tmp/build/node_modules/. /ql/node_modules/
|
||||||
|
|
||||||
WORKDIR ${QL_DIR}
|
WORKDIR ${QL_DIR}
|
||||||
|
|
|
@ -14,14 +14,13 @@ LABEL maintainer="${QL_MAINTAINER}"
|
||||||
ARG QL_URL=https://github.com/${QL_MAINTAINER}/qinglong.git
|
ARG QL_URL=https://github.com/${QL_MAINTAINER}/qinglong.git
|
||||||
ARG QL_BRANCH=develop
|
ARG QL_BRANCH=develop
|
||||||
|
|
||||||
ENV PNPM_HOME=/root/.local/share/pnpm \
|
ENV QL_DIR=/ql \
|
||||||
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/root/.local/share/pnpm:/root/.local/share/pnpm/global/5/node_modules \
|
QL_BRANCH=${QL_BRANCH} \
|
||||||
NODE_PATH=/usr/local/bin:/usr/local/pnpm-global/5/node_modules:/usr/local/lib/node_modules:/root/.local/share/pnpm/global/5/node_modules \
|
|
||||||
LANG=C.UTF-8 \
|
LANG=C.UTF-8 \
|
||||||
SHELL=/bin/bash \
|
SHELL=/bin/bash \
|
||||||
PS1="\u@\h:\w \$ " \
|
PS1="\u@\h:\w \$ " \
|
||||||
QL_DIR=/ql \
|
PYTHONPATH= \
|
||||||
QL_BRANCH=${QL_BRANCH}
|
PYTHON_SHORT_VERSION=
|
||||||
|
|
||||||
VOLUME /ql/data
|
VOLUME /ql/data
|
||||||
|
|
||||||
|
@ -56,11 +55,9 @@ RUN set -x \
|
||||||
&& git config --global user.email "qinglong@@users.noreply.github.com" \
|
&& git config --global user.email "qinglong@@users.noreply.github.com" \
|
||||||
&& git config --global user.name "qinglong" \
|
&& git config --global user.name "qinglong" \
|
||||||
&& git config --global http.postBuffer 524288000 \
|
&& git config --global http.postBuffer 524288000 \
|
||||||
&& rm -rf /root/.pnpm-store \
|
|
||||||
&& rm -rf /root/.local/share/pnpm/store \
|
|
||||||
&& rm -rf /root/.cache \
|
&& rm -rf /root/.cache \
|
||||||
&& ulimit -c 0 \
|
&& ulimit -c 0 \
|
||||||
&& pip3 install requests
|
&& PYTHON_SHORT_VERSION=$(echo ${PYTHON_VERSION} | cut -d. -f1,2)
|
||||||
|
|
||||||
ARG SOURCE_COMMIT
|
ARG SOURCE_COMMIT
|
||||||
RUN git clone --depth=1 -b ${QL_BRANCH} ${QL_URL} ${QL_DIR} \
|
RUN git clone --depth=1 -b ${QL_BRANCH} ${QL_URL} ${QL_DIR} \
|
||||||
|
@ -73,6 +70,17 @@ RUN git clone --depth=1 -b ${QL_BRANCH} ${QL_URL} ${QL_DIR} \
|
||||||
&& cp -rf /static/* ${QL_DIR}/static \
|
&& cp -rf /static/* ${QL_DIR}/static \
|
||||||
&& rm -rf /static
|
&& rm -rf /static
|
||||||
|
|
||||||
|
ENV PNPM_HOME=${QL_DIR}/data/dep_cache/node \
|
||||||
|
PYTHON_HOME=${QL_DIR}/data/dep_cache/python3 \
|
||||||
|
PYTHONUSERBASE=${QL_DIR}/data/dep_cache/python3
|
||||||
|
|
||||||
|
ENV PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:${PNPM_HOME} \
|
||||||
|
NODE_PATH=/usr/local/bin:/usr/local/lib/node_modules:${PNPM_HOME}/global/5/node_modules \
|
||||||
|
PIP_CACHE_DIR=${PYTHON_HOME}/pip \
|
||||||
|
PYTHONPATH=${PYTHON_HOME}:${PYTHON_HOME}/lib/python${PYTHON_SHORT_VERSION}:${PYTHON_HOME}/lib/python${PYTHON_SHORT_VERSION}/site-packages:${PYTHONPATH}
|
||||||
|
|
||||||
|
RUN pip3 install --prefix ${PYTHON_HOME} requests
|
||||||
|
|
||||||
COPY --from=builder /tmp/build/node_modules/. /ql/node_modules/
|
COPY --from=builder /tmp/build/node_modules/. /ql/node_modules/
|
||||||
|
|
||||||
WORKDIR ${QL_DIR}
|
WORKDIR ${QL_DIR}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user