mirror of https://github.com/docker/docs.git
Merge branch 'master' into sean-polish
Conflicts: src/NewContainer.react.js src/Setup.react.js src/SetupStore.js
This commit is contained in:
commit
4061544976
|
@ -0,0 +1,26 @@
|
|||
# Kitematic Testing
|
||||
|
||||
## Unit Tests
|
||||
|
||||
Simply run `npm test`
|
||||
|
||||
## Integration Tests
|
||||
|
||||
*Coming Soon*
|
||||
|
||||
## Manual Setup Tests
|
||||
|
||||
These tests only need to be run if code in `src/SetupStore.js` or `src/Setup.react.js` are changed.
|
||||
|
||||
The expected result for all test cases is that the setup finishes and an HTML container can be created, Also check that there are no errors in the output of Kitematic.
|
||||
|
||||
### Test Cases
|
||||
|
||||
**Clean state**: run `__tests__/util/reset`. WARNING: This will erase your existing VirtualBox, Docker & Kitematic installation.
|
||||
|
||||
- Clean state
|
||||
- Clean state with an old version of VirtualBox installed and running `4.3.16<`
|
||||
- Clean state with VirtualBox installed `4.3.18+`
|
||||
- Clean state with an old Boot2Docker VM & installation `0.12+`
|
||||
- Clean state with the latest Boot2Docker VM & installation
|
||||
- `FAILING` Clean state with an aborted Boot2Docker VM
|
|
@ -13,7 +13,6 @@ describe('SetupStore', function () {
|
|||
virtualBox.installed.mockReturnValue(false);
|
||||
setupUtil.download.mockReturnValue(Promise.resolve());
|
||||
return setupStore.steps().download.run().then(() => {
|
||||
// TODO: make sure download was called with the right args
|
||||
expect(setupUtil.download).toBeCalled();
|
||||
});
|
||||
});
|
||||
|
@ -30,26 +29,38 @@ describe('SetupStore', function () {
|
|||
});
|
||||
|
||||
describe('install step', function () {
|
||||
util.exec.mockReturnValue(Promise.resolve());
|
||||
util.copyBinariesCmd.mockReturnValue('copycmd');
|
||||
util.fixBinariesCmd.mockReturnValue('fixcmd');
|
||||
virtualBox.killall.mockReturnValue(Promise.resolve());
|
||||
setupUtil.installVirtualBoxCmd.mockReturnValue('installvb');
|
||||
setupUtil.macSudoCmd.mockImplementation(cmd => 'macsudo ' + cmd);
|
||||
|
||||
pit('installs virtualbox if it is not installed', function () {
|
||||
virtualBox.installed.mockReturnValue(false);
|
||||
virtualBox.killall.mockReturnValue(Promise.resolve());
|
||||
util.exec.mockReturnValue(Promise.resolve());
|
||||
return setupStore.steps().install.run().then(() => {
|
||||
// TODO: make sure that the right install command was executed
|
||||
expect(util.exec).toBeCalled();
|
||||
expect(virtualBox.killall).toBeCalled();
|
||||
expect(util.exec).toBeCalledWith('macsudo copycmd && fixcmd && installvbcmd');
|
||||
});
|
||||
});
|
||||
|
||||
pit('installs virtualbox if it is installed but has an outdated version', function () {
|
||||
virtualBox.installed.mockReturnValue(true);
|
||||
virtualBox.version.mockReturnValue(Promise.resolve('4.3.16'));
|
||||
virtualBox.killall.mockReturnValue(Promise.resolve());
|
||||
setupUtil.compareVersions.mockReturnValue(-1);
|
||||
util.exec.mockReturnValue(Promise.resolve());
|
||||
return setupStore.steps().install.run().then(() => {
|
||||
// TODO: make sure the right install command was executed
|
||||
expect(virtualBox.killall).toBeCalled();
|
||||
expect(util.exec).toBeCalled();
|
||||
expect(util.exec).toBeCalledWith('macsudo copycmd && fixcmd && installvbcmd');
|
||||
});
|
||||
});
|
||||
|
||||
pit('only installs binaries if virtualbox is installed', function () {
|
||||
virtualBox.installed.mockReturnValue(true);
|
||||
setupUtil.compareVersions.mockReturnValue(0);
|
||||
return setupStore.steps().install.run().then(() => {
|
||||
expect(util.exec).toBeCalledWith('macsudo copycmd && fixcmd');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -0,0 +1,245 @@
|
|||
#!/bin/bash
|
||||
# $Id: VirtualBox_Uninstall.tool 89624 2013-10-07 16:13:23Z bird $
|
||||
## @file
|
||||
# VirtualBox Uninstaller Script.
|
||||
#
|
||||
|
||||
#
|
||||
# Copyright (C) 2007-2013 Oracle Corporation
|
||||
#
|
||||
# This file is part of VirtualBox Open Source Edition (OSE), as
|
||||
# available from http://www.virtualbox.org. This file is free software;
|
||||
# you can redistribute it and/or modify it under the terms of the GNU
|
||||
# General Public License (GPL) as published by the Free Software
|
||||
# Foundation, in version 2 as it comes in the "COPYING" file of the
|
||||
# VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
||||
# hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
||||
#
|
||||
|
||||
# Override any funny stuff from the user.
|
||||
export PATH="/bin:/usr/bin:/sbin:/usr/sbin:$PATH"
|
||||
|
||||
#
|
||||
# Display a simple welcome message first.
|
||||
#
|
||||
echo ""
|
||||
echo "Welcome to the VirtualBox uninstaller script."
|
||||
echo ""
|
||||
|
||||
#
|
||||
# Check for arguments and display
|
||||
#
|
||||
my_default_prompt=0
|
||||
if test "$#" != "0"; then
|
||||
if test "$#" != "1" -o "$1" != "--unattended"; then
|
||||
echo "Error: Unknown argument(s): $*"
|
||||
echo ""
|
||||
echo "Usage: uninstall.sh [--unattended]"
|
||||
echo ""
|
||||
echo "If the '--unattended' option is not given, you will be prompted"
|
||||
echo "for a Yes/No before doing the actual uninstallation."
|
||||
echo ""
|
||||
exit 4;
|
||||
fi
|
||||
my_default_prompt="Yes"
|
||||
fi
|
||||
|
||||
#
|
||||
# Collect directories and files to remove.
|
||||
# Note: Do NOT attempt adding directories or filenames with spaces!
|
||||
#
|
||||
declare -a my_directories
|
||||
declare -a my_files
|
||||
|
||||
# Users files first
|
||||
test -f "${HOME}/Library/LaunchAgents/org.virtualbox.vboxwebsrv.plist" && my_files+=("${HOME}/Library/LaunchAgents/org.virtualbox.vboxwebsrv.plist")
|
||||
|
||||
test -d /Library/StartupItems/VirtualBox/ && my_directories+=("/Library/StartupItems/VirtualBox/")
|
||||
test -d /Library/Receipts/VBoxStartupItems.pkg/ && my_directories+=("/Library/Receipts/VBoxStartupItems.pkg/")
|
||||
|
||||
test -d "/Library/Application Support/VirtualBox/LaunchDaemons/" && my_directories+=("/Library/Application Support/VirtualBox/LaunchDaemons/")
|
||||
test -d "/Library/Application Support/VirtualBox/VBoxDrv.kext/" && my_directories+=("/Library/Application Support/VirtualBox/VBoxDrv.kext/")
|
||||
test -d "/Library/Application Support/VirtualBox/VBoxUSB.kext/" && my_directories+=("/Library/Application Support/VirtualBox/VBoxUSB.kext/")
|
||||
test -d "/Library/Application Support/VirtualBox/VBoxNetFlt.kext/" && my_directories+=("/Library/Application Support/VirtualBox/VBoxNetFlt.kext/")
|
||||
test -d "/Library/Application Support/VirtualBox/VBoxNetAdp.kext/" && my_directories+=("/Library/Application Support/VirtualBox/VBoxNetAdp.kext/")
|
||||
# Pre 4.3.0rc1 locations:
|
||||
test -d /Library/Extensions/VBoxDrv.kext/ && my_directories+=("/Library/Extensions/VBoxDrv.kext/")
|
||||
test -d /Library/Extensions/VBoxUSB.kext/ && my_directories+=("/Library/Extensions/VBoxUSB.kext/")
|
||||
test -d /Library/Extensions/VBoxNetFlt.kext/ && my_directories+=("/Library/Extensions/VBoxNetFlt.kext/")
|
||||
test -d /Library/Extensions/VBoxNetAdp.kext/ && my_directories+=("/Library/Extensions/VBoxNetAdp.kext/")
|
||||
# Tiger support is obsolete, but we leave it here for a clean removing of older
|
||||
# VirtualBox versions
|
||||
test -d /Library/Extensions/VBoxDrvTiger.kext/ && my_directories+=("/Library/Extensions/VBoxDrvTiger.kext/")
|
||||
test -d /Library/Extensions/VBoxUSBTiger.kext/ && my_directories+=("/Library/Extensions/VBoxUSBTiger.kext/")
|
||||
test -d /Library/Receipts/VBoxKEXTs.pkg/ && my_directories+=("/Library/Receipts/VBoxKEXTs.pkg/")
|
||||
|
||||
test -f /usr/bin/VirtualBox && my_files+=("/usr/bin/VirtualBox")
|
||||
test -f /usr/bin/VBoxManage && my_files+=("/usr/bin/VBoxManage")
|
||||
test -f /usr/bin/VBoxVRDP && my_files+=("/usr/bin/VBoxVRDP")
|
||||
test -f /usr/bin/VBoxHeadless && my_files+=("/usr/bin/VBoxHeadless")
|
||||
test -f /usr/bin/vboxwebsrv && my_files+=("/usr/bin/vboxwebsrv")
|
||||
test -f /usr/bin/VBoxBalloonCtrl && my_files+=("/usr/bin/VBoxBalloonCtrl")
|
||||
test -f /usr/bin/VBoxAutostart && my_files+=("/usr/bin/VBoxAutostart")
|
||||
test -f /usr/bin/vbox-img && my_files+=("/usr/bin/vbox-img")
|
||||
test -d /Library/Receipts/VirtualBoxCLI.pkg/ && my_directories+=("/Library/Receipts/VirtualBoxCLI.pkg/")
|
||||
test -f /Library/LaunchDaemons/org.virtualbox.startup.plist && my_files+=("/Library/LaunchDaemons/org.virtualbox.startup.plist")
|
||||
|
||||
test -d /Applications/VirtualBox.app/ && my_directories+=("/Applications/VirtualBox.app/")
|
||||
test -d /Library/Receipts/VirtualBox.pkg/ && my_directories+=("/Library/Receipts/VirtualBox.pkg/")
|
||||
|
||||
# legacy
|
||||
test -d /Library/Receipts/VBoxDrv.pkg/ && my_directories+=("/Library/Receipts/VBoxDrv.pkg/")
|
||||
test -d /Library/Receipts/VBoxUSB.pkg/ && my_directories+=("/Library/Receipts/VBoxUSB.pkg/")
|
||||
|
||||
# python stuff
|
||||
python_versions="2.3 2.5 2.6 2.7"
|
||||
for p in $python_versions; do
|
||||
test -f /Library/Python/$p/site-packages/vboxapi/VirtualBox_constants.py && my_files+=("/Library/Python/$p/site-packages/vboxapi/VirtualBox_constants.py")
|
||||
test -f /Library/Python/$p/site-packages/vboxapi/VirtualBox_constants.pyc && my_files+=("/Library/Python/$p/site-packages/vboxapi/VirtualBox_constants.pyc")
|
||||
test -f /Library/Python/$p/site-packages/vboxapi/__init__.py && my_files+=("/Library/Python/$p/site-packages/vboxapi/__init__.py")
|
||||
test -f /Library/Python/$p/site-packages/vboxapi/__init__.pyc && my_files+=("/Library/Python/$p/site-packages/vboxapi/__init__.pyc")
|
||||
test -f /Library/Python/$p/site-packages/vboxapi-1.0-py$p.egg-info && my_files+=("/Library/Python/$p/site-packages/vboxapi-1.0-py$p.egg-info")
|
||||
test -d /Library/Python/$p/site-packages/vboxapi/ && my_directories+=("/Library/Python/$p/site-packages/vboxapi/")
|
||||
done
|
||||
|
||||
#
|
||||
# Collect KEXTs to remove.
|
||||
# Note that the unload order is significant.
|
||||
#
|
||||
declare -a my_kexts
|
||||
for kext in org.virtualbox.kext.VBoxUSB org.virtualbox.kext.VBoxNetFlt org.virtualbox.kext.VBoxNetAdp org.virtualbox.kext.VBoxDrv; do
|
||||
if /usr/sbin/kextstat -b $kext -l | grep -q $kext; then
|
||||
my_kexts+=("$kext")
|
||||
fi
|
||||
done
|
||||
|
||||
#
|
||||
# Collect packages to forget
|
||||
#
|
||||
my_pb='org\.virtualbox\.pkg\.'
|
||||
my_pkgs=`/usr/sbin/pkgutil --pkgs="${my_pb}vboxkexts|${my_pb}vboxstartupitems|${my_pb}virtualbox|${my_pb}virtualboxcli"`
|
||||
|
||||
#
|
||||
# Did we find anything to uninstall?
|
||||
#
|
||||
if test -z "${my_directories[*]}" -a -z "${my_files[*]}" -a -z "${my_kexts[*]}" -a -z "$my_pkgs"; then
|
||||
echo "No VirtualBox files, directories, KEXTs or packages to uninstall."
|
||||
echo "Done."
|
||||
exit 0;
|
||||
fi
|
||||
|
||||
#
|
||||
# Look for running VirtualBox processes and warn the user
|
||||
# if something is running. Since deleting the files of
|
||||
# running processes isn't fatal as such, we will leave it
|
||||
# to the user to choose whether to continue or not.
|
||||
#
|
||||
# Note! comm isn't supported on Tiger, so we make -c to do the stripping.
|
||||
#
|
||||
my_processes="`ps -axco 'pid uid command' | grep -wEe '(VirtualBox|VirtualBoxVM|VBoxManage|VBoxHeadless|vboxwebsrv|VBoxXPCOMIPCD|VBoxSVC|VBoxNetDHCP|VBoxNetNAT)' | grep -vw grep | grep -vw VirtualBox_Uninstall.tool | tr '\n' '\a'`";
|
||||
if test -n "$my_processes"; then
|
||||
echo 'Warning! Found the following active VirtualBox processes:'
|
||||
echo "$my_processes" | tr '\a' '\n'
|
||||
echo ""
|
||||
echo "We recommend that you quit all VirtualBox processes before"
|
||||
echo "uninstalling the product."
|
||||
echo ""
|
||||
if test "$my_default_prompt" != "Yes"; then
|
||||
echo "Do you wish to continue none the less (Yes/No)?"
|
||||
read my_answer
|
||||
if test "$my_answer" != "Yes" -a "$my_answer" != "YES" -a "$my_answer" != "yes"; then
|
||||
echo "Aborting uninstall. (answer: '$my_answer')".
|
||||
exit 2;
|
||||
fi
|
||||
echo ""
|
||||
my_answer=""
|
||||
fi
|
||||
fi
|
||||
|
||||
#
|
||||
# Display the files and directories that will be removed
|
||||
# and get the user's consent before continuing.
|
||||
#
|
||||
if test -n "${my_files[*]}" -o -n "${my_directories[*]}"; then
|
||||
echo "The following files and directories (bundles) will be removed:"
|
||||
for file in "${my_files[@]}"; do echo " $file"; done
|
||||
for dir in "${my_directories[@]}"; do echo " $dir"; done
|
||||
echo ""
|
||||
fi
|
||||
if test -n "${my_kexts[*]}"; then
|
||||
echo "And the following KEXTs will be unloaded:"
|
||||
for kext in "${my_kexts[@]}"; do echo " $kext"; done
|
||||
echo ""
|
||||
fi
|
||||
if test -n "$my_pkgs"; then
|
||||
echo "And the traces of following packages will be removed:"
|
||||
for kext in $my_pkgs; do echo " $kext"; done
|
||||
echo ""
|
||||
fi
|
||||
|
||||
if test "$my_default_prompt" != "Yes"; then
|
||||
echo "Do you wish to uninstall VirtualBox (Yes/No)?"
|
||||
read my_answer
|
||||
if test "$my_answer" != "Yes" -a "$my_answer" != "YES" -a "$my_answer" != "yes"; then
|
||||
echo "Aborting uninstall. (answer: '$my_answer')".
|
||||
exit 2;
|
||||
fi
|
||||
echo ""
|
||||
fi
|
||||
|
||||
#
|
||||
# Unregister has to be done before the files are removed.
|
||||
#
|
||||
LSREGISTER=/System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/LaunchServices.framework/Versions/A/Support/lsregister
|
||||
if [ -e ${LSREGISTER} ]; then
|
||||
${LSREGISTER} -u /Applications/VirtualBox.app > /dev/null
|
||||
${LSREGISTER} -u /Applications/VirtualBox.app/Contents/Resources/vmstarter.app > /dev/null
|
||||
fi
|
||||
|
||||
#
|
||||
# Display the sudo usage instructions and execute the command.
|
||||
#
|
||||
echo "The uninstallation processes requires administrative privileges"
|
||||
echo "because some of the installed files cannot be removed by a normal"
|
||||
echo "user. You may be prompted for your password now..."
|
||||
echo ""
|
||||
|
||||
if test -n "${my_files[*]}" -o -n "${my_directories[*]}"; then
|
||||
/usr/bin/sudo -p "Please enter %u's password:" /bin/rm -Rf "${my_files[@]}" "${my_directories[@]}"
|
||||
my_rc=$?
|
||||
if test "$my_rc" -ne 0; then
|
||||
echo "An error occurred durning 'sudo rm', there should be a message above. (rc=$my_rc)"
|
||||
test -x /usr/bin/sudo || echo "warning: Cannot find /usr/bin/sudo or it's not an executable."
|
||||
test -x /bin/rm || echo "warning: Cannot find /bin/rm or it's not an executable"
|
||||
echo ""
|
||||
echo "The uninstall failed. Please retry."
|
||||
exit 1;
|
||||
fi
|
||||
fi
|
||||
|
||||
my_rc=0
|
||||
for kext in "${my_kexts[@]}"; do
|
||||
echo unloading $kext
|
||||
/usr/bin/sudo -p "Please enter %u's password (unloading $kext):" /sbin/kextunload -m $kext
|
||||
my_rc2=$?
|
||||
if test "$my_rc2" -ne 0; then
|
||||
echo "An error occurred durning 'sudo /sbin/kextunload -m $kext', there should be a message above. (rc=$my_rc2)"
|
||||
test -x /usr/bin/sudo || echo "warning: Cannot find /usr/bin/sudo or it's not an executable."
|
||||
test -x /sbin/kextunload || echo "warning: Cannot find /sbin/kextunload or it's not an executable"
|
||||
my_rc=$my_rc2
|
||||
fi
|
||||
done
|
||||
if test "$my_rc" -eq 0; then
|
||||
echo "Successfully unloaded VirtualBox kernel extensions."
|
||||
else
|
||||
echo "Failed to unload one or more KEXTs, please reboot the machine to complete the uninstall."
|
||||
exit 1;
|
||||
fi
|
||||
|
||||
# Cleaning up pkgutil database
|
||||
for my_pkg in $my_pkgs; do
|
||||
/usr/bin/sudo -p "Please enter %u's password (removing $my_pkg):" /usr/sbin/pkgutil --forget "$my_pkg"
|
||||
done
|
||||
|
||||
echo "Done."
|
||||
exit 0;
|
|
@ -0,0 +1,10 @@
|
|||
#!/bin/bash
|
||||
|
||||
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||
|
||||
rm -rf ~/Library/Application\ Support/Kitematic/
|
||||
pkill VBox
|
||||
pkill VirtualBox
|
||||
$DIR/VirtualBox_Uninstall.tool
|
||||
rm -rf ~/.boot2docker
|
||||
rm -rf ~/VirtualBox\ VMs/boot2docker-vm
|
|
@ -16,6 +16,7 @@ try {
|
|||
process.env.NODE_PATH = __dirname + '/../node_modules';
|
||||
process.env.RESOURCES_PATH = __dirname + '/../resources';
|
||||
process.chdir(path.join(__dirname, '..'));
|
||||
process.env.PATH = '/usr/local/bin:' + process.env.PATH;
|
||||
|
||||
if (argv.integration) {
|
||||
process.env.TEST_TYPE = 'integration';
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
<head>
|
||||
<link rel="stylesheet" href="main.css"/>
|
||||
<meta http-equiv="Content-Security-Policy" content="default-src *; script-src 'self' http://localhost:35729; style-src 'self' 'unsafe-inline';">
|
||||
|
||||
<title>Kitematic</title>
|
||||
</head>
|
||||
<body>
|
||||
|
|
|
@ -38,8 +38,8 @@
|
|||
"node_modules/6to5"
|
||||
]
|
||||
},
|
||||
"docker-version": "1.4.1",
|
||||
"boot2docker-version": "1.4.1",
|
||||
"docker-version": "1.5.0",
|
||||
"boot2docker-version": "1.5.0",
|
||||
"atom-shell-version": "0.21.1",
|
||||
"virtualbox-version": "4.3.20",
|
||||
"virtualbox-filename": "VirtualBox-4.3.20.pkg",
|
||||
|
|
Binary file not shown.
Binary file not shown.
|
@ -19,7 +19,7 @@ var ContainerDetail = React.createClass({
|
|||
},
|
||||
init: function () {
|
||||
var currentRoute = _.last(this.getRoutes()).name;
|
||||
if (currentRoute === 'containerDetail') {
|
||||
if (currentRoute === 'containerDetails') {
|
||||
this.transitionTo('containerHome', {name: this.getParams().name});
|
||||
}
|
||||
},
|
||||
|
|
|
@ -1,640 +0,0 @@
|
|||
var _ = require('underscore');
|
||||
var $ = require('jquery');
|
||||
var React = require('react/addons');
|
||||
var Router = require('react-router');
|
||||
var exec = require('exec');
|
||||
var path = require('path');
|
||||
var remote = require('remote');
|
||||
var rimraf = require('rimraf');
|
||||
var fs = require('fs');
|
||||
var dialog = remote.require('dialog');
|
||||
var ContainerStore = require('./ContainerStore');
|
||||
var ContainerUtil = require('./ContainerUtil');
|
||||
var boot2docker = require('./Boot2Docker');
|
||||
var ContainerDetailsHeader = require('./ContainerDetailsHeader.react');
|
||||
var ContainerHome = require('./ContainerHome.react');
|
||||
var RetinaImage = require('react-retina-image');
|
||||
var Radial = require('./Radial.react');
|
||||
|
||||
var _oldHeight = 0;
|
||||
|
||||
var ContainerDetailsbak = React.createClass({
|
||||
mixins: [Router.State, Router.Navigation],
|
||||
PAGE_HOME: 'home',
|
||||
PAGE_LOGS: 'logs',
|
||||
PAGE_SETTINGS: 'settings',
|
||||
PAGE_PORTS: 'ports',
|
||||
PAGE_VOLUMES: 'volumes',
|
||||
getInitialState: function () {
|
||||
return {
|
||||
logs: [],
|
||||
page: this.PAGE_HOME,
|
||||
env: {},
|
||||
pendingEnv: {},
|
||||
ports: {},
|
||||
volumes: {},
|
||||
defaultPort: null
|
||||
};
|
||||
},
|
||||
componentWillReceiveProps: function () {
|
||||
this.init();
|
||||
},
|
||||
componentDidMount: function () {
|
||||
this.init();
|
||||
ContainerStore.on(ContainerStore.SERVER_PROGRESS_EVENT, this.updateProgress);
|
||||
ContainerStore.on(ContainerStore.SERVER_LOGS_EVENT, this.updateLogs);
|
||||
},
|
||||
componentWillUnmount: function () {
|
||||
ContainerStore.removeListener(ContainerStore.SERVER_PROGRESS_EVENT, this.updateProgress);
|
||||
ContainerStore.removeListener(ContainerStore.SERVER_LOGS_EVENT, this.updateLogs);
|
||||
},
|
||||
componentDidUpdate: function () {
|
||||
// Scroll logs to bottom
|
||||
var parent = $('.details-logs');
|
||||
if (parent.length) {
|
||||
if (parent.scrollTop() >= _oldHeight) {
|
||||
parent.stop();
|
||||
parent.scrollTop(parent[0].scrollHeight - parent.height());
|
||||
}
|
||||
_oldHeight = parent[0].scrollHeight - parent.height();
|
||||
}
|
||||
},
|
||||
init: function () {
|
||||
var container = ContainerStore.container(this.getParams().name);
|
||||
if (!container) {
|
||||
return;
|
||||
}
|
||||
this.setState({
|
||||
progress: ContainerStore.progress(this.getParams().name),
|
||||
env: ContainerUtil.env(container),
|
||||
page: this.PAGE_HOME
|
||||
});
|
||||
var ports = ContainerUtil.ports(container);
|
||||
var webPorts = ['80', '8000', '8080', '3000', '5000', '2368'];
|
||||
this.setState({
|
||||
ports: ports,
|
||||
defaultPort: _.find(_.keys(ports), function (port) {
|
||||
return webPorts.indexOf(port) !== -1;
|
||||
})
|
||||
});
|
||||
this.updateLogs();
|
||||
},
|
||||
updateLogs: function (name) {
|
||||
if (name && name !== this.getParams().name) {
|
||||
return;
|
||||
}
|
||||
this.setState({
|
||||
logs: ContainerStore.logs(this.getParams().name)
|
||||
});
|
||||
},
|
||||
updateProgress: function (name) {
|
||||
if (name === this.getParams().name) {
|
||||
this.setState({
|
||||
progress: ContainerStore.progress(name)
|
||||
});
|
||||
}
|
||||
},
|
||||
disableRun: function () {
|
||||
return (!this.props.container.State.Running || !this.state.defaultPort);
|
||||
},
|
||||
disableRestart: function () {
|
||||
return (this.props.container.State.Downloading || this.props.container.State.Restarting);
|
||||
},
|
||||
disableTerminal: function () {
|
||||
return (!this.props.container.State.Running);
|
||||
},
|
||||
disableTab: function () {
|
||||
return (this.props.container.State.Downloading);
|
||||
},
|
||||
showHome: function () {
|
||||
if (!this.disableTab()) {
|
||||
/*this.setState({
|
||||
page: this.PAGE_HOME
|
||||
});*/
|
||||
this.transitionTo('containerHome', {name: this.getParams().name});
|
||||
}
|
||||
},
|
||||
showLogs: function () {
|
||||
if (!this.disableTab()) {
|
||||
this.setState({
|
||||
page: this.PAGE_LOGS
|
||||
});
|
||||
}
|
||||
},
|
||||
showPorts: function () {
|
||||
this.setState({
|
||||
page: this.PAGE_PORTS
|
||||
});
|
||||
},
|
||||
showVolumes: function () {
|
||||
this.setState({
|
||||
page: this.PAGE_VOLUMES
|
||||
});
|
||||
},
|
||||
showSettings: function () {
|
||||
if (!this.disableTab()) {
|
||||
this.setState({
|
||||
page: this.PAGE_SETTINGS
|
||||
});
|
||||
}
|
||||
},
|
||||
handleRun: function () {
|
||||
if (this.state.defaultPort && !this.disableRun()) {
|
||||
exec(['open', this.state.ports[this.state.defaultPort].url], function (err) {
|
||||
if (err) { throw err; }
|
||||
});
|
||||
}
|
||||
},
|
||||
handleRestart: function () {
|
||||
if (!this.disableRestart()) {
|
||||
ContainerStore.restart(this.props.container.Name, function (err) {
|
||||
console.log(err);
|
||||
});
|
||||
}
|
||||
},
|
||||
handleTerminal: function () {
|
||||
if (!this.disableTerminal()) {
|
||||
var container = this.props.container;
|
||||
var terminal = path.join(process.cwd(), 'resources', 'terminal');
|
||||
var cmd = [terminal, boot2docker.command().replace(/ /g, '\\\\\\\\ ').replace(/\(/g, '\\\\\\\\(').replace(/\)/g, '\\\\\\\\)'), 'ssh', '-t', 'sudo', 'docker', 'exec', '-i', '-t', container.Name, 'sh'];
|
||||
exec(cmd, function (stderr, stdout, code) {
|
||||
console.log(stderr);
|
||||
console.log(stdout);
|
||||
if (code) {
|
||||
console.log(stderr);
|
||||
}
|
||||
});
|
||||
}
|
||||
},
|
||||
handleViewLink: function (url) {
|
||||
exec(['open', url], function (err) {
|
||||
if (err) { throw err; }
|
||||
});
|
||||
},
|
||||
handleChangeDefaultPort: function (port, e) {
|
||||
if (e.target.checked) {
|
||||
this.setState({
|
||||
defaultPort: null
|
||||
});
|
||||
} else {
|
||||
this.setState({
|
||||
defaultPort: port
|
||||
});
|
||||
}
|
||||
},
|
||||
handleChooseVolumeClick: function (dockerVol) {
|
||||
var self = this;
|
||||
dialog.showOpenDialog({properties: ['openDirectory', 'createDirectory']}, function (filenames) {
|
||||
if (!filenames) {
|
||||
return;
|
||||
}
|
||||
var directory = filenames[0];
|
||||
if (directory) {
|
||||
var volumes = _.clone(self.props.container.Volumes);
|
||||
volumes[dockerVol] = directory;
|
||||
var binds = _.pairs(volumes).map(function (pair) {
|
||||
return pair[1] + ':' + pair[0];
|
||||
});
|
||||
ContainerStore.updateContainer(self.props.container.Name, {
|
||||
Binds: binds
|
||||
}, function (err) {
|
||||
if (err) { console.log(err); }
|
||||
});
|
||||
}
|
||||
});
|
||||
},
|
||||
handleOpenVolumeClick: function (path) {
|
||||
exec(['open', path], function (err) {
|
||||
if (err) { throw err; }
|
||||
});
|
||||
},
|
||||
handleSaveContainerName: function () {
|
||||
var newName = $('#input-container-name').val();
|
||||
if (newName === this.props.container.Name) {
|
||||
return;
|
||||
}
|
||||
if (fs.existsSync(path.join(process.env.HOME, 'Kitematic', this.props.container.Name))) {
|
||||
fs.renameSync(path.join(process.env.HOME, 'Kitematic', this.props.container.Name), path.join(process.env.HOME, 'Kitematic', newName));
|
||||
}
|
||||
ContainerStore.updateContainer(this.props.container.Name, {
|
||||
name: newName
|
||||
}, function (err) {
|
||||
this.transitionTo('container', {name: newName});
|
||||
if (err) {
|
||||
console.error(err);
|
||||
}
|
||||
}.bind(this));
|
||||
},
|
||||
handleSaveEnvVar: function () {
|
||||
var $rows = $('.env-vars .keyval-row');
|
||||
var envVarList = [];
|
||||
$rows.each(function () {
|
||||
var key = $(this).find('.key').val();
|
||||
var val = $(this).find('.val').val();
|
||||
if (!key.length || !val.length) {
|
||||
return;
|
||||
}
|
||||
envVarList.push(key + '=' + val);
|
||||
});
|
||||
var self = this;
|
||||
ContainerStore.updateContainer(self.props.container.Name, {
|
||||
Env: envVarList
|
||||
}, function (err) {
|
||||
if (err) {
|
||||
console.error(err);
|
||||
} else {
|
||||
self.setState({
|
||||
pendingEnv: {}
|
||||
});
|
||||
$('#new-env-key').val('');
|
||||
$('#new-env-val').val('');
|
||||
}
|
||||
});
|
||||
},
|
||||
handleAddPendingEnvVar: function () {
|
||||
var newKey = $('#new-env-key').val();
|
||||
var newVal = $('#new-env-val').val();
|
||||
var newEnv = {};
|
||||
newEnv[newKey] = newVal;
|
||||
this.setState({
|
||||
pendingEnv: _.extend(this.state.pendingEnv, newEnv)
|
||||
});
|
||||
$('#new-env-key').val('');
|
||||
$('#new-env-val').val('');
|
||||
},
|
||||
handleRemoveEnvVar: function (key) {
|
||||
var newEnv = _.omit(this.state.env, key);
|
||||
this.setState({
|
||||
env: newEnv
|
||||
});
|
||||
},
|
||||
handleRemovePendingEnvVar: function (key) {
|
||||
var newEnv = _.omit(this.state.pendingEnv, key);
|
||||
this.setState({
|
||||
pendingEnv: newEnv
|
||||
});
|
||||
},
|
||||
handleDeleteContainer: function () {
|
||||
dialog.showMessageBox({
|
||||
message: 'Are you sure you want to delete this container?',
|
||||
buttons: ['Delete', 'Cancel']
|
||||
}, function (index) {
|
||||
var volumePath = path.join(process.env.HOME, 'Kitematic', this.props.container.Name);
|
||||
if (fs.existsSync(volumePath)) {
|
||||
rimraf(volumePath, function (err) {
|
||||
console.log(err);
|
||||
});
|
||||
}
|
||||
if (index === 0) {
|
||||
ContainerStore.remove(this.props.container.Name, function (err) {
|
||||
console.error(err);
|
||||
});
|
||||
}
|
||||
}.bind(this));
|
||||
},
|
||||
handleItemMouseEnterRun: function () {
|
||||
var $action = $(this.getDOMNode()).find('.action .run');
|
||||
$action.css("visibility", "visible");
|
||||
},
|
||||
handleItemMouseLeaveRun: function () {
|
||||
var $action = $(this.getDOMNode()).find('.action .run');
|
||||
$action.css("visibility", "hidden");
|
||||
},
|
||||
handleItemMouseEnterRestart: function () {
|
||||
var $action = $(this.getDOMNode()).find('.action .restart');
|
||||
$action.css("visibility", "visible");
|
||||
},
|
||||
handleItemMouseLeaveRestart: function () {
|
||||
var $action = $(this.getDOMNode()).find('.action .restart');
|
||||
$action.css("visibility", "hidden");
|
||||
},
|
||||
handleItemMouseEnterTerminal: function () {
|
||||
var $action = $(this.getDOMNode()).find('.action .terminal');
|
||||
$action.css("visibility", "visible");
|
||||
},
|
||||
handleItemMouseLeaveTerminal: function () {
|
||||
var $action = $(this.getDOMNode()).find('.action .terminal');
|
||||
$action.css("visibility", "hidden");
|
||||
},
|
||||
render: function () {
|
||||
var self = this;
|
||||
|
||||
if (!this.state) {
|
||||
return <div></div>;
|
||||
}
|
||||
|
||||
var logs = this.state.logs.map(function (l, i) {
|
||||
return <p key={i} dangerouslySetInnerHTML={{__html: l}}></p>;
|
||||
});
|
||||
|
||||
if (!this.props.container) {
|
||||
return false;
|
||||
}
|
||||
|
||||
var button;
|
||||
if (this.state.progress === 1) {
|
||||
button = <a className="btn btn-primary" onClick={this.handleClick}>View</a>;
|
||||
} else {
|
||||
button = <a className="btn btn-primary disabled" onClick={this.handleClick}>View</a>;
|
||||
}
|
||||
|
||||
var envVars = _.map(this.state.env, function (val, key) {
|
||||
return (
|
||||
<div key={key} className="keyval-row">
|
||||
<input type="text" className="key line" defaultValue={key}></input>
|
||||
<input type="text" className="val line" defaultValue={val}></input>
|
||||
<a onClick={self.handleRemoveEnvVar.bind(self, key)} className="only-icon btn btn-action small"><span className="icon icon-cross"></span></a>
|
||||
</div>
|
||||
);
|
||||
});
|
||||
var pendingEnvVars = _.map(this.state.pendingEnv, function (val, key) {
|
||||
return (
|
||||
<div key={key} className="keyval-row">
|
||||
<input type="text" className="key line" defaultValue={key}></input>
|
||||
<input type="text" className="val line" defaultValue={val}></input>
|
||||
<a onClick={self.handleRemovePendingEnvVar.bind(self, key)} className="only-icon btn btn-action small"><span className="icon icon-arrow-undo"></span></a>
|
||||
</div>
|
||||
);
|
||||
});
|
||||
|
||||
var disabledClass = '';
|
||||
if (!this.props.container.State.Running) {
|
||||
disabledClass = 'disabled';
|
||||
}
|
||||
|
||||
/*var buttonClass = React.addons.classSet({
|
||||
btn: true,
|
||||
'btn-action': true,
|
||||
'with-icon': true,
|
||||
disabled: !this.props.container.State.Running
|
||||
});
|
||||
|
||||
var restartButtonClass = React.addons.classSet({
|
||||
btn: true,
|
||||
'btn-action': true,
|
||||
'with-icon': true,
|
||||
disabled: this.props.container.State.Downloading || this.props.container.State.Restarting
|
||||
});
|
||||
|
||||
var viewButtonClass = React.addons.classSet({
|
||||
btn: true,
|
||||
'btn-action': true,
|
||||
'with-icon': true,
|
||||
disabled: !this.props.container.State.Running || !this.state.defaultPort
|
||||
});
|
||||
|
||||
var kitematicVolumes = _.pairs(this.props.container.Volumes).filter(function (pair) {
|
||||
return pair[1].indexOf(path.join(process.env.HOME, 'Kitematic')) !== -1;
|
||||
});
|
||||
|
||||
var volumesButtonClass = React.addons.classSet({
|
||||
btn: true,
|
||||
'btn-action': true,
|
||||
'with-icon': true,
|
||||
disabled: !kitematicVolumes.length
|
||||
});
|
||||
|
||||
var textButtonClasses = React.addons.classSet({
|
||||
'btn': true,
|
||||
'btn-action': true,
|
||||
'only-icon': true,
|
||||
'active': this.state.page === this.PAGE_LOGS,
|
||||
disabled: this.props.container.State.Downloading
|
||||
});
|
||||
|
||||
var gearButtonClass = React.addons.classSet({
|
||||
'btn': true,
|
||||
'btn-action': true,
|
||||
'only-icon': true,
|
||||
'active': this.state.page === this.PAGE_SETTINGS,
|
||||
disabled: this.props.container.State.Downloading
|
||||
});*/
|
||||
|
||||
var ports = _.map(_.pairs(self.state.ports), function (pair) {
|
||||
var key = pair[0];
|
||||
var val = pair[1];
|
||||
return (
|
||||
<div key={key} className="table-values">
|
||||
<span className="value-left">{key}</span><span className="icon icon-arrow-right"></span>
|
||||
<a className="value-right" onClick={self.handleViewLink.bind(self, val.url)}>{val.display}</a>
|
||||
</div>
|
||||
);
|
||||
});
|
||||
|
||||
var volumes = _.map(self.props.container.Volumes, function (val, key) {
|
||||
if (!val || val.indexOf(process.env.HOME) === -1) {
|
||||
val = 'No Host Folder';
|
||||
}
|
||||
return (
|
||||
<div key={key} className="table-values">
|
||||
<span className="value-left">{key}</span><span className="icon icon-arrow-right"></span>
|
||||
<a className="value-right">{val.replace(process.env.HOME, '~')}</a>
|
||||
</div>
|
||||
);
|
||||
});
|
||||
|
||||
var body;
|
||||
if (this.props.container.State.Downloading) {
|
||||
if (this.state.progress) {
|
||||
body = (
|
||||
<div className="details-progress">
|
||||
<h2>Downloading Image</h2>
|
||||
<Radial progress={Math.round(this.state.progress * 100)}/>
|
||||
</div>
|
||||
);
|
||||
} else {
|
||||
body = (
|
||||
<div className="details-progress">
|
||||
<h2>Connecting to Docker Hub</h2>
|
||||
<Radial spin="true" progress="90"/>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
} else {
|
||||
if (this.state.page === this.PAGE_HOME) {
|
||||
body = (
|
||||
<ContainerHome ports={this.state.ports} defaultPort={this.state.defaultPort} logs={logs} container={this.props.container} />
|
||||
);
|
||||
} else if (this.state.page === this.PAGE_LOGS) {
|
||||
body = (
|
||||
<div className="details-panel details-logs logs">
|
||||
{logs}
|
||||
</div>
|
||||
);
|
||||
} else if (this.state.page === this.PAGE_PORTS) {
|
||||
body = (
|
||||
<div className="details-panel">
|
||||
<div className="ports">
|
||||
<h3>Configure Ports</h3>
|
||||
<div className="table">
|
||||
<div className="table-labels">
|
||||
<div className="label-left">DOCKER PORT</div>
|
||||
<div className="label-right">MAC PORT</div>
|
||||
</div>
|
||||
{ports}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
} else if (this.state.page === this.PAGE_VOLUMES) {
|
||||
body = (
|
||||
<div className="details-panel">
|
||||
<div className="volumes">
|
||||
<h3>Configure Volumes</h3>
|
||||
<div className="table">
|
||||
<div className="table-labels">
|
||||
<div className="label-left">DOCKER FOLDER</div>
|
||||
<div className="label-right">MAC FOLDER</div>
|
||||
</div>
|
||||
{volumes}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
} else {
|
||||
var rename = (
|
||||
<div className="settings-section">
|
||||
<h3>Container Name</h3>
|
||||
<div className="container-name">
|
||||
<input id="input-container-name" type="text" className="line" placeholder="Container Name" defaultValue={this.props.container.Name}></input>
|
||||
</div>
|
||||
<a className="btn btn-action" onClick={this.handleSaveContainerName}>Save</a>
|
||||
</div>
|
||||
);
|
||||
body = (
|
||||
<div className="details-panel">
|
||||
<div className="settings">
|
||||
{rename}
|
||||
<div className="settings-section">
|
||||
<h3>Environment Variables</h3>
|
||||
<div className="env-vars-labels">
|
||||
<div className="label-key">KEY</div>
|
||||
<div className="label-val">VALUE</div>
|
||||
</div>
|
||||
<div className="env-vars">
|
||||
{envVars}
|
||||
{pendingEnvVars}
|
||||
<div className="keyval-row">
|
||||
<input id="new-env-key" type="text" className="key line"></input>
|
||||
<input id="new-env-val" type="text" className="val line"></input>
|
||||
<a onClick={this.handleAddPendingEnvVar} className="only-icon btn btn-positive small"><span className="icon icon-add-1"></span></a>
|
||||
</div>
|
||||
</div>
|
||||
<a className="btn btn-action" onClick={this.handleSaveEnvVar}>Save</a>
|
||||
</div>
|
||||
<div className="settings-section">
|
||||
<h3>Delete Container</h3>
|
||||
<a className="btn btn-action" onClick={this.handleDeleteContainer}>Delete Container</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
var tabHomeClasses = React.addons.classSet({
|
||||
'tab': true,
|
||||
'active': this.state.page === this.PAGE_HOME,
|
||||
disabled: this.disableTab()
|
||||
});
|
||||
|
||||
var tabLogsClasses = React.addons.classSet({
|
||||
'tab': true,
|
||||
'active': this.state.page === this.PAGE_LOGS,
|
||||
disabled: this.disableTab()
|
||||
});
|
||||
|
||||
var tabSettingsClasses = React.addons.classSet({
|
||||
'tab': true,
|
||||
'active': this.state.page === this.PAGE_SETTINGS,
|
||||
disabled: this.disableTab()
|
||||
});
|
||||
|
||||
/*var ports = _.map(_.pairs(self.state.ports), function (pair, index, list) {
|
||||
var key = pair[0];
|
||||
var val = pair[1];
|
||||
return (
|
||||
<div key={key} className="table-values">
|
||||
<span className="value-left">{key}</span><span className="icon icon-arrow-right"></span>
|
||||
<a className="value-right" onClick={self.handleViewLink.bind(self, val.url)}>{val.display}</a>
|
||||
<input onChange={self.handleChangeDefaultPort.bind(self, key)} type="checkbox" checked={self.state.defaultPort === key}/> <label>Default</label>
|
||||
</div>
|
||||
);
|
||||
});
|
||||
|
||||
var volumes = _.map(self.props.container.Volumes, function (val, key) {
|
||||
if (!val || val.indexOf(process.env.HOME) === -1) {
|
||||
val = <span>No folder<a className="btn btn-primary btn-xs" onClick={self.handleChooseVolumeClick.bind(self, key)}>Choose</a></span>;
|
||||
} else {
|
||||
val = <span><a className="value-right" onClick={self.handleOpenVolumeClick.bind(self, val)}>{val.replace(process.env.HOME, '~')}</a> <a className="btn btn-primary btn-xs" onClick={self.handleChooseVolumeClick.bind(self, key)}>Choose</a></span>;
|
||||
}
|
||||
return (
|
||||
<div key={key} className="table-values">
|
||||
<span className="value-left">{key}</span><span className="icon icon-arrow-right"></span>
|
||||
{val}
|
||||
</div>
|
||||
);
|
||||
});*/
|
||||
|
||||
/* var view;
|
||||
if (this.state.defaultPort) {
|
||||
view = (
|
||||
<div className="action btn-group">
|
||||
<a className={viewButtonClass} onClick={this.handleView}><span className="icon icon-preview-2"></span><span className="content">View</span></a>
|
||||
<a className={dropdownViewButtonClass} onClick={this.handleViewDropdown}><span className="icon-dropdown icon icon-arrow-37"></span></a>
|
||||
</div>
|
||||
);
|
||||
} else {
|
||||
view = (
|
||||
<div className="action">
|
||||
<a className={dropdownViewButtonClass} onClick={this.handleViewDropdown}><span className="icon icon-preview-2"></span> <span className="content">Ports</span> <span className="icon-dropdown icon icon-arrow-37"></span></a>
|
||||
</div>
|
||||
);
|
||||
}*/
|
||||
|
||||
var runActionClass = React.addons.classSet({
|
||||
action: true,
|
||||
disabled: this.disableRun()
|
||||
});
|
||||
|
||||
var restartActionClass = React.addons.classSet({
|
||||
action: true,
|
||||
disabled: this.disableRestart()
|
||||
});
|
||||
|
||||
var terminalActionClass = React.addons.classSet({
|
||||
action: true,
|
||||
disabled: this.disableTerminal()
|
||||
});
|
||||
|
||||
return (
|
||||
<div className="details">
|
||||
<ContainerDetailsHeader container={this.props.container} />
|
||||
<div className="details-subheader">
|
||||
<div className="details-header-actions">
|
||||
<div className={runActionClass} onMouseEnter={this.handleItemMouseEnterRun} onMouseLeave={this.handleItemMouseLeaveRun}>
|
||||
<span className="action-icon" onClick={this.handleRun}><RetinaImage src="button-run.png"/></span>
|
||||
<span className="btn-label run">Run</span>
|
||||
</div>
|
||||
<div className={restartActionClass} onMouseEnter={this.handleItemMouseEnterRestart} onMouseLeave={this.handleItemMouseLeaveRestart}>
|
||||
<span className="action-icon" onClick={this.handleRestart}><RetinaImage src="button-restart.png"/></span>
|
||||
<span className="btn-label restart">Restart</span>
|
||||
</div>
|
||||
<div className={terminalActionClass} onMouseEnter={this.handleItemMouseEnterTerminal} onMouseLeave={this.handleItemMouseLeaveTerminal}>
|
||||
<span className="action-icon" onClick={this.handleTerminal}><RetinaImage src="button-terminal.png"/></span>
|
||||
<span className="btn-label terminal">Terminal</span>
|
||||
</div>
|
||||
</div>
|
||||
<div className="details-subheader-tabs">
|
||||
<span className={tabHomeClasses} onClick={this.showHome}>Home</span>
|
||||
<span className={tabLogsClasses} onClick={this.showLogs}>Logs</span>
|
||||
<span className={tabSettingsClasses} onClick={this.showSettings}>Settings</span>
|
||||
</div>
|
||||
</div>
|
||||
{body}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
module.exports = ContainerDetailsbak;
|
|
@ -90,7 +90,7 @@ var ContainerHome = React.createClass({
|
|||
<ContainerHomePreview />
|
||||
</div>
|
||||
<div className="right">
|
||||
<ContainerHomeLogs />
|
||||
<ContainerHomeLogs/>
|
||||
<ContainerHomeFolders container={this.props.container} />
|
||||
</div>
|
||||
</div>
|
||||
|
@ -116,7 +116,7 @@ var ContainerHome = React.createClass({
|
|||
<div className="details-panel home">
|
||||
<div className="content">
|
||||
<div className="left">
|
||||
<ContainerHomeLogs />
|
||||
<ContainerHomeLogs/>
|
||||
</div>
|
||||
{right}
|
||||
</div>
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
var $ = require('jquery');
|
||||
var React = require('react/addons');
|
||||
var ContainerStore = require('./ContainerStore');
|
||||
var LogStore = require('./LogStore');
|
||||
var Router = require('react-router');
|
||||
|
||||
var ContainerHomeLogs = React.createClass({
|
||||
|
@ -15,10 +15,10 @@ var ContainerHomeLogs = React.createClass({
|
|||
},
|
||||
componentDidMount: function() {
|
||||
this.init();
|
||||
ContainerStore.on(ContainerStore.SERVER_LOGS_EVENT, this.updateLogs);
|
||||
LogStore.on(LogStore.SERVER_LOGS_EVENT, this.updateLogs);
|
||||
},
|
||||
componentWillUnmount: function() {
|
||||
ContainerStore.removeListener(ContainerStore.SERVER_LOGS_EVENT, this.updateLogs);
|
||||
LogStore.removeListener(LogStore.SERVER_LOGS_EVENT, this.updateLogs);
|
||||
},
|
||||
componentDidUpdate: function () {
|
||||
// Scroll logs to bottom
|
||||
|
@ -39,7 +39,7 @@ var ContainerHomeLogs = React.createClass({
|
|||
return;
|
||||
}
|
||||
this.setState({
|
||||
logs: ContainerStore.logs(this.getParams().name)
|
||||
logs: LogStore.logs(this.getParams().name)
|
||||
});
|
||||
},
|
||||
handleClickLogs: function () {
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
var _ = require('underscore');
|
||||
var $ = require('jquery');
|
||||
var React = require('react/addons');
|
||||
var Router = require('react-router');
|
||||
|
@ -34,19 +33,7 @@ var ContainerListItem = React.createClass({
|
|||
render: function () {
|
||||
var self = this;
|
||||
var container = this.props.container;
|
||||
var downloadingImage = null, downloading = false;
|
||||
var env = container.Config.Env;
|
||||
if (env.length) {
|
||||
var obj = _.object(env.map(function (e) {
|
||||
return e.split('=');
|
||||
}));
|
||||
if (obj.KITEMATIC_DOWNLOADING) {
|
||||
downloading = true;
|
||||
}
|
||||
downloadingImage = obj.KITEMATIC_DOWNLOADING_IMAGE || null;
|
||||
}
|
||||
|
||||
var imageName = downloadingImage || container.Config.Image;
|
||||
var imageName = container.Config.Image;
|
||||
|
||||
// Synchronize all animations
|
||||
var style = {
|
||||
|
@ -54,7 +41,7 @@ var ContainerListItem = React.createClass({
|
|||
};
|
||||
|
||||
var state;
|
||||
if (downloading) {
|
||||
if (container.State.Downloading) {
|
||||
state = <div className="state state-downloading"><div style={style} className="downloading-arrow"></div></div>;
|
||||
} else if (container.State.Running && !container.State.Paused) {
|
||||
state = <div className="state state-running"><div style={style} className="runningwave"></div></div>;
|
||||
|
@ -70,7 +57,7 @@ var ContainerListItem = React.createClass({
|
|||
}
|
||||
|
||||
return (
|
||||
<Router.Link data-container={name} to="containerDetail" params={{name: container.Name}}>
|
||||
<Router.Link data-container={name} to="containerDetails" params={{name: container.Name}}>
|
||||
<li onMouseEnter={self.handleItemMouseEnter} onMouseLeave={self.handleItemMouseLeave}>
|
||||
{state}
|
||||
<div className="info">
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
var $ = require('jquery');
|
||||
var React = require('react/addons');
|
||||
var ContainerStore = require('./ContainerStore');
|
||||
var LogStore = require('./LogStore');
|
||||
var Router = require('react-router');
|
||||
|
||||
var ContainerLogs = React.createClass({
|
||||
|
@ -15,10 +15,10 @@ var ContainerLogs = React.createClass({
|
|||
},
|
||||
componentDidMount: function() {
|
||||
this.init();
|
||||
ContainerStore.on(ContainerStore.SERVER_LOGS_EVENT, this.updateLogs);
|
||||
LogStore.on(LogStore.SERVER_LOGS_EVENT, this.updateLogs);
|
||||
},
|
||||
componentWillUnmount: function() {
|
||||
ContainerStore.removeListener(ContainerStore.SERVER_LOGS_EVENT, this.updateLogs);
|
||||
LogStore.removeListener(LogStore.SERVER_LOGS_EVENT, this.updateLogs);
|
||||
},
|
||||
componentDidUpdate: function () {
|
||||
// Scroll logs to bottom
|
||||
|
@ -39,7 +39,7 @@ var ContainerLogs = React.createClass({
|
|||
return;
|
||||
}
|
||||
this.setState({
|
||||
logs: ContainerStore.logs(this.getParams().name)
|
||||
logs: LogStore.logs(this.getParams().name)
|
||||
});
|
||||
},
|
||||
render: function () {
|
||||
|
|
|
@ -1,48 +1,20 @@
|
|||
var $ = require('jquery');
|
||||
var _ = require('underscore');
|
||||
var EventEmitter = require('events').EventEmitter;
|
||||
var async = require('async');
|
||||
var path = require('path');
|
||||
var assign = require('object-assign');
|
||||
var Convert = require('ansi-to-html');
|
||||
var docker = require('./Docker');
|
||||
var registry = require('./Registry');
|
||||
var ContainerUtil = require('./ContainerUtil');
|
||||
|
||||
var convert = new Convert();
|
||||
var _recommended = [];
|
||||
var _placeholders = {};
|
||||
var _containers = {};
|
||||
var _progress = {};
|
||||
var _logs = {};
|
||||
var _streams = {};
|
||||
var _muted = {};
|
||||
|
||||
var ContainerStore = assign(Object.create(EventEmitter.prototype), {
|
||||
CLIENT_CONTAINER_EVENT: 'client_container_event',
|
||||
CLIENT_RECOMMENDED_EVENT: 'client_recommended_event',
|
||||
SERVER_CONTAINER_EVENT: 'server_container_event',
|
||||
SERVER_PROGRESS_EVENT: 'server_progress_event',
|
||||
SERVER_LOGS_EVENT: 'server_logs_event',
|
||||
_pullScratchImage: function (callback) {
|
||||
var image = docker.client().getImage('scratch:latest');
|
||||
image.inspect(function (err, data) {
|
||||
if (!data) {
|
||||
docker.client().pull('scratch:latest', function (err, stream) {
|
||||
if (err) {
|
||||
callback(err);
|
||||
return;
|
||||
}
|
||||
stream.setEncoding('utf8');
|
||||
stream.on('data', function () {});
|
||||
stream.on('end', function () {
|
||||
callback();
|
||||
});
|
||||
});
|
||||
} else {
|
||||
callback();
|
||||
}
|
||||
});
|
||||
},
|
||||
_pullImage: function (repository, tag, callback, progressCallback) {
|
||||
registry.layers(repository, tag, function (err, layerSizes) {
|
||||
|
||||
|
@ -89,7 +61,7 @@ var ContainerStore = assign(Object.create(EventEmitter.prototype), {
|
|||
|
||||
var totalReceived = chunks.reduce(function (pv, sv) {
|
||||
return pv + sv;
|
||||
});
|
||||
}, 0);
|
||||
|
||||
var totalProgress = totalReceived / totalBytes;
|
||||
progressCallback(totalProgress);
|
||||
|
@ -101,12 +73,6 @@ var ContainerStore = assign(Object.create(EventEmitter.prototype), {
|
|||
});
|
||||
});
|
||||
},
|
||||
_escapeHTML: function (html) {
|
||||
var text = document.createTextNode(html);
|
||||
var div = document.createElement('div');
|
||||
div.appendChild(text);
|
||||
return div.innerHTML;
|
||||
},
|
||||
_createContainer: function (name, containerData, callback) {
|
||||
var existing = docker.client().getContainer(name);
|
||||
var self = this;
|
||||
|
@ -118,14 +84,8 @@ var ContainerStore = assign(Object.create(EventEmitter.prototype), {
|
|||
if (containerData.Config && containerData.Config.Image) {
|
||||
containerData.Image = containerData.Config.Image;
|
||||
}
|
||||
existing.kill(function (err) {
|
||||
if (err) {
|
||||
console.log(err);
|
||||
}
|
||||
existing.remove(function (err) {
|
||||
if (err) {
|
||||
console.log(err);
|
||||
}
|
||||
existing.kill(function () {
|
||||
existing.remove(function () {
|
||||
docker.client().getImage(containerData.Image).inspect(function (err, data) {
|
||||
if (err) {
|
||||
callback(err);
|
||||
|
@ -161,31 +121,6 @@ var ContainerStore = assign(Object.create(EventEmitter.prototype), {
|
|||
});
|
||||
});
|
||||
},
|
||||
_createPlaceholderContainer: function (imageName, name, callback) {
|
||||
var self = this;
|
||||
this._pullScratchImage(function (err) {
|
||||
if (err) {
|
||||
callback(err);
|
||||
return;
|
||||
}
|
||||
docker.client().createContainer({
|
||||
Image: 'scratch:latest',
|
||||
Tty: false,
|
||||
Env: [
|
||||
'KITEMATIC_DOWNLOADING=true',
|
||||
'KITEMATIC_DOWNLOADING_IMAGE=' + imageName
|
||||
],
|
||||
Cmd: 'placeholder',
|
||||
name: name
|
||||
}, function (err) {
|
||||
if (err) {
|
||||
callback(err);
|
||||
return;
|
||||
}
|
||||
self.fetchContainer(name, callback);
|
||||
});
|
||||
});
|
||||
},
|
||||
_generateName: function (repository) {
|
||||
var base = _.last(repository.split('/'));
|
||||
var count = 1;
|
||||
|
@ -201,18 +136,22 @@ var ContainerStore = assign(Object.create(EventEmitter.prototype), {
|
|||
}
|
||||
},
|
||||
_resumePulling: function () {
|
||||
var downloading = _.filter(_.values(_containers), function (container) {
|
||||
var downloading = _.filter(_.values(this.containers()), function (container) {
|
||||
return container.State.Downloading;
|
||||
});
|
||||
|
||||
// Recover any pulls that were happening
|
||||
var self = this;
|
||||
downloading.forEach(function (container) {
|
||||
docker.client().pull(container.KitematicDownloadingImage, function (err, stream) {
|
||||
docker.client().pull(container.Config.Image, function (err, stream) {
|
||||
delete _placeholders[container.Name];
|
||||
localStorage.setItem('store.placeholders', JSON.stringify(_placeholders));
|
||||
stream.setEncoding('utf8');
|
||||
stream.on('data', function () {});
|
||||
stream.on('end', function () {
|
||||
self._createContainer(container.Name, {Image: container.KitematicDownloadingImage}, function () {});
|
||||
self._createContainer(container.Name, {Image: container.Config.Image}, function () {
|
||||
self.emit(self.CLIENT_CONTAINER_EVENT, container.Name);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -262,13 +201,18 @@ var ContainerStore = assign(Object.create(EventEmitter.prototype), {
|
|||
} else {
|
||||
callback();
|
||||
}
|
||||
var placeholderData = JSON.parse(localStorage.getItem('store.placeholders'));
|
||||
console.log(placeholderData);
|
||||
console.log(_.keys(_containers));
|
||||
if (placeholderData) {
|
||||
_placeholders = _.omit(placeholderData, _.keys(_containers));
|
||||
localStorage.setItem('store.placeholders', JSON.stringify(_placeholders));
|
||||
}
|
||||
console.log(_placeholders);
|
||||
this.emit(this.CLIENT_CONTAINER_EVENT);
|
||||
this._resumePulling();
|
||||
this._startListeningToEvents();
|
||||
}.bind(this));
|
||||
this.fetchRecommended(function () {
|
||||
this.emit(this.CLIENT_RECOMMENDED_EVENT);
|
||||
}.bind(this));
|
||||
},
|
||||
fetchContainer: function (id, callback) {
|
||||
docker.client().getContainer(id).inspect(function (err, container) {
|
||||
|
@ -281,15 +225,6 @@ var ContainerStore = assign(Object.create(EventEmitter.prototype), {
|
|||
}
|
||||
// Fix leading slash in container names
|
||||
container.Name = container.Name.replace('/', '');
|
||||
|
||||
// Add Downloading State (stored in environment variables) to containers for Kitematic
|
||||
var env = ContainerUtil.env(container);
|
||||
container.State.Downloading = !!env.KITEMATIC_DOWNLOADING;
|
||||
container.KitematicDownloadingImage = env.KITEMATIC_DOWNLOADING_IMAGE;
|
||||
|
||||
this.fetchLogs(container.Name, function () {
|
||||
}.bind(this));
|
||||
|
||||
_containers[container.Name] = container;
|
||||
callback(null, container);
|
||||
}
|
||||
|
@ -311,103 +246,42 @@ var ContainerStore = assign(Object.create(EventEmitter.prototype), {
|
|||
});
|
||||
});
|
||||
},
|
||||
fetchRecommended: function (callback) {
|
||||
if (_recommended.length) {
|
||||
return;
|
||||
}
|
||||
$.ajax({
|
||||
url: 'https://kitematic.com/recommended.json',
|
||||
cache: false,
|
||||
dataType: 'json',
|
||||
success: function (res) {
|
||||
var recommended = res.repos;
|
||||
async.map(recommended, function (rec, callback) {
|
||||
$.get('https://registry.hub.docker.com/v1/search?q=' + rec.repo, function (data) {
|
||||
var results = data.results;
|
||||
var result = _.find(results, function (r) {
|
||||
return r.name === rec.repo;
|
||||
});
|
||||
callback(null, _.extend(result, rec));
|
||||
});
|
||||
}, function (err, results) {
|
||||
_recommended = results.filter(function(r) { return !!r; });
|
||||
callback();
|
||||
});
|
||||
},
|
||||
error: function (err) {
|
||||
console.log(err);
|
||||
}
|
||||
});
|
||||
},
|
||||
fetchLogs: function (name, callback) {
|
||||
var index = 0;
|
||||
var self = this;
|
||||
docker.client().getContainer(name).logs({
|
||||
follow: true,
|
||||
stdout: true,
|
||||
stderr: true,
|
||||
timestamps: true
|
||||
}, function (err, stream) {
|
||||
callback(err);
|
||||
if (_streams[name]) {
|
||||
return;
|
||||
}
|
||||
_streams[name] = stream;
|
||||
if (err) {
|
||||
return;
|
||||
}
|
||||
_logs[name] = [];
|
||||
stream.setEncoding('utf8');
|
||||
var timeout;
|
||||
stream.on('data', function (buf) {
|
||||
// Every other message is a header
|
||||
if (index % 2 === 1) {
|
||||
//var time = buf.substr(0,buf.indexOf(' '));
|
||||
var msg = buf.substr(buf.indexOf(' ')+1);
|
||||
if (timeout) {
|
||||
clearTimeout(timeout);
|
||||
timeout = null;
|
||||
}
|
||||
timeout = setTimeout(function () {
|
||||
timeout = null;
|
||||
self.emit(self.SERVER_LOGS_EVENT, name);
|
||||
}, 100);
|
||||
_logs[name].push(convert.toHtml(self._escapeHTML(msg)));
|
||||
}
|
||||
index += 1;
|
||||
});
|
||||
stream.on('end', function () {
|
||||
delete _streams[name];
|
||||
});
|
||||
});
|
||||
},
|
||||
create: function (repository, tag, callback) {
|
||||
tag = tag || 'latest';
|
||||
var self = this;
|
||||
var imageName = repository + ':' + tag;
|
||||
var containerName = this._generateName(repository);
|
||||
// Pull image
|
||||
self._createPlaceholderContainer(imageName, containerName, function (err, container) {
|
||||
if (err) {
|
||||
callback(err);
|
||||
return;
|
||||
|
||||
_placeholders[containerName] = {
|
||||
Name: containerName,
|
||||
Image: imageName,
|
||||
Config: {
|
||||
Image: imageName,
|
||||
},
|
||||
State: {
|
||||
Downloading: true
|
||||
}
|
||||
_containers[containerName] = container;
|
||||
self.emit(self.CLIENT_CONTAINER_EVENT, containerName, 'create');
|
||||
_muted[containerName] = true;
|
||||
_progress[containerName] = 0;
|
||||
self._pullImage(repository, tag, function () {
|
||||
self._createContainer(containerName, {Image: imageName}, function () {
|
||||
delete _progress[containerName];
|
||||
_muted[containerName] = false;
|
||||
self.emit(self.CLIENT_CONTAINER_EVENT, containerName);
|
||||
});
|
||||
}, function (progress) {
|
||||
_progress[containerName] = progress;
|
||||
self.emit(self.SERVER_PROGRESS_EVENT, containerName);
|
||||
};
|
||||
console.log(_placeholders);
|
||||
console.log(JSON.stringify(_placeholders));
|
||||
localStorage.setItem('store.placeholders', JSON.stringify(_placeholders));
|
||||
self.emit(self.CLIENT_CONTAINER_EVENT, containerName, 'create');
|
||||
|
||||
_muted[containerName] = true;
|
||||
_progress[containerName] = 0;
|
||||
self._pullImage(repository, tag, function () {
|
||||
delete _placeholders[containerName];
|
||||
localStorage.setItem('store.placeholders', JSON.stringify(_placeholders));
|
||||
self._createContainer(containerName, {Image: imageName}, function () {
|
||||
delete _progress[containerName];
|
||||
_muted[containerName] = false;
|
||||
self.emit(self.CLIENT_CONTAINER_EVENT, containerName);
|
||||
});
|
||||
callback(null, containerName);
|
||||
}, function (progress) {
|
||||
_progress[containerName] = progress;
|
||||
self.emit(self.SERVER_PROGRESS_EVENT, containerName);
|
||||
});
|
||||
callback(null, containerName);
|
||||
},
|
||||
updateContainer: function (name, data, callback) {
|
||||
_muted[name] = true;
|
||||
|
@ -428,6 +302,10 @@ var ContainerStore = assign(Object.create(EventEmitter.prototype), {
|
|||
});
|
||||
},
|
||||
remove: function (name, callback) {
|
||||
if (_placeholders[name]) {
|
||||
delete _placeholders[name];
|
||||
return;
|
||||
}
|
||||
var container = docker.client().getContainer(name);
|
||||
if (_containers[name].State.Paused) {
|
||||
container.unpause(function (err) {
|
||||
|
@ -464,25 +342,19 @@ var ContainerStore = assign(Object.create(EventEmitter.prototype), {
|
|||
}
|
||||
},
|
||||
containers: function() {
|
||||
return _containers;
|
||||
return _.extend(_containers, _placeholders);
|
||||
},
|
||||
container: function (name) {
|
||||
return _containers[name];
|
||||
return this.containers()[name];
|
||||
},
|
||||
sorted: function () {
|
||||
return _.values(_containers).sort(function (a, b) {
|
||||
return _.values(this.containers()).sort(function (a, b) {
|
||||
return a.Name.localeCompare(b.Name);
|
||||
});
|
||||
},
|
||||
recommended: function () {
|
||||
return _recommended;
|
||||
},
|
||||
progress: function (name) {
|
||||
return _progress[name];
|
||||
},
|
||||
logs: function (name) {
|
||||
return _logs[name] || [];
|
||||
}
|
||||
});
|
||||
|
||||
module.exports = ContainerStore;
|
||||
|
|
|
@ -13,6 +13,9 @@ var ContainerUtil = {
|
|||
}));
|
||||
},
|
||||
ports: function (container) {
|
||||
if (!container.NetworkSettings) {
|
||||
return {};
|
||||
}
|
||||
var res = {};
|
||||
var ip = docker.host;
|
||||
_.each(container.NetworkSettings.Ports, function (value, key) {
|
||||
|
|
|
@ -0,0 +1,70 @@
|
|||
var EventEmitter = require('events').EventEmitter;
|
||||
var assign = require('object-assign');
|
||||
var Convert = require('ansi-to-html');
|
||||
var docker = require('./Docker');
|
||||
|
||||
var _convert = new Convert();
|
||||
var _logs = {};
|
||||
var _streams = {};
|
||||
|
||||
var LogStore = assign(Object.create(EventEmitter.prototype), {
|
||||
SERVER_LOGS_EVENT: 'server_logs_event',
|
||||
_escapeHTML: function (html) {
|
||||
var text = document.createTextNode(html);
|
||||
var div = document.createElement('div');
|
||||
div.appendChild(text);
|
||||
return div.innerHTML;
|
||||
},
|
||||
fetchLogs: function (name) {
|
||||
if (!name || !docker.client()) {
|
||||
return;
|
||||
}
|
||||
var index = 0;
|
||||
var self = this;
|
||||
docker.client().getContainer(name).logs({
|
||||
follow: true,
|
||||
stdout: true,
|
||||
stderr: true,
|
||||
timestamps: true
|
||||
}, function (err, stream) {
|
||||
if (_streams[name]) {
|
||||
return;
|
||||
}
|
||||
_streams[name] = stream;
|
||||
if (err) {
|
||||
return;
|
||||
}
|
||||
_logs[name] = [];
|
||||
stream.setEncoding('utf8');
|
||||
var timeout;
|
||||
stream.on('data', function (buf) {
|
||||
// Every other message is a header
|
||||
if (index % 2 === 1) {
|
||||
//var time = buf.substr(0,buf.indexOf(' '));
|
||||
var msg = buf.substr(buf.indexOf(' ')+1);
|
||||
if (timeout) {
|
||||
clearTimeout(timeout);
|
||||
timeout = null;
|
||||
}
|
||||
timeout = setTimeout(function () {
|
||||
timeout = null;
|
||||
self.emit(self.SERVER_LOGS_EVENT, name);
|
||||
}, 100);
|
||||
_logs[name].push(_convert.toHtml(self._escapeHTML(msg)));
|
||||
}
|
||||
index += 1;
|
||||
});
|
||||
stream.on('end', function () {
|
||||
delete _streams[name];
|
||||
});
|
||||
});
|
||||
},
|
||||
logs: function (name) {
|
||||
if (!_streams[name]) {
|
||||
this.fetchLogs(name);
|
||||
}
|
||||
return _logs[name] || [];
|
||||
}
|
||||
});
|
||||
|
||||
module.exports = LogStore;
|
32
src/Main.js
32
src/Main.js
|
@ -33,26 +33,14 @@ bugsnag.notifyReleaseStages = ['production'];
|
|||
bugsnag.appVersion = app.getVersion();
|
||||
|
||||
router.run(Handler => React.render(<Handler/>, document.body));
|
||||
if (!window.location.hash.length || window.location.hash === '#/') {
|
||||
SetupStore.run().then(boot2docker.ip).then(ip => {
|
||||
console.log(ip);
|
||||
docker.setHost(ip);
|
||||
ContainerStore.init(function (err) {
|
||||
if (err) { console.log(err); }
|
||||
router.transitionTo('containers');
|
||||
});
|
||||
}).catch(err => {
|
||||
bugsnag.notify(err);
|
||||
SetupStore.run().then(boot2docker.ip).then(ip => {
|
||||
console.log(ip);
|
||||
docker.setHost(ip);
|
||||
ContainerStore.init(function (err) {
|
||||
if (err) { console.log(err); }
|
||||
router.transitionTo('containers');
|
||||
});
|
||||
} else {
|
||||
console.log('Skipping installer.');
|
||||
router.transitionTo('containers');
|
||||
boot2docker.ip().then(ip => {
|
||||
docker.setHost(ip);
|
||||
ContainerStore.init(function (err) {
|
||||
if (err) { console.log(err); }
|
||||
});
|
||||
}).catch(err => {
|
||||
bugsnag.notify(err);
|
||||
});
|
||||
}
|
||||
}).catch(err => {
|
||||
console.log(err);
|
||||
bugsnag.notify(err);
|
||||
});
|
||||
|
|
|
@ -1,17 +1,20 @@
|
|||
var _ = require('underscore');
|
||||
var $ = require('jquery');
|
||||
var React = require('react/addons');
|
||||
var RetinaImage = require('react-retina-image');
|
||||
var ContainerStore = require('./ContainerStore');
|
||||
var Radial = require('./Radial.react');
|
||||
var ImageCard = require('./ImageCard.react');
|
||||
var Promise = require('bluebird');
|
||||
|
||||
var _recommended = [];
|
||||
|
||||
var NewContainer = React.createClass({
|
||||
_searchRequest: null,
|
||||
getInitialState: function () {
|
||||
return {
|
||||
query: '',
|
||||
results: [],
|
||||
loading: false
|
||||
loading: false,
|
||||
results: _recommended
|
||||
};
|
||||
},
|
||||
componentDidMount: function () {
|
||||
|
@ -19,14 +22,8 @@ var NewContainer = React.createClass({
|
|||
creating: []
|
||||
});
|
||||
this.refs.searchInput.getDOMNode().focus();
|
||||
ContainerStore.on(ContainerStore.CLIENT_RECOMMENDED_EVENT, this.update);
|
||||
this.update();
|
||||
},
|
||||
update: function () {
|
||||
if (!this.state.query.length) {
|
||||
this.setState({
|
||||
results: ContainerStore.recommended()
|
||||
});
|
||||
if (!_recommended.length) {
|
||||
this.recommended();
|
||||
}
|
||||
},
|
||||
search: function (query) {
|
||||
|
@ -55,6 +52,40 @@ var NewContainer = React.createClass({
|
|||
}
|
||||
});
|
||||
},
|
||||
recommended: function () {
|
||||
if (this._searchRequest) {
|
||||
this._searchRequest.abort();
|
||||
this._searchRequest = null;
|
||||
}
|
||||
|
||||
if (_recommended.length) {
|
||||
return;
|
||||
}
|
||||
Promise.resolve($.ajax({
|
||||
url: 'https://kitematic.com/recommended.json',
|
||||
cache: false,
|
||||
dataType: 'json',
|
||||
})).then(res => res.repos).map(repo => {
|
||||
return $.get('https://registry.hub.docker.com/v1/search?q=' + repo.repo).then(data => {
|
||||
var results = data.results;
|
||||
var result = _.find(results, function (r) {
|
||||
return r.name === repo.repo;
|
||||
});
|
||||
return _.extend(result, repo);
|
||||
});
|
||||
}).then(results => {
|
||||
_recommended = results.filter(r => !!r);
|
||||
if (!this.state.query.length) {
|
||||
if (this.isMounted()) {
|
||||
this.setState({
|
||||
results: _recommended
|
||||
});
|
||||
}
|
||||
}
|
||||
}).catch(err => {
|
||||
console.log(err);
|
||||
});
|
||||
},
|
||||
handleChange: function (e) {
|
||||
var query = e.target.value;
|
||||
|
||||
|
@ -66,7 +97,7 @@ var NewContainer = React.createClass({
|
|||
if (!query.length) {
|
||||
this.setState({
|
||||
query: query,
|
||||
results: ContainerStore.recommended()
|
||||
results: _recommended
|
||||
});
|
||||
} else {
|
||||
var self = this;
|
||||
|
|
|
@ -27,7 +27,7 @@ var App = React.createClass({
|
|||
var routes = (
|
||||
<Route name="app" path="/" handler={App}>
|
||||
<Route name="containers" handler={Containers}>
|
||||
<Route name="containerDetail" path="/containers/:name" handler={ContainerDetails}>
|
||||
<Route name="containerDetails" path="/containers/:name" handler={ContainerDetails}>
|
||||
<Route name="containerHome" path="/containers/:name/home" handler={ContainerHome} />
|
||||
<Route name="containerLogs" path="/containers/:name/logs" handler={ContainerLogs}/>
|
||||
<Route name="containerSettings" path="/containers/:name/settings" handler={ContainerSettings}>
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
var EventEmitter = require('events').EventEmitter;
|
||||
var _ = require('underscore');
|
||||
var path = require('path');
|
||||
var fs = require('fs');
|
||||
var Promise = require('bluebird');
|
||||
var boot2docker = require('./Boot2Docker');
|
||||
var virtualBox = require('./VirtualBox');
|
||||
|
@ -20,13 +21,12 @@ var _steps = [{
|
|||
message: 'VirtualBox is being downloaded. Kitematic requires VirtualBox to run containers.',
|
||||
totalPercent: 35,
|
||||
percent: 0,
|
||||
run: Promise.coroutine(function* (progressCallback) {
|
||||
run: function (progressCallback) {
|
||||
var packagejson = util.packagejson();
|
||||
var virtualBoxFile = `https://github.com/kitematic/virtualbox/releases/download/${packagejson['virtualbox-version']}/${packagejson['virtualbox-filename']}`;
|
||||
yield setupUtil.download(virtualBoxFile, path.join(util.supportDir(), packagejson['virtualbox-filename']), packagejson['virtualbox-checksum'], percent => {
|
||||
return setupUtil.download(setupUtil.virtualBoxUrl(), path.join(util.supportDir(), packagejson['virtualbox-filename']), packagejson['virtualbox-checksum'], percent => {
|
||||
progressCallback(percent);
|
||||
});
|
||||
})
|
||||
}
|
||||
}, {
|
||||
name: 'install',
|
||||
title: 'Installing Docker & VirtualBox',
|
||||
|
@ -34,18 +34,16 @@ var _steps = [{
|
|||
totalPercent: 5,
|
||||
percent: 0,
|
||||
seconds: 5,
|
||||
run: Promise.coroutine(function* () {
|
||||
run: Promise.coroutine(function* (progressCallback) {
|
||||
var packagejson = util.packagejson();
|
||||
var base = util.copyBinariesCmd() + ' && ' + util.fixBinariesCmd();
|
||||
var cmd = util.copyBinariesCmd() + ' && ' + util.fixBinariesCmd();
|
||||
if (!virtualBox.installed() || setupUtil.compareVersions(yield virtualBox.version(), packagejson['virtualbox-required-version']) < 0) {
|
||||
yield virtualBox.killall();
|
||||
base += ` && installer -pkg ${util.escapePath(path.join(util.supportDir(), packagejson['virtualbox-filename']))} -target /`;
|
||||
cmd += ' && ' + setupUtil.installVirtualBoxCmd();
|
||||
}
|
||||
console.log(base);
|
||||
var cmd = `${util.escapePath(path.join(util.resourceDir(), 'cocoasudo'))} --prompt="Kitematic requires administrative privileges to install VirtualBox." sudo -u root bash -c \"${base}\"`;
|
||||
try {
|
||||
var stdout = yield util.exec(cmd);
|
||||
console.log(stdout);
|
||||
progressCallback(50); // TODO: detect when the installation has started so we can simulate progress
|
||||
yield util.exec(setupUtil.macSudoCmd(cmd));
|
||||
} catch (err) {
|
||||
throw null;
|
||||
}
|
||||
|
@ -132,12 +130,16 @@ var SetupStore = assign(Object.create(EventEmitter.prototype), {
|
|||
_retryPromise = Promise.defer();
|
||||
return _retryPromise.promise;
|
||||
},
|
||||
init: Promise.coroutine(function* () {
|
||||
requiredSteps: Promise.coroutine(function* () {
|
||||
if (_requiredSteps.length) {
|
||||
return Promise.resolve(_requiredSteps);
|
||||
}
|
||||
var packagejson = util.packagejson();
|
||||
var isoversion = boot2docker.isoversion();
|
||||
var required = {};
|
||||
required.download = !virtualBox.installed() || setupUtil.compareVersions(yield virtualBox.version(), packagejson['virtualbox-required-version']) < 0;
|
||||
required.install = required.download || setupUtil.needsBinaryFix();
|
||||
var vboxfile = path.join(util.supportDir(), packagejson['virtualbox-filename']);
|
||||
required.download = !virtualBox.installed() && (!fs.existsSync(vboxfile) || setupUtil.checksum(vboxfile) !== packagejson['virtualbox-checksum']);
|
||||
required.install = !virtualBox.installed() || setupUtil.needsBinaryFix();
|
||||
required.init = !(yield boot2docker.exists()) || !isoversion || setupUtil.compareVersions(isoversion, boot2docker.version()) < 0;
|
||||
required.start = required.init || (yield boot2docker.status()) !== 'running';
|
||||
|
||||
|
@ -149,6 +151,7 @@ var SetupStore = assign(Object.create(EventEmitter.prototype), {
|
|||
_requiredSteps = _steps.filter(function (step) {
|
||||
return required[step.name];
|
||||
});
|
||||
return Promise.resolve(_requiredSteps);
|
||||
}),
|
||||
updateBinaries: function () {
|
||||
if (setupUtil.needsBinaryFix()) {
|
||||
|
@ -160,9 +163,11 @@ var SetupStore = assign(Object.create(EventEmitter.prototype), {
|
|||
return Promise.resolve();
|
||||
},
|
||||
run: Promise.coroutine(function* () {
|
||||
yield this.init();
|
||||
yield this.updateBinaries();
|
||||
for (let step of _requiredSteps) {
|
||||
var steps = yield this.requiredSteps();
|
||||
console.log(steps);
|
||||
for (let step of steps) {
|
||||
console.log(step.name);
|
||||
_currentStep = step;
|
||||
step.percent = 0;
|
||||
while (true) {
|
||||
|
|
|
@ -29,6 +29,17 @@ var SetupUtil = {
|
|||
this.checksum('/usr/local/bin/boot2docker') !== this.checksum(path.join(util.resourceDir(), 'boot2docker-' + packagejson['boot2docker-version'])) ||
|
||||
this.checksum('/usr/local/bin/docker') !== this.checksum(path.join(util.resourceDir(), 'docker-' + packagejson['docker-version']));
|
||||
},
|
||||
installVirtualBoxCmd: function () {
|
||||
var packagejson = util.packagejson();
|
||||
return `installer -pkg ${util.escapePath(path.join(util.supportDir(), packagejson['virtualbox-filename']))} -target /`;
|
||||
},
|
||||
virtualBoxUrl: function () {
|
||||
var packagejson = util.packagejson();
|
||||
return `https://github.com/kitematic/virtualbox/releases/download/${packagejson['virtualbox-version']}/${packagejson['virtualbox-filename']}`;
|
||||
},
|
||||
macSudoCmd: function (cmd) {
|
||||
return `${util.escapePath(path.join(util.resourceDir(), 'macsudo'))} -p "Kitematic requires administrative privileges to install VirtualBox." sh -c \"${cmd}\"`;
|
||||
},
|
||||
simulateProgress: function (estimateSeconds, progress) {
|
||||
var times = _.range(0, estimateSeconds * 1000, 200);
|
||||
var timers = [];
|
||||
|
|
|
@ -7,7 +7,6 @@ module.exports = {
|
|||
exec: function (args, options) {
|
||||
options = options || {};
|
||||
return new Promise((resolve, reject) => {
|
||||
console.log(options);
|
||||
exec(args, options, (stderr, stdout, code) => {
|
||||
if (code) {
|
||||
reject(stderr);
|
||||
|
|
Loading…
Reference in New Issue