From 9d5cdbf3a653c1c8d30fea8a3f1f8bf91480b772 Mon Sep 17 00:00:00 2001 From: fanxb Date: Tue, 7 Dec 2021 10:17:18 -0500 Subject: [PATCH] =?UTF-8?q?deploy:=E4=BF=AE=E6=94=B9=E6=89=93=E5=8C=85?= =?UTF-8?q?=E8=84=9A=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 4 +++- Dockerfile | 1 - build.sh | 13 +++++++++++++ openRenamerBackend/util/SqliteHelper.ts | 10 +++++++--- 4 files changed, 23 insertions(+), 5 deletions(-) create mode 100644 build.sh diff --git a/.gitignore b/.gitignore index d6dd4f5..35fc111 100644 --- a/.gitignore +++ b/.gitignore @@ -101,4 +101,6 @@ dist .dynamodb/ # TernJS port file -.tern-port \ No newline at end of file +.tern-port + +data \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index dc6afc7..d5eeda3 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,7 +1,6 @@ FROM node:lts-buster-slim WORKDIR /app copy ./openRenamerBackend /app -RUN rm /app/sqls/* && chmod 777 /app/sqls ENV PORT 80 CMD ["/usr/local/bin/node", "dist/index.js"] diff --git a/build.sh b/build.sh new file mode 100644 index 0000000..68d9810 --- /dev/null +++ b/build.sh @@ -0,0 +1,13 @@ +#!/bin/bash +base=$(cd "$(dirname "$0")";pwd) +cd $base +docker run -it --rm --name buildOpenRenamer --user ${UID} -v $base/openRenamerFront:/opt/front node:lts-buster-slim bash -c "cd /opt/front && yarn --registry https://registry.npm.taobao.org && yarn build" + +rm -rf openRenamerBackend/static/* +touch openRenamerBackend/static/.gitkeep +mv openRenamerFront/dist/* openRenamerBackend/static + +docker run -it --rm --name buildOpenRenamer --user ${UID} -v $base/openRenamerBackend:/opt/backend node:lts-buster-slim bash -c "cd /opt/backend && yarn config set registry https://registry.npm.taobao.org && yarn global add typescript && yarn && tsc" + +# docker镜像打包 +# docker build -t fleyx:open-renamer:0.3 . \ No newline at end of file diff --git a/openRenamerBackend/util/SqliteHelper.ts b/openRenamerBackend/util/SqliteHelper.ts index 57e529d..d2e399d 100644 --- a/openRenamerBackend/util/SqliteHelper.ts +++ b/openRenamerBackend/util/SqliteHelper.ts @@ -12,12 +12,16 @@ class SqliteHelper { public static pool: Database = null; static async createPool() { + let dataFolder = path.join(config.rootPath, "data"); + if (!fs.existsSync(dataFolder)) { + fs.mkdir(dataFolder); + } SqliteHelper.pool = await open({ - filename: path.join(config.rootPath, "database.db"), + filename: path.join(dataFolder, "database.db"), driver: sqlite3.Database }); let basePath = path.join(config.rootPath, "sqls"); - let hisPath = path.join(basePath, HISTORY_NAME); + let hisPath = path.join(dataFolder, HISTORY_NAME); let history: Array; if (fs.existsSync(hisPath)) { history = JSON.parse(await fs.readFile(hisPath, "utf-8")); @@ -32,7 +36,7 @@ class SqliteHelper { log.info("sql无需重复执行:", files[i]); continue; } - let sqlLines = (await fs.readFile(path.join(basePath, files[i]), 'utf-8')).split(/[\r\n]/g).map(item=>item.trim()).filter(item=>!item.startsWith("--")); + let sqlLines = (await fs.readFile(path.join(basePath, files[i]), 'utf-8')).split(/[\r\n]/g).map(item => item.trim()).filter(item => !item.startsWith("--")); try { let sql = ""; for (let j = 0; j < sqlLines.length; j++) {