idleman 1 年間 前
コミット
3dbadc8548
3 ファイル変更55 行追加0 行削除
  1. 9 0
      app/Dockerfile
  2. 2 0
      app/run.bat
  3. 44 0
      app/start.js

+ 9 - 0
app/Dockerfile

@@ -0,0 +1,9 @@
+FROM node:latest
+LABEL description="A demo Dockerfile for build Docsify."
+RUN apt update
+RUN apt install cron nano git -y
+WORKDIR /rdoc
+RUN npm install -g docsify-cli@latest
+EXPOSE 3000/tcp
+COPY start.js /rdoc/start.js
+ENTRYPOINT node start.js

+ 2 - 0
app/run.bat

@@ -0,0 +1,2 @@
+docker build -t rdoc .
+docker run -p 3000:3000 -p 35729:35729 -e REFRESH_DELAY=1 -e REPOSITORY_URL=https://git.idleman.fr/idleman/doc.git rdoc

+ 44 - 0
app/start.js

@@ -0,0 +1,44 @@
+const { exec,execSync  } = require('child_process');
+
+let refreshDelay = 60;
+
+if(process.env.REFRESH_DELAY) refreshDelay = process.env.REFRESH_DELAY;
+
+if(!process.env.REPOSITORY_URL) throw "Env var GIT_REPOSITORY must be a valid repository url";
+
+let cloneUrl = process.env.REPOSITORY_URL;
+if(process.env.REPOSITORY_TOKEN){
+	cloneUrl = cloneUrl.replace(/(.*:\/\/)(.*)/,'$1'+'myProject:'+process.env.REPOSITORY_TOKEN+'@$2');
+}
+
+console.log("starting program");
+console.log("refresh delay is ("+refreshDelay+"s)");
+
+console.log('Cloning doc repository: '+process.env.GIT_REPOSITORY);
+let stdout = execSync('cd /rdoc && git clone '+cloneUrl+" docs");
+console.log(stdout);
+
+setInterval(function() {
+    exec('cd /rdoc/docs && git reset --hard origin/master && git pull', (error, stdout, stderr) => {
+  if (error) {
+    console.error(`error: ${error}`);
+    return;
+  }
+  if(stdout.indexOf('Already up to date')!==-1) return;
+  console.log(`${stdout}`);
+  console.error(`${stderr}`);
+});
+}, refreshDelay * 1000);
+
+console.log("load docsify");
+
+exec('docsify serve /rdoc/docs', (error, stdout, stderr) => {
+  if (error) {
+    console.error(`error: ${error}`);
+    return;
+  }
+  console.log(` ${stdout}`);
+  console.error(`${stderr}`);
+});
+
+