From 0ce1fc1d2de655b42fe0b14995fc2cfb87842372 Mon Sep 17 00:00:00 2001 From: "cn.yimian.xyz" Date: Fri, 19 Jun 2020 12:16:16 +0800 Subject: [PATCH] docker --- Dockerfile | 16 ++++++++++++++++ pm2.json | 11 +++++++++++ index.js => src/index.js | 4 ++-- startup.sh => src/startup.sh | 0 4 files changed, 29 insertions(+), 2 deletions(-) create mode 100644 Dockerfile create mode 100644 pm2.json rename index.js => src/index.js (95%) rename startup.sh => src/startup.sh (100%) diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..a3c33ac --- /dev/null +++ b/Dockerfile @@ -0,0 +1,16 @@ +FROM keymetrics/pm2:latest-alpine + +# Bundle APP files +COPY src src/ +COPY package.json . +COPY pm2.json . + +# Install app dependencies +ENV NPM_CONFIG_LOGLEVEL warn +RUN npm install --production +RUN pm2 install pm2-auto-pull + +# Show current folder structure in logs +RUN ls -al -R + +CMD [ "pm2-runtime", "start", "pm2.json" ] diff --git a/pm2.json b/pm2.json new file mode 100644 index 0000000..ab4ac16 --- /dev/null +++ b/pm2.json @@ -0,0 +1,11 @@ +{ + "name": "acg.watch-api", + "script": "src/index.js", + "instances": "2", + "env": { + "NODE_ENV": "development" + }, + "env_production" : { + "NODE_ENV": "production" + } +} diff --git a/index.js b/src/index.js similarity index 95% rename from index.js rename to src/index.js index ef5e0cd..8ebc08f 100644 --- a/index.js +++ b/src/index.js @@ -57,7 +57,7 @@ var video = { danmakuID: '40404040', 'class': 'extra' }, - getAll: () => JSON.parse(fs.readFileSync(__dirname+'/../cache/video.json')), + getAll: () => JSON.parse(fs.readFileSync('mnt/cache/video/video.json')), getClassBySeries: series => new Promise((resolve, reject) => { Object.keys(video.obj).forEach(item => { if(video.obj[item].hasOwnProperty(series)){ @@ -109,5 +109,5 @@ var video = { /* watch video.json cache */ video.reload(); -fs.watch(__dirname+'/../cache/', event => video.reload()); +fs.watch('/mnt/cache/video/', event => video.reload()); diff --git a/startup.sh b/src/startup.sh similarity index 100% rename from startup.sh rename to src/startup.sh