Parcourir la source

Fixed webhook script and docker port

rigwild il y a 5 ans
Parent
commit
69e8a47a76
2 fichiers modifiés avec 10 ajouts et 2 suppressions
  1. 1 1
      docker-compose.yml
  2. 9 1
      webhook_deploy_gogs.js

+ 1 - 1
docker-compose.yml

@@ -12,7 +12,7 @@ services:
       environment:
           NODE_ENV: production
           SERVE_CLIENT: "${SERVE_CLIENT:-true}"
-          PORT: "${PORT:-5000}"
+          PORT: "5000"
       volumes:
           - "${IMAGES_PATH:-./images}:/usr/src/app/images"
           - "./logs:/usr/src/app/logs"

+ 9 - 1
webhook_deploy_gogs.js

@@ -25,6 +25,12 @@ const exec = promisify(require('child_process').exec)
 // The port which this script will listen on
 const port = parseInt(process.env.WEBHOOK_PORT, 10)
 
+// Check the "WEBHOOK_PORT" environment variable is set to a valid integer
+if (!process.env.WEBHOOK_PORT || !parseInt(process.env.WEBHOOK_PORT, 10)) {
+  console.error(`${new Date().toLocaleString()} - The "WEBHOOK_PORT" environment variable is not set or is not an integer.`)
+  process.exit(1)
+}
+
 // The path to the project directory
 const projectPath = path.resolve('.')
 
@@ -66,13 +72,14 @@ let env = {
   IMAGES_PATH: process.env.IMAGES_PATH
 }
 env = Object.assign(process.env, env)
+if (!env.IMAGES_PATH) env.IMAGES_PATH = ''
 
 // Recap used environment variables
 Object.keys(env).forEach(x => console.log(`${x}=${env[x]}`))
 
 // The script that will be executed by the machine
 const deployScript = `cd ${projectPath}` +
-  ' && git reset --hard HEAD' +
+  // ' && git reset --hard HEAD' +
   ' && git pull origin master' +
   ' && docker-compose down' +
   ' && docker-compose build' +
@@ -106,6 +113,7 @@ const deploy = async () => {
   }
 }
 
+
 // Configuration is fine, start the server
 http.createServer((req, res) => {
   // Check the method is POST