This project uses NodeJS to listen to Github Push Events.
Each time something is pushed on bblfr_data, this NodeJS application:
- fetch https://github.com/brownbaglunch/bblfr_data/blob/gh-pages/baggers.js
- split
datainbaggersandcities - enrich
baggers.citieswith geo location point and image of the associated city - index
baggersandcitiesin elasticsearch. The index name is timestamped. - move or create alias
bblfron the index name - remove the old index
Data are available in elasticsearch:
To run it, you need to have Node JS installed.
git clone https://github.com/brownbaglunch/webhook.git
cd webhook
npm install
node app.js It should says:
Brownbaglunch webhook app listening at http://:::5000
elasticsearch cluster is running!
Then just POST to http://localhost:5000:
curl -XPOST localhost:5000If you want to push to another cluster, you need to create a local .env file as follow:
SOURCE=https://raw.githubusercontent.com/brownbaglunch/bblfr_data/gh-pages/baggers.js
TARGET=https://username:[email protected]:9243/
ALIAS=bblfr
TOKEN=hhdquiHdsuqiudshqhiudhuebefbbcbzbczib
PORT=5000TOKEN value is the one you defined in Github Hooks.
It can be null (default) in development mode.
If you want to change network settings, change PORT system variables or change it in .env file:
PORT=9000 node app.jsBy default, it will listen on 0.0.0.0, port 5000.
NodeMon is recommended when you want to code:
npm install nodemon -gTo monitor and restart your application automatically, run:
nodemon app.jsConnect to your Clever-cloud console. Create your NodeJS application and define your variables:
SOURCE=https://raw.githubusercontent.com/brownbaglunch/bblfr_data/gh-pages/baggers.js
TARGET=http://bblfr:password@localhost:9200
ALIAS=bblfr
TOKEN=12345678
PORT=8080Note that PORT must be 8080.
Add clever as a git remote repository (change ID below):
git remote add clever git+ssh://[email protected]/app_ID.git
Deploy!
git push -u clever masterEt voilà!
You need to use the Heroku CLI:
brew install herokuLog in to Heroku:
heroku loginTo deploy on Heroku, create the Heroku application. It will basically create an Heroku application and add an "heroku" remote to your local git repository:
heroku create brownbaglunch-webhookTo deploy, run:
git add .
git push heroku masterMake sure you define needed system properties:
heroku config:set SOURCE=https://raw.githubusercontent.com/brownbaglunch/bblfr_data/gh-pages/baggers.js
heroku config:set TARGET=http://bblfr:password@localhost:9200
heroku config:set ALIAS=bblfr
heroku config:set TOKEN=12345678
heroku config:set PORT=5000When running in production, you can use forever to run it as a service.
sudo npm -g install forever
sudo npm install -g forever-service
git clone https://github.com/brownbaglunch/webhook.git
cd webhook
npm install
# This will install webhook as a service
sudo forever-service install -e "PORT=5000" webhookAnd start it:
sudo service webhook startOr stop it:
sudo service webhook stopTo check if it's running:
sudo service webhook statusYou can also check logs:
tail -f /var/log/webhook.log