Adding setup page for usage diagnostics

This commit is contained in:
Jeff Morgan 2014-09-10 19:39:25 -07:00
parent c1907be3d2
commit 59e14fb883
27 changed files with 191 additions and 110 deletions

View File

@ -47,7 +47,7 @@ var start = function (callback) {
console.log('MongoDB: ' + mongoPort);
console.log('webPort: ' + webPort);
child_process.exec('kill $(ps aux -e | grep PURPOSE=KITEMATIC | awk \'{print $2}\') && rm ' + path.join(dataPath, 'mongod.lock'), function (error, stdout, stderr) {
var mongoChild = child_process.spawn(path.join(process.cwd(), 'resources', 'mongod'), ['--bind_ip', '127.0.0.1', '--dbpath', dataPath, '--port', mongoPort, '--unixSocketPrefix', dataPath], {
var mongoChild = child_process.spawn(path.join(__dirname, 'resources', 'mongod'), ['--bind_ip', '127.0.0.1', '--dbpath', dataPath, '--port', mongoPort, '--unixSocketPrefix', dataPath], {
env: {
PURPOSE: 'KITEMATIC'
}
@ -65,29 +65,16 @@ var start = function (callback) {
console.log('Starting node child...');
var rootURL = 'http://localhost:' + webPort;
var user_env = process.env;
user_env.ROOT_URL = rootURL;
user_env.PORT = webPort;
user_env.BIND_IP = '127.0.0.1';
user_env.DB_PATH = dataPath;
user_env.MONGO_URL = 'mongodb://localhost:' + mongoPort + '/meteor';
user_env.METEOR_SETTINGS = fs.readFileSync(path.join(process.cwd(), 'resources', 'settings.json'), 'utf8');
var nodeChild = child_process.spawn(path.join(process.cwd(), 'resources', 'node'), ['./bundle/main.js'], {
env: user_env
});
var opened = false;
nodeChild.stdout.setEncoding('utf8');
nodeChild.stdout.on('data', function (data) {
console.log(data);
if (data.indexOf('Kitematic started.') !== -1) {
if (!opened) {
opened = true;
} else {
return;
}
callback(rootURL, nodeChild, mongoChild);
}
});
process.env.ROOT_URL = rootURL;
process.env.PORT = webPort;
process.env.BIND_IP = '127.0.0.1';
process.env.DB_PATH = dataPath;
process.env.MONGO_URL = 'mongodb://localhost:' + mongoPort + '/meteor';
process.env.METEOR_SETTINGS = fs.readFileSync(path.join(__dirname, 'resources', 'settings.json'), 'utf8');
process.env.DIR = __dirname;
process.env.NODE_ENV = 'production';
process.env.NODE_PATH = path.join(__dirname, 'node_modules');
require('./bundle/main.js');
}
});
});
@ -128,5 +115,7 @@ app.on('ready', function() {
// and load the index.html of the app.
mainWindow.loadUrl(url);
mainWindow.show();
mainWindow.focus();
});
});

BIN
kitematic.icns Normal file

Binary file not shown.

View File

@ -7,7 +7,7 @@ Docker = {};
Docker.DOCKER_HOST = '192.168.60.103';
Docker.DEFAULT_IMAGES_FILENAME = 'base-images-0.0.2.tar.gz';
Docker.DEFAULT_IMAGES_CHECKSUM = '67e7c7562991a4208c90007461ec14bc184a52ad6048e6bed3e8a8c2b306cee7'; // Sha256 Checksum
Docker.DEFAULT_IMAGES_CHECKSUM = 'a3517ac21034a1969d9ff15e3c41b1e2f1aa83c67b16a8bd0bc378ffefaf573b'; // Sha256 Checksum
Docker.client = function () {
return new Dockerode({host: Docker.DOCKER_HOST, port: '2375'});

View File

@ -88,7 +88,9 @@ Installer.steps = [
callback('Boot2Docker SSH key doesn\'t exist. Fix by deleting the existing Boot2Docker VM and re-run the installer. This usually occurs because an old version of Boot2Docker is installed.');
} else {
Boot2Docker.stop(function(err) {
callback();
Boot2Docker.upgrade(function (err) {
callback(err);
});
});
}
}

View File

@ -13,14 +13,14 @@ Router.configure({
SetupController = RouteController.extend({
layoutTemplate: 'setup_layout',
waitOn: function () {
return [Meteor.subscribe('installs')];
return [Meteor.subscribe('installs'), Meteor.subscribe('settings')];
}
});
DashboardController = RouteController.extend({
layoutTemplate: 'dashboard_layout',
waitOn: function () {
return [Meteor.subscribe('apps'), Meteor.subscribe('images'), Meteor.subscribe('installs')];
return [Meteor.subscribe('apps'), Meteor.subscribe('images'), Meteor.subscribe('installs'), Meteor.subscribe('settings')];
}
});
@ -50,6 +50,11 @@ Router.map(function () {
controller: 'SetupController'
});
this.route('setup_finish', {
path: '/setup/finish',
controller: 'SetupController'
});
this.route('setup', {
path: '/',
controller: 'SetupController',
@ -58,12 +63,11 @@ Router.map(function () {
if (!Installer.isUpToDate()) {
if (!Installs.findOne()) {
console.log('No installs detected, running installer again.');
this.redirect('/setup/intro');
} else {
// There's an install but it's lower than the current version, re-run as an 'update'.
Session.set('isUpdating', true);
this.redirect('/setup/intro');
}
this.redirect('/setup/intro');
} else {
this.redirect('/apps');
}

View File

@ -1,7 +1,8 @@
var path = require('path');
var fs = require('fs');
var wget = require('wget');
var nodeCrypto = require('crypto');
var request = require('request');
var progress = require('request-progress');
Util = {};
@ -10,15 +11,7 @@ Util.getHomePath = function () {
};
Util.getBinDir = function () {
if (process.env.NODE_ENV === 'development') {
return path.join(path.join(process.env.PWD, '..'), 'resources');
} else {
if (Meteor.isClient) {
return path.join(process.cwd(), 'resources');
} else {
return path.join(process.cwd(), '../../../resources');
}
}
return path.join(process.env.DIR, 'resources');
};
Util.getResourceDir = function () {
@ -97,22 +90,16 @@ Util.openTerminal = function (command) {
Util.downloadFile = function (url, filename, checksum, callback, progressCallback) {
var doDownload = function () {
var percent = 0;
var interval = setInterval(function () {
progressCallback(percent);
}, 250);
var download = wget.download(url, filename);
download.on('error', function (err) {
console.log(err);
clearInterval(interval);
});
download.on('end', function (output) {
console.log(output);
callback();
clearInterval(interval);
});
download.on('progress', function (progress) {
percent = Math.round(progress * 100.0);
progress(request(url), {
throttle: 250,
}).on('progress', function (state) {
progressCallback(state.percent);
}).on('error', function (err) {
callback(err);
}).pipe(fs.createWriteStream(filename)).on('error', function (err) {
callback(err);
}).on('close', function (err) {
callback(err);
});
};

View File

@ -1,7 +1,6 @@
var fs = require('fs');
var exec = require('exec');
var path = require('path');
var crypto = require('crypto');
VirtualBox = {};

View File

@ -40,6 +40,25 @@
margin-top: 60px;
}
.install-finish {
-webkit-app-region: no-drag;
margin-top: 80px;
p {
margin-top: 0;
font-size: 13px;
}
}
.install-diagonistics {
-webkit-app-region: no-drag;
label {
text-align: left;
}
margin: 0 auto;
max-width: 300px;
margin-top: 50px;
}
.install-continue {
-webkit-app-region: no-drag;
margin-top: 140px;

View File

@ -1,5 +1,3 @@
var path = require('path');
Template.dashboard_apps_layout.rendered = function () {
Meteor.setInterval(function () {
$('.header .icons a').tooltip();
@ -26,7 +24,7 @@ Template.dashboard_apps_layout.events({
AppUtil.logs(this._id);
},
'click .btn-terminal': function () {
var cmd = Boot2Docker.command() + ' ssh -t "sudo docker-enter ' + app.docker.Id + '"';
var cmd = Boot2Docker.command() + ' ssh -t "sudo docker-enter ' + this.docker.Id + '"';
Util.openTerminal(cmd);
},
'click .btn-restart': function () {

View File

@ -41,14 +41,14 @@
</div>
<div class="section dashboard-settings">
<div class="left-section">
<h4>Usage Analytics</h4>
<p class="help-block">Send usage analytics to help us improve the developer experience. No sensitive data will be tracked. We really appreciate the help.</p>
<h4>Usage Diagnostics</h4>
<p class="help-block">Send anonymized usage diagnostics to help us improve Kitematic.</p>
</div>
<div class="right-section">
{{#if install.tracking}}
<a onclick="trackLink('turn off usage analytics')" class="btn btn-negative btn-usage-analytics-off">Turn Off Usage Analytics</a>
{{#if settings.tracking}}
<a onclick="trackLink('turn off usage analytics')" class="btn btn-negative btn-usage-analytics-off">Turn Off Usage Diagnostics</a>
{{else}}
<a onclick="trackLink('turn on usage analytics')" class="btn btn-positive btn-usage-analytics-on">Turn On Usage Analytics</a>
<a onclick="trackLink('turn on usage analytics')" class="btn btn-positive btn-usage-analytics-on">Turn On Usage Diagnostics</a>
{{/if}}
</div>
</div>

View File

@ -22,16 +22,16 @@ Template.dashboard_settings.events({
});
},
'click .btn-usage-analytics-on': function () {
var install = Installs.findOne({});
Installs.update(install._id, {
var settings = Settings.findOne();
Settings.update(settings._id, {
$set: {
tracking: true
}
});
},
'click .btn-usage-analytics-off': function () {
var install = Installs.findOne({});
Installs.update(install._id, {
var settings = Settings.findOne();
Settings.update(settings._id, {
$set: {
tracking: false
}
@ -40,8 +40,8 @@ Template.dashboard_settings.events({
});
Template.dashboard_settings.helpers({
install: function () {
return Installs.findOne({});
settings: function () {
return Settings.findOne({});
}
});

View File

@ -0,0 +1,21 @@
<template name="setup_finish">
<h2>Installation Complete</h2>
<div class="container text-center">
<div class="install_logo">
<img src="/install_finished.png">
</div>
<div class="install-diagonistics">
<div class="checkbox">
<label>
<input type="checkbox" checked> Enable anonymous usage diagnostics to help us improve Kitematic.
</label>
</div>
</div>
<div class="install-finish">
<a onclick="trackLink('finish install')" class="finish-button">
<img src="/continue.png">
<p>Finish</p>
</a>
</div>
</div>
</template>

View File

@ -0,0 +1,20 @@
Template.setup_finish.events({
'click .finish-button': function (e) {
var enableDiagnostics = $('.install-diagonistics input').attr('checked') ? true : false;
Installs.insert({version: Installer.CURRENT_VERSION});
var settings = Settings.findOne();
if (!settings) {
Settings.insert({tracking: enableDiagnostics});
} else {
settings.update(settings._id, {
$set: {
tracking: true
}
});
}
Router.go('dashboard_apps');
e.preventDefault();
e.stopPropagation();
return false;
}
});

View File

@ -1,4 +1,11 @@
<template name="setup_install">
{{#if isUpdating}}
<h2>Updating</h2>
<p>This may take a few minutes.</p>
{{else}}
<h2>Installing</h2>
<p>This may take a few minutes.</p>
{{/if}}
<div class="container text-left">
<div class="steps">
{{#each steps}}

View File

@ -7,8 +7,7 @@ Template.setup_install.rendered = function() {
console.log('Setup failed.');
console.log(err);
} else {
Installs.insert({version: Installer.CURRENT_VERSION});
Router.go('dashboard_apps');
Router.go('setup_finish');
}
});
}

View File

@ -1,4 +1,11 @@
<template name="setup_intro">
{{#if isUpdating}}
<h2>Welcome Back</h2>
<p>Kitematic needs to update itself to continue.</p>
{{else}}
<h2>Welcome to Kitematic</h2>
<p>This will set up everything needed to run Kitematic on your Mac.</p>
{{/if}}
<div class="container text-center">
<div class="install_logo">
<img src="/install_logo.png">

View File

@ -1,6 +1,5 @@
Template.setup_intro.events({
'click .continue-button': function (e) {
console.log('here');
Router.go('setup_install');
e.preventDefault();
e.stopPropagation();

View File

@ -1,13 +1,6 @@
<template name="setup_layout">
{{setTitle}}
<div class="setup content text-center">
{{#if isUpdating}}
<h2>Welcome Back</h2>
<p>Kitematic needs to update itself to continue.</p>
{{else}}
<h2>Welcome to Kitematic</h2>
<p>This will set up everything needed to run Kitematic on your Mac.</p>
{{/if}}
{{> yield}}
</div>
</template>

View File

@ -0,0 +1,13 @@
Settings = new Meteor.Collection('settings');
Settings.allow({
'update': function () {
return true;
},
'insert': function () {
return true;
},
'remove': function () {
return true;
}
});

Binary file not shown.

Before

Width:  |  Height:  |  Size: 857 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 23 KiB

View File

@ -9,3 +9,7 @@ Meteor.publish('images', function () {
Meteor.publish('installs', function () {
return Installs.find({});
});
Meteor.publish('settings', function () {
return Settings.find({});
});

View File

@ -11,6 +11,7 @@
"dockerode": "2.0.3",
"tar": "0.1.20",
"ansi-to-html": "0.2.0",
"wget": "0.0.1"
"request": "2.42.0",
"request-progress": "0.3.1"
}
}

View File

@ -6,6 +6,8 @@ source $DIR/colors.sh
BASE=$DIR/..
NPM="$BASE/cache/node/bin/npm"
NODE="$BASE/cache/node/bin/node"
VERSION=$($NODE -pe 'JSON.parse(process.argv[1]).version' "$(cat package.json)")
pushd $BASE/meteor
@ -28,51 +30,55 @@ popd
pushd $BASE
rm -rf dist/osx/Kitematic.app
rm -rf dist/osx/Kitematic.zip
rm -rf dist/osx
mkdir -p dist/osx/
cecho "-----> Creating Kitematic.app..." $blue
DIST_APP=Kitematic.app
cecho "-----> Creating $DIST_APP..." $blue
find cache/atom-shell -name "debug\.log" -print0 | xargs -0 rm -rf
cp -R cache/atom-shell/Atom.app dist/osx/
mv dist/osx/Atom.app dist/osx/Kitematic.app
mkdir -p dist/osx/Kitematic.app/Contents/Resources/app
mv dist/osx/Atom.app dist/osx/$DIST_APP
mkdir -p dist/osx/$DIST_APP/Contents/Resources/app
cecho "-----> Copying meteor bundle into Kitematic.app..." $blue
cp -R bundle dist/osx/Kitematic.app/Contents/Resources/app/
cecho "-----> Copying meteor bundle into $DIST_APP..." $blue
mv bundle dist/osx/$DIST_APP/Contents/Resources/app/
cecho "-----> Copying node-webkit app into Kitematic.app..." $blue
cp index.js dist/osx/Kitematic.app/Contents/Resources/app/
cp package.json dist/osx/Kitematic.app/Contents/Resources/app/
cp -R node_modules dist/osx/Kitematic.app/Contents/Resources/app/
cecho "-----> Copying node-webkit app into $DIST_APP..." $blue
cp index.js dist/osx/$DIST_APP/Contents/Resources/app/
cp package.json dist/osx/$DIST_APP/Contents/Resources/app/
cp -R node_modules dist/osx/$DIST_APP/Contents/Resources/app/
cecho "-----> Copying binary files to Kitematic.app" $blue
mkdir -p dist/osx/Kitematic.app/Contents/Resources/app/resources
cp -v resources/* dist/osx/Kitematic.app/Contents/Resources/app/resources/ || :
cecho "-----> Copying binary files to $DIST_APP" $blue
mkdir -p dist/osx/$DIST_APP/Contents/Resources/app/resources
cp -v resources/* dist/osx/$DIST_APP/Contents/Resources/app/resources/ || :
chmod +x dist/osx/Kitematic.app/Contents/Resources/app/resources/$BOOT2DOCKER_CLI_FILE
chmod +x dist/osx/Kitematic.app/Contents/Resources/app/resources/$COCOASUDO_FILE
chmod +x dist/osx/Kitematic.app/Contents/Resources/app/resources/install
chmod +x dist/osx/Kitematic.app/Contents/Resources/app/resources/terminal
chmod +x dist/osx/Kitematic.app/Contents/Resources/app/resources/unison
chmod +x dist/osx/Kitematic.app/Contents/Resources/app/resources/node
cecho "-----> Copying icon to $DIST_APP" $blue
cp kitematic.icns dist/osx/$DIST_APP/Contents/Resources/atom.icns
chmod +x dist/osx/$DIST_APP/Contents/Resources/app/resources/$BOOT2DOCKER_CLI_FILE
chmod +x dist/osx/$DIST_APP/Contents/Resources/app/resources/$COCOASUDO_FILE
chmod +x dist/osx/$DIST_APP/Contents/Resources/app/resources/install
chmod +x dist/osx/$DIST_APP/Contents/Resources/app/resources/terminal
chmod +x dist/osx/$DIST_APP/Contents/Resources/app/resources/unison
chmod +x dist/osx/$DIST_APP/Contents/Resources/app/resources/node
cecho "-----> Updating Info.plist version to $VERSION" $blue
/usr/libexec/PlistBuddy -c "Set :CFBundleVersion $VERSION" $BASE/dist/osx/$DIST_APP/Contents/Info.plist
/usr/libexec/PlistBuddy -c "Set :CFBundleDisplayName Kitematic" $BASE/dist/osx/$DIST_APP/Contents/Info.plist
if [ -f $DIR/sign.sh ]; then
cecho "-----> Signing app file...." $blue
$DIR/sign.sh $BASE/dist/osx/Kitematic.app
$DIR/sign.sh $BASE/dist/osx/$DIST_APP
fi
pushd dist/osx
cecho "-----> Creating disributable zip file...." $blue
ditto -c -k --sequesterRsrc --keepParent Kitematic.app Kitematic.zip
ditto -c -k --sequesterRsrc --keepParent $DIST_APP Kitematic-$VERSION.zip
popd
VERSION=$(node -pe 'JSON.parse(process.argv[1]).version' "$(cat package.json)")
cecho "Updating Info.plist version to $VERSION"
/usr/libexec/PlistBuddy -c "Set :CFBundleVersion 0.3.0" $BASE/dist/osx/Kitematic.app/Contents/Info.plist
cecho "Done." $green
cecho "Kitematic app available at dist/osx/Kitematic.app" $green
cecho "Kitematic app available at dist/osx/$DIST_APP" $green
cecho "Kitematic zip distribution available at dist/osx/Kitematic.zip" $green
popd

View File

@ -3,9 +3,12 @@
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
BASE=$DIR/..
source $BASE/script/setup.sh
export ROOT_URL=https://localhost:3000
export DOCKER_HOST=http://192.168.59.103
export DOCKER_PORT=2375
export DIR=$BASE
cd $BASE/meteor
exec 3< <(meteor --settings $BASE/meteor/settings_dev.json)

View File

@ -15,6 +15,16 @@ BOOT2DOCKER_CLI_VERSION=1.2.0
BOOT2DOCKER_CLI_VERSION_FILE=boot2docker-$BOOT2DOCKER_CLI_VERSION
BOOT2DOCKER_CLI_FILE=boot2docker
ATOM_SHELL_VERSION=0.16.2
ATOM_SHELL_FILE=atom-shell-v$ATOM_SHELL_VERSION-darwin-x64.zip
if [ ! -f $ATOM_SHELL_FILE ]; then
cecho "-----> Downloading Boot2docker CLI..." $purple
curl -L -o $ATOM_SHELL_FILE https://github.com/atom/atom-shell/releases/download/v$ATOM_SHELL_VERSION/$ATOM_SHELL_FILE
mkdir -p atom-shell
unzip -d atom-shell $ATOM_SHELL_FILE
fi
if [ ! -f $BOOT2DOCKER_CLI_VERSION_FILE ]; then
cecho "-----> Downloading Boot2docker CLI..." $purple
curl -L -o $BOOT2DOCKER_CLI_VERSION_FILE https://s3.amazonaws.com/kite-installer/boot2docker-v$BOOT2DOCKER_CLI_VERSION
@ -55,7 +65,7 @@ popd
NPM="$BASE/cache/node/bin/npm"
export npm_config_disturl=https://gh-contractor-zcbenz.s3.amazonaws.com/atom-shell/dist
export npm_config_target=0.16.0
export npm_config_target=0.16.2
export npm_config_arch=ia32
HOME=~/.atom-shell-gyp $NPM install