From 5f750affcdea4f2ee63fa73c053b7b8446016aae Mon Sep 17 00:00:00 2001 From: Vincent Fiduccia Date: Thu, 12 Jul 2018 15:03:23 -0700 Subject: [PATCH] Better leader check --- Dockerfile.algolia | 3 --- gulpfile.babel.js | 50 +++++++++++++++++++++++++--------------------- package.json | 1 + 3 files changed, 28 insertions(+), 26 deletions(-) diff --git a/Dockerfile.algolia b/Dockerfile.algolia index 9212eafcc24..3107ac79636 100644 --- a/Dockerfile.algolia +++ b/Dockerfile.algolia @@ -3,9 +3,6 @@ FROM rancher/docs:build VOLUME /usr/share/nginx/html/docs WORKDIR /run -ADD https://github.com/rancher/giddyup/releases/download/v0.19.0/giddyup /usr/bin/giddyup -RUN chmod +x /usr/bin/giddyup - COPY gulpfile.babel.js /run/ ENTRYPOINT ["gulp"] diff --git a/gulpfile.babel.js b/gulpfile.babel.js index 1bad647a806..8d9afd90d9f 100644 --- a/gulpfile.babel.js +++ b/gulpfile.babel.js @@ -17,6 +17,7 @@ const fs = require('fs'); const $ = gulpLoadPlugins(); const browserSync = require('browser-sync').create(); +const request = require('request'); const isProduction = process.env.NODE_ENV === 'production'; process.on('SIGINT', (err) => { @@ -29,10 +30,6 @@ process.on('uncaughtException', (err) => { process.exit(1); }); -console.log('&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&') -console.log(process.env) -console.log('&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&') - // -- gulp.task('dev', ['build-dev'], () => { gulp.start('init-watch'); @@ -194,26 +191,33 @@ gulp.task('publish:search-index', (cb) => { env: env }; + request.get({url: 'http://rancher-metadata/2015-07-25/self/service/containers/0', timeout: 2000}, function(err, res, first) { + if ( err ) { + return cb(err); + } - console.log('Waiting'); - setTimeout(() => { - console.log('Done'); - exec('giddyup leader check', opts, function(err, stdout, stderr) { - console.log('Error:', err); - console.log('Stdout:', stdout); - console.log('Stderr:', stderr); - }).on('close', code => { - if (code === 0) { - console.log('Publishing to algolia', process.env.ALGOLIA_INDEX_NAME); - atomicalgolia(process.env.ALGOLIA_INDEX_NAME, process.env.ALGOLIA_INDEX_FILE, {verbose: true}, (err, result) => { - console.log(result); - cb(err); - }); - } else { - console.log('I am not the leader (' + code + ')'); - cb(new Error('Not the leader')); + request.get({url: 'http://rancher-metadata/2015-07-25/self/container/name', timeout: 2000}, function(err, res, me) { + if ( err ) { + return cb(err); } - }); - }, 10000); + console.log('First:', first); + console.log('Me:', me); + + if ( !first || !me ) { + return cb(new Error('Unable to determine who is the leader (' + first + ', ' + me+ ')')); + } + + if ( first !== me ) { + console.log('I am not the leader'); + return cb(); + } + + console.log('Publishing to algolia', process.env.ALGOLIA_INDEX_NAME); + atomicalgolia(process.env.ALGOLIA_INDEX_NAME, process.env.ALGOLIA_INDEX_FILE, {verbose: true}, (err, result) => { + console.log(result); + cb(err); + }); + }); + }); }); diff --git a/package.json b/package.json index 6ef83f75291..7347d0ea7ed 100644 --- a/package.json +++ b/package.json @@ -38,6 +38,7 @@ "moment": "^2.20.1", "node-sass-tilde-importer": "^1.0.0", "rancher-website-theme": "https://github.com/rancherlabs/website-theme.git", + "request": "^2.87.0", "run-sequence": "^2.0.0", "vinyl-buffer": "^1.0.1", "vinyl-source-stream": "^2.0.0"