基础命令重构

1. 移除命令中 bash 依赖
2. jd命令重命名为js
3. 修改默认初始目录
4. 移除冗余代码
This commit is contained in:
whyour
2021-03-25 23:44:57 +08:00
parent 43eab41579
commit 8906472ae0
17 changed files with 133 additions and 199 deletions
+28 -25
View File
@@ -1,12 +1,12 @@
FROM node:lts-alpine as build
LABEL maintainer="whyour"
ARG JD_BASE_URL=https://github.com.cnpmjs.org/whyour/qinglong
ARG JD_BASE_BRANCH=master
ARG QL_BASE_URL=https://github.com.cnpmjs.org/whyour/qinglong
ARG QL_BASE_BRANCH=master
ENV PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin \
LANG=zh_CN.UTF-8 \
SHELL=/bin/bash \
PS1="\u@\h:\w \$ " \
JD_DIR=/jd
QL_DIR=/ql
RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories \
&& apk update -f \
&& apk upgrade \
@@ -17,21 +17,22 @@ RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories
make \
g++ \
yarn \
&& git clone -b ${JD_BASE_BRANCH} ${JD_BASE_URL} ${JD_DIR} \
&& cd ${JD_DIR} \
&& git clone -b ${QL_BASE_BRANCH} ${QL_BASE_URL} ${QL_DIR} \
&& cd ${QL_DIR} \
&& cp -f .env.example .env \
&& yarn --network-timeout 100000
FROM node:lts-alpine
LABEL maintainer="whyour"
ARG JD_BASE_URL=https://github.com.cnpmjs.org/whyour/qinglong
ARG JD_BASE_BRANCH=master
ARG JD_SCRIPTS_URL=https://github.com.cnpmjs.org/RikudouPatrickstar/jd_scripts
ARG JD_SCRIPTS_BRANCH=master
ARG QL_BASE_URL=https://github.com.cnpmjs.org/whyour/qinglong
ARG QL_BASE_BRANCH=master
ARG QL_SCRIPTS_URL=https://github.com.cnpmjs.org/RikudouPatrickstar/QL_scripts
ARG QL_SCRIPTS_BRANCH=master
ENV PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin \
LANG=zh_CN.UTF-8 \
SHELL=/bin/bash \
PS1="\u@\h:\w \$ " \
JD_DIR=/jd
QL_DIR=/ql
WORKDIR ${QL_DIR}
RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories \
&& apk update -f \
&& apk upgrade \
@@ -55,24 +56,26 @@ RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories
&& echo "Asia/Shanghai" > /etc/timezone \
&& touch ~/.bashrc \
&& mkdir /run/nginx \
&& git clone -b ${JD_BASE_BRANCH} ${JD_BASE_URL} ${JD_DIR} \
&& cd ${JD_DIR} \
&& git clone -b ${QL_BASE_BRANCH} ${QL_BASE_URL} ${QL_DIR} \
&& cd ${QL_DIR} \
&& cp -f .env.example .env \
&& ln -sf ${JD_DIR}/shell/jd.sh /usr/local/bin/jd \
&& ln -sf ${JD_DIR}/shell/git_pull.sh /usr/local/bin/git_pull \
&& ln -sf ${JD_DIR}/shell/rm_log.sh /usr/local/bin/rm_log \
&& ln -sf ${JD_DIR}/shell/export_sharecodes.sh /usr/local/bin/export_sharecodes \
&& ln -sf ${JD_DIR}/shell/git_diy.sh /usr/local/bin/diy \
&& ln -sf ${JD_DIR}/shell/notify.sh /usr/local/bin/notify \
&& ln -sf ${JD_DIR}/shell/rebuild.sh /usr/local/bin/rebuild
COPY --from=build /jd/node_modules /jd/node_modules/
RUN cd ${JD_DIR} \
&& ln -sf ${QL_DIR}/shell/js.sh /usr/local/bin/js \
&& ln -sf ${QL_DIR}/shell/git_pull.sh /usr/local/bin/git_pull \
&& ln -sf ${QL_DIR}/shell/rm_log.sh /usr/local/bin/rm_log \
&& ln -sf ${QL_DIR}/shell/export_sharecodes.sh /usr/local/bin/export_sharecodes \
&& ln -sf ${QL_DIR}/shell/git_diy.sh /usr/local/bin/diy \
&& ln -sf ${QL_DIR}/shell/notify.sh /usr/local/bin/notify \
&& ln -sf ${QL_DIR}/shell/rebuild.sh /usr/local/bin/rebuild
&& cp -f $QL_DIR/docker/docker-entrypoint.sh /usr/local/bin/docker-entrypoint.sh \
&& chmod 777 /usr/local/bin/docker-entrypoint.sh \
&& chmod 777 $QL_DIR/shell/*.sh \
COPY --from=build /ql/node_modules /ql/node_modules/
RUN cd ${QL_DIR} \
&& yarn build \
&& yarn build-back \
&& git clone -b ${JD_SCRIPTS_BRANCH} ${JD_SCRIPTS_URL} ${JD_DIR}/scripts \
&& cd ${JD_DIR}/scripts \
&& git clone -b ${QL_SCRIPTS_BRANCH} ${QL_SCRIPTS_URL} ${QL_DIR}/scripts \
&& cd ${QL_DIR}/scripts \
&& npm install \
&& npm install -g pm2 \
&& rm -rf /root/.npm
WORKDIR ${JD_DIR}
ENTRYPOINT bash ${JD_DIR}/docker/docker-entrypoint.sh
ENTRYPOINT ["docker-entrypoint.sh"]
+18 -18
View File
@@ -2,34 +2,34 @@
set -e
echo -e "======================1. 检测配置文件========================\n"
[ ! -d ${JD_DIR}/config ] && mkdir -p ${JD_DIR}/config
[ ! -d ${QL_DIR}/config ] && mkdir -p ${QL_DIR}/config
if [ ! -s ${JD_DIR}/config/crontab.list ]
if [ ! -s ${QL_DIR}/config/crontab.list ]
then
echo -e "检测到config配置目录下不存在crontab.list或存在但文件为空,从示例文件复制一份用于初始化...\n"
cp -fv ${JD_DIR}/sample/crontab.list.sample ${JD_DIR}/config/crontab.list
sed -i "s,MY_PATH,${JD_DIR},g" ${JD_DIR}/config/crontab.list
sed -i "s,ENV_PATH=,PATH=$PATH,g" ${JD_DIR}/config/crontab.list
cp -fv ${QL_DIR}/sample/crontab.list.sample ${QL_DIR}/config/crontab.list
sed -i "s,MY_PATH,${QL_DIR},g" ${QL_DIR}/config/crontab.list
sed -i "s,ENV_PATH=,PATH=$PATH,g" ${QL_DIR}/config/crontab.list
fi
crond
crontab ${JD_DIR}/config/crontab.list
crontab ${QL_DIR}/config/crontab.list
echo -e "成功添加定时任务...\n"
if [ ! -s ${JD_DIR}/config/cookie.sh ]; then
if [ ! -s ${QL_DIR}/config/cookie.sh ]; then
echo -e "检测到config配置目录下不存在config.sh,从示例文件复制一份用于初始化...\n"
touch ${JD_DIR}/config/cookie.sh
touch ${QL_DIR}/config/cookie.sh
echo
fi
if [ ! -s ${JD_DIR}/config/config.sh ]; then
if [ ! -s ${QL_DIR}/config/config.sh ]; then
echo -e "检测到config配置目录下不存在config.sh,从示例文件复制一份用于初始化...\n"
cp -fv ${JD_DIR}/sample/config.sh.sample ${JD_DIR}/config/config.sh
cp -fv ${QL_DIR}/sample/config.sh.sample ${QL_DIR}/config/config.sh
echo
fi
if [ ! -s ${JD_DIR}/config/auth.json ]; then
if [ ! -s ${QL_DIR}/config/auth.json ]; then
echo -e "检测到config配置目录下不存在auth.json,从示例文件复制一份用于初始化...\n"
cp -fv ${JD_DIR}/sample/auth.json ${JD_DIR}/config/auth.json
cp -fv ${QL_DIR}/sample/auth.json ${QL_DIR}/config/auth.json
echo
fi
@@ -39,29 +39,29 @@ if [ -s /etc/nginx/conf.d/default.conf ]; then
echo
fi
cp -fv ${JD_DIR}/docker/front.conf /etc/nginx/conf.d/front.conf
cp -fv ${QL_DIR}/docker/front.conf /etc/nginx/conf.d/front.conf
echo -e "======================2. 启动nginx========================\n"
nginx -c /etc/nginx/nginx.conf
echo
echo -e "======================3. 更新源代码========================\n"
bash ${JD_DIR}/shell/git_pull.sh
git_pull
echo
echo -e "======================4. 启动挂机程序========================\n"
CookieConf=${JD_DIR}/config/cookie.sh
. ${JD_DIR}/config/config.sh
CookieConf=${QL_DIR}/config/cookie.sh
. ${QL_DIR}/config/config.sh
. ${CookieConf}
if [ -s ${CookieConf} ]; then
bash ${JD_DIR}/shell/jd.sh hangup 2>/dev/null
js hangup 2>/dev/null
echo -e "挂机程序启动成功...\n"
else
echo -e "尚未在Cookie管理中添加一条Cookie,可能是首次部署容器,因此不启动挂机程序...\n"
fi
echo -e "======================5. 启动控制面板========================\n"
pm2 start ${JD_DIR}/build/app.js -n panel
pm2 start ${QL_DIR}/build/app.js -n panel
echo -e "控制面板启动成功...\n"
echo -e "\n容器启动成功...\n"
+1 -1
View File
@@ -4,7 +4,7 @@ upstream api {
server {
listen 5700;
root /jd/dist;
root /ql/dist;
ssl_session_timeout 5m;
location /api {