problem description
the problems encountered in automating Web site deployment using Github"s webhooks are described in detail below.
reference article: automate website deployment using Github"s webhooks | Aotu.io" Bump Lab "
related codes
my automation script:
echo `date`
SITE_PATH = "****"
cd $SITE_PATH
echo start pull from github
git reset --hard origin/master
git clean -f
git pull
git checkout master
echo start build..
jekyll build --destination=/usr/share/nginx/html
using github-webhook-handler
, create the service main entry .js
file:
var http = require("http");
var createHandler = require("github-webhook-handler");
var handler = createHandler({ path: "/webhook", secret: "*******" });
function run_cmd(cmd, args, callback) {
var spawn = require("child_process").spawn;
var child = spawn(cmd, args);
var resp = "";
child.stdout.on("data", function(buffer) { resp += buffer.toString(); });
child.stdout.on("end", function() { callback (resp) });
}
http.createServer(function (req, res) {
handler(req, res, function (err) {
res.statusCode = 404
res.end("no such location")
})
}).listen(3001)
handler.on("error", function (err) {
console.error("Error:", err.message)
})
handler.on("push", function (event) {
console.log("Received a push event for %s to %s",
event.payload.repository.name,
event.payload.ref);
run_cmd("sh", ["./start_blog.sh"], function(text){ console.log(text) });
})
and run successfully using forever start * .js
.
after examination, there should be no problem with the first two.
reverse proxy in Nginx:
server {
listen 80 ;
server_name <mydomain>.com;
location = /webhook {
proxy_pass http://127.0.0.1:3001/webhook;
}
return 301 https://www.<mydomain>.com$request_uri;
}
server {
listen 443;
server_name <mydomain>.com;
return 301 https://www.<mydomain>.com$request_uri;
}
server {
listen 443 default_server ssl;
server_name www.<mydomain>.com;
-sharp
return 301 https://www.<mydomain>.com$request_uri;
}
Port 3001 is open:
tcp 0 0 :::3001 :::* LISTEN 31061/node
Webhook settings
Deliver :
:
so there may be a problem with the redirect. Is there an error in the Nginx agent configuration?
question is relatively long, thank you for your patience to read here, hope to give some advice.