Skip to content

Commit ace0723

Browse files
committed
fix(openshift): fix issues with openshift deployment
app is now restarted after being created openshift is used as the remote name git push exceeding buffer size causing exec to fail
1 parent 4485223 commit ace0723

File tree

1 file changed

+63
-49
lines changed

1 file changed

+63
-49
lines changed

Diff for: openshift/index.js

+63-49
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
'use strict';
22
var util = require('util');
33
var yeoman = require('yeoman-generator');
4-
var exec = require('child_process').exec;
4+
var childProcess = require('child_process');
55
var chalk = require('chalk');
66
var path = require('path');
7+
var exec = childProcess.exec;
8+
var spawn = childProcess.spawn;
79

810
var Generator = module.exports = function Generator() {
911
yeoman.generators.Base.apply(this, arguments);
@@ -66,14 +68,14 @@ Generator.prototype.gitRemoteCheck = function gitRemoteCheck() {
6668
if(this.abort || typeof this.dist_repo_url !== 'undefined') return;
6769
var done = this.async();
6870

69-
this.log(chalk.bold("\nChecking for an existing git remote named '"+this.deployedName+"'..."));
71+
this.log(chalk.bold("\nChecking for an existing git remote named '"+'openshift'+"'..."));
7072
exec('git remote -v', { cwd: 'dist' }, function (err, stdout, stderr) {
7173
var lines = stdout.split('\n');
7274
var dist_repo = '';
7375
if (err && stderr.search('DL is deprecated') === -1) {
7476
this.log.error(err);
7577
} else {
76-
var repo_url_finder = new RegExp(this.deployedName+"[ ]*");
78+
var repo_url_finder = new RegExp('openshift'+"[ ]*");
7779
lines.forEach(function(line) {
7880
if(line.search(repo_url_finder) === 0 && dist_repo === '') {
7981
var dist_repo_detailed = line.slice(line.match(repo_url_finder)[0].length);
@@ -166,7 +168,7 @@ Generator.prototype.gitRemoteAdd = function gitRemoteAdd() {
166168
var done = this.async();
167169
this.log(chalk.bold("\nAdding remote repo url: "+this.dist_repo_url));
168170

169-
var child = exec('git remote add '+this.deployedName+' '+this.dist_repo_url, { cwd: 'dist' }, function (err, stdout, stderr) {
171+
var child = exec('git remote add '+'openshift'+' '+this.dist_repo_url, { cwd: 'dist' }, function (err, stdout, stderr) {
170172
if (err) {
171173
this.log.error(err);
172174
} else {
@@ -229,58 +231,70 @@ Generator.prototype.gitCommit = function gitInit() {
229231
};
230232

231233
Generator.prototype.gitForcePush = function gitForcePush() {
232-
if(this.abort || !this.openshift_remote_exists ) return;
234+
if (this.abort || !this.openshift_remote_exists) return;
233235
var done = this.async();
234-
this.log(chalk.bold("\nUploading your initial application code.\n This may take "+chalk.cyan('several minutes')+" depending on your connection speed..."));
236+
this.log(chalk.bold("\nUploading your initial application code.\n This may take " + chalk.cyan('several minutes') + " depending on your connection speed..."));
235237

236-
var child = exec('git push -f '+this.deployedName+' master', { cwd: 'dist' }, function (err, stdout, stderr) {
237-
if (err) {
238-
this.log.error(err);
239-
} else {
240-
var host_url = '';
241-
var hasWarning = false;
242-
var before_hostname = this.dist_repo_url.indexOf('@') + 1;
243-
var after_hostname = this.dist_repo_url.length - ( this.deployedName.length + 12 );
244-
host_url = 'http://' + this.dist_repo_url.slice(before_hostname, after_hostname);
245-
246-
if(this.filters.socketio) {
247-
this.log(chalk.yellow('Openshift websockets use port 8000, you will need to update the client to connect to the correct port for sockets to work.\n\t' + 'in `/client/app/components/socket/socket.service`: ' + chalk.bold('var ioSocket = io.connect(\'' + host_url + ':8000' + '\')' + '\n')));
248-
hasWarning = true;
249-
}
238+
var push = spawn('git', ['push', '-f', 'openshift', 'master'], {cwd: 'dist'});
239+
var error = null;
250240

251-
if(this.filters.facebookAuth) {
252-
this.log(chalk.yellow('You will need to set environment variables for facebook auth:\n\t' +
253-
chalk.bold('rhc set-env FACEBOOK_ID=id -a ' + this.deployedName + '\n\t') +
254-
chalk.bold('rhc set-env FACEBOOK_SECRET=secret -a ' + this.deployedName + '\n')));
255-
hasWarning = true;
256-
}
257-
if(this.filters.googleAuth) {
258-
this.log(chalk.yellow('You will need to set environment variables for google auth:\n\t' +
259-
chalk.bold('rhc set-env GOOGLE_ID=id -a ' + this.deployedName + '\n\t') +
260-
chalk.bold('rhc set-env GOOGLE_SECRET=secret -a ' + this.deployedName + '\n')));
261-
hasWarning = true;
262-
}
263-
if(this.filters.twitterAuth) {
264-
this.log(chalk.yellow('You will need to set environment variables for twitter auth:\n\t' +
265-
chalk.bold('rhc set-env TWITTER_ID=id -a ' + this.deployedName + '\n\t') +
266-
chalk.bold('rhc set-env TWITTER_SECRET=secret -a ' + this.deployedName + '\n')));
267-
hasWarning = true;
268-
}
241+
push.stderr.on('data', function (data) {
242+
var output = data.toString();
243+
this.log.error(output);
244+
}.bind(this));
269245

270-
this.log(chalk.green('\nYour app should now be live at \n\t' + chalk.bold(host_url)));
271-
if(hasWarning) {
272-
this.log(chalk.green('\nYou may need to address the issues mentioned above and restart the server for the app to work correctly \n\t' +
273-
'rhc app-restart -a ' + this.deployedName));
274-
}
275-
this.log(chalk.yellow('After app modification run\n\t' + chalk.bold('grunt build') +
276-
'\nThen enter the dist folder to commit these updates:\n\t' + chalk.bold('cd dist && git add -A && git commit -m "describe your changes here"')));
277-
this.log(chalk.green('Finally, deploy your updated build to OpenShift with\n\t' + chalk.bold('git push -f '+this.deployedName+' master')));
246+
push.stdout.on('data', function (data) {
247+
var output = data.toString();
248+
this.log.stdin(output);
249+
}.bind(this));
250+
251+
push.on('exit', function (code) {
252+
if (code !== 0) {
253+
this.abort = true;
254+
return done();
278255
}
279256
done();
280257
}.bind(this));
258+
};
281259

282-
child.stdout.on('data', function(data) {
283-
var output = data.toString();
284-
this.log(output);
260+
Generator.prototype.restartApp = function restartApp() {
261+
if(this.abort || !this.openshift_remote_exists ) return;
262+
this.log(chalk.bold("\nRestarting your openshift app.\n"));
263+
264+
var child = exec('rhc app restart -a ' + this.deployedName, function(err, stdout, stderr) {
265+
266+
var host_url = '';
267+
var hasWarning = false;
268+
var before_hostname = this.dist_repo_url.indexOf('@') + 1;
269+
var after_hostname = this.dist_repo_url.length - ( 'openshift'.length + 12 );
270+
host_url = 'http://' + this.dist_repo_url.slice(before_hostname, after_hostname);
271+
272+
if(this.filters.facebookAuth) {
273+
this.log(chalk.yellow('You will need to set environment variables for facebook auth:\n\t' +
274+
chalk.bold('rhc set-env FACEBOOK_ID=id -a ' + this.deployedName + '\n\t') +
275+
chalk.bold('rhc set-env FACEBOOK_SECRET=secret -a ' + this.deployedName + '\n')));
276+
hasWarning = true;
277+
}
278+
if(this.filters.googleAuth) {
279+
this.log(chalk.yellow('You will need to set environment variables for google auth:\n\t' +
280+
chalk.bold('rhc set-env GOOGLE_ID=id -a ' + this.deployedName + '\n\t') +
281+
chalk.bold('rhc set-env GOOGLE_SECRET=secret -a ' + this.deployedName + '\n')));
282+
hasWarning = true;
283+
}
284+
if(this.filters.twitterAuth) {
285+
this.log(chalk.yellow('You will need to set environment variables for twitter auth:\n\t' +
286+
chalk.bold('rhc set-env TWITTER_ID=id -a ' + this.deployedName + '\n\t') +
287+
chalk.bold('rhc set-env TWITTER_SECRET=secret -a ' + this.deployedName + '\n')));
288+
hasWarning = true;
289+
}
290+
291+
this.log(chalk.green('\nYour app should now be live at \n\t' + chalk.bold(host_url)));
292+
if(hasWarning) {
293+
this.log(chalk.green('\nYou may need to address the issues mentioned above and restart the server for the app to work correctly \n\t' +
294+
'rhc app-restart -a ' + this.deployedName));
295+
}
296+
this.log(chalk.yellow('After app modification run\n\t' + chalk.bold('grunt build') +
297+
'\nThen enter the dist folder to commit these updates:\n\t' + chalk.bold('cd dist && git add -A && git commit -m "describe your changes here"')));
298+
this.log(chalk.green('Finally, deploy your updated build to OpenShift with\n\t' + chalk.bold('git push -f '+'openshift'+' master')));
285299
}.bind(this));
286300
};

0 commit comments

Comments
 (0)