Skip to content

Commit

Permalink
Merge branch 'release/0.1.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
Kami committed Apr 25, 2011
2 parents e965c80 + fcf9bf3 commit 28cd733
Show file tree
Hide file tree
Showing 15 changed files with 135 additions and 71 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,6 @@ lib/extern/node-jscoverage/*
.tests
*.pyc
temp/*
dist/
deps/
tmp/
3 changes: 3 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
25.04.2011 - v0.1.0 (stable, preview):

* Initial public preview release
40 changes: 33 additions & 7 deletions SConstruct
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,13 @@ AddOption(
help = 'A list of JavaScript files'
)

AddOption(
'--no-deps',
dest = 'no_deps',
action = 'store_true',
help = 'Don\'t download dependencies when creating a distribution tarball'
)

env = Environment(options=opts,
ENV = os.environ.copy(),
tools = ['default', 'packaging'])
Expand Down Expand Up @@ -86,6 +93,7 @@ dist_tests = env.Glob('tests/dist/*.js');

allsource = testsource + source

no_deps = GetOption('no_deps')
js_files = GetOption('js_files')
if js_files:
js_files = js_files.split(' ')
Expand Down Expand Up @@ -181,19 +189,23 @@ dependencies = [
[ env['node_tarball_url'], 'deps/node.tar.gz' ],
]

download_dependencies = []
download_dependencies = [ env.Command('.mkdir_deps', [], 'rm -rf deps ; mkdir deps')]
dependency_paths = [ 'deps/node.tar.gz' ]
for dependency in dependencies:
download_dependencies.append((env.Command('.%s' % (dependency[1]), '', download_file(dependency[0], dependency[1]))))

paths_to_include = [ 'bin', 'lib', 'node_modules', 'other', 'deps']
files_to_include = [ 'SConstruct', 'README', 'NOTICE',
'LICENSE' ]
paths_to_skip = [ 'lib/extern/expresso', 'lib/extern/whiskey',
'lib/extern/Nodelint',
'LICENSE', 'CHANGES' ]
paths_to_skip = [ 'lib/extern/Nodelint',
'lib/extern/jsdoc-toolkit', 'lib/extern/closure-linter',
'lib/extern/node-jscoverage',
'node_modules/.npm/',
'lib/SConscript', 'lib/README', 'other/SConstruct',
'node_modules/whiskey',
'node_modules/nodelint',
'node_modules/.bin/',
'lib/SConscript',
'other/SConstruct',
'other/docgen.js']
files_to_pack = get_file_list(cwd, paths_to_include, paths_to_skip)
build_to_pack = [ pjoin('build', path) for path in files_to_pack +
Expand Down Expand Up @@ -224,10 +236,16 @@ env.AlwaysBuild(covcmd)
"""

folder_name = 'cast-%s' % (env['version_string'])
tarball_name = '%s.tar.gz' % (folder_name)

# Calculate distribution tarball md5sum
calculate_md5sum = env.Command('.calculate_md5sum', [],
'md5sum dist/%s | awk \'{gsub("dist/", "", $0); print $0}\' > dist/%s.md5sum' % (tarball_name, tarball_name))

copy_paths = [ 'cp -R %s build' % (path) for path in paths_to_include +
files_to_include ]
create_tarball = '%s -zc -f dist/%s --transform \'s,^build,%s,\' %s' % (
tar_bin_path, '%s.tar.gz' % (folder_name),
tar_bin_path, '%s' % (tarball_name),
folder_name, ' '.join(build_to_pack))
create_distribution_commands = [
'rm -rf dist',
Expand All @@ -241,8 +259,16 @@ create_distribution_commands.extend(['rm -rf build'])
create_distribution_tarball = env.Command('.create-dist', [],
' ; '.join(create_distribution_commands))

dist_targets = [ create_distribution_tarball, calculate_md5sum ]

if not no_deps:
Depends(create_distribution_tarball, download_dependencies)
dist_targets.insert(0, download_dependencies)

Depends(calculate_md5sum, create_distribution_tarball)

env.Alias('download-deps', download_dependencies)
env.Alias('dist', create_distribution_tarball)
env.Alias('dist', dist_targets)

targets = []
env.Default(targets)
8 changes: 0 additions & 8 deletions TODO
Original file line number Diff line number Diff line change
@@ -1,11 +1,3 @@

* HTTP Interfaces
** Define reverse pulling / Helen-like API for HTTP RPC in reverse
** Figure out authentication / SSL Certs / less pain

* Services Management
** Decide if we stick with runit, patch it, use something else, or rewrite.

* Cluster Support
** BItTorrent Plan
** File distribution / patching
Expand Down
2 changes: 1 addition & 1 deletion build.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
node_tarball_url = 'http://nodejs.org/dist/node-v0.4.6.tar.gz'
node_tarball_url = 'http://nodejs.org/dist/node-v0.4.7.tar.gz'
5 changes: 5 additions & 0 deletions lib/cast-client/commands/bundles/upload.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,11 @@ function handleCommand(args) {
var pbar = spinner.percentbar(pbarString, size);

http.buildRequest(args.remote, opts, function(err, request) {
if (err) {
callback(err);
return;
}

function tick(bytes) {
pbar.tick(bytes);
}
Expand Down
2 changes: 1 addition & 1 deletion lib/cast-client/entry.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ var term = require('util/terminal');
var parser = require('./parser');

var requirements = {
'node_version': ['0.3.0', req.compareVersions, 'Minimum node version must be 0.3.0']
'node_version': ['0.4.0', req.compareVersions, 'Minimum node version must be 0.4.0']
};

/**
Expand Down
4 changes: 2 additions & 2 deletions lib/services/http/services.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ function actionService(req, res, action, serviceName) {
var statusCode, errMessage;
var manager = serviceManagement.getDefaultManager().getManager();

manager.runAction(serviceName, action, function(err, service) {
manager.runAction(serviceName, action, function(err) {
if (err) {
if (err.errno === constants.ENOENT) {
statusCode = 404;
Expand All @@ -140,7 +140,7 @@ function actionService(req, res, action, serviceName) {
}

http.returnJson(res, 200, {
'service': service,
'service': serviceName,
'method': action,
'result': 'success'
});
Expand Down
12 changes: 3 additions & 9 deletions lib/util/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ var defaults = {
'gzip': 'gzip', // gzip binary
'tar': null, // tar binary (TODO: deprecated?)
'norris_ttl': (60 * 10), // TTL of norris cache
'pretty_json': false, // Output pretty JSON

/* Service Manager Related Configuration */
'service_manager': 'runit'
Expand Down Expand Up @@ -188,15 +189,8 @@ exports.setupAgent = function(callback) {
var err = null;
var conf = exports.currentConfig;

if (!conf['secret']) {
if (!conf['ssl_enabled']) {
err = new Error('SSL is disabled by no \'secret\' has been provided');
} else if (!conf['verify_client_cert']) {
err = new Error('Either \'verify_client_cert\' must be enabled ' +
'or a \'secret\' must be provided.');
} else if (conf['warn_nosecret']) {
log.warn('WARNING: No \'secret\' has been congigured.');
}
if (!conf['secret'] && conf['warn_nosecret']) {
log.warn('WARNING: No \'secret\' has been congigured.');
}

callback(err);
Expand Down
24 changes: 15 additions & 9 deletions lib/util/http.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,9 @@ function _baseRequest(remote, options, callback) {
};

// Set the HMAC headers
hmac.createHttpHmac(reqOptions.method, reqOptions.path, headers);
if (conf['secret']) {
hmac.createHttpHmac(reqOptions.method, reqOptions.path, headers);
}

// Callback we set later to actually perform HTTPS requests
function doHttpsRequest(err, certText) {
Expand Down Expand Up @@ -363,7 +365,9 @@ function returnText(res, code, type, data) {
* @param {Object} data The data to write to the response.
*/
function returnJson(res, code, data) {
returnText(res, code, 'application/json', JSON.stringify(data));
var conf = config.get();
var indent = conf['pretty_json'] ? 4 : undefined;
returnText(res, code, 'application/json', JSON.stringify(data, null, indent));
}

/**
Expand Down Expand Up @@ -647,13 +651,15 @@ function buildServer() {
ct = req;
}

if (!hmac.validateHttpHmac(req.method, req.url, req.headers)) {
// Verify request HMAC
log.info(sprintf('Invalid HMAC from %s', ct.socket.remoteAddress));
returnJson(res, 401, {
'message': 'HMAC verification failed.'
});
return;
if (conf['secret']) {
if (!hmac.validateHttpHmac(req.method, req.url, req.headers)) {
// Verify request HMAC
log.info(sprintf('Invalid HMAC from %s', ct.socket.remoteAddress));
returnJson(res, 401, {
'message': 'HMAC verification failed.'
});
return;
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion lib/util/version.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ var CAST_VERSION_MINOR = 1;
var CAST_VERSION_PATCH = 0;

/* change this on release tags */
var CAST_IS_DEV = true;
var CAST_IS_DEV = false;

/** Major version */
exports.MAJOR = CAST_VERSION_MAJOR;
Expand Down
64 changes: 45 additions & 19 deletions other/SConstruct
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,12 @@ cwd = os.getcwd()
user_home_path = os.path.expanduser('~')

opts = Variables('build.py')
opts.Add(PathVariable('PREFIX', default = '/opt/cast',
help = 'Directory to install under',
opts.Add(PathVariable('CASTPREFIX', default = '/opt/cast',
help = 'Directory to install Cast under',
validator = SCons.Variables.PathVariable.PathAccept))

opts.Add(PathVariable('PREFIX', default = '/usr/local/bin',
help = 'Destination where the symlinks will be created',
validator = SCons.Variables.PathVariable.PathAccept))

env = Environment(options = opts, ENV = os.environ.copy())
Expand All @@ -53,7 +57,14 @@ AddOption(
'--no-symlinks',
dest = 'no_symlinks',
action = 'store_true',
help = 'True to not create client and agent symlink in /usr/local/bin'
help = 'True to not create Cast client and agent symlink in PREFIX'
)

AddOption(
'--settings-path',
dest = 'settings_path',
action = 'store',
help = 'Settings path'
)

AddOption(
Expand All @@ -63,9 +74,13 @@ AddOption(
help = 'True to also remove cast settings directory upon uninstall'
)

settings_path = GetOption('settings_path')
settings_path = settings_path or pjoin(user_home_path, '.cast')

system_node_binary_path = None
no_symlinks = False
remove_settings = False

if GetOption('use_system_node'):
# TODO: Check for min version
system_node_binary_path = env.WhereIs('node')
Expand All @@ -78,18 +93,20 @@ if GetOption('no_symlinks'):
no_symlinks = True
if GetOption('remove_settings'):
remove_settings = True
settings_path = pjoin(user_home_path, '.cast')

# Variables
node_tarball = 'deps/node.tar.gz'

prefix = env['PREFIX']
base_install_prefix = '%s/' % (prefix)
node_install_prefix = '%s/node/' % (prefix)
cast_install_prefix = '%s/cast/' % (prefix)
cast_data_prefix = '%s/cast/data/' % (prefix)
symlinks_prefix = env['PREFIX']
cast_prefix = env['CASTPREFIX']

cast_config_path = pjoin(user_home_path, '.cast/config.json')
base_install_prefix = cast_prefix
node_install_prefix = pjoin(cast_prefix, 'node')
cast_install_prefix = pjoin(cast_prefix, 'cast')
cast_data_prefix = pjoin(cast_prefix, 'data')
services_enabled_directory = pjoin(cast_data_prefix, 'services-enabled')

cast_config_path = pjoin(settings_path, 'config.json')
cast_paths = [ 'lib/', 'bin/', 'node_modules/' ]

default_config = """{
Expand All @@ -98,8 +115,8 @@ default_config = """{
}
"""

cast_client_bin_path = pjoin('/usr/local/bin', 'cast')
cast_agent_bin_path = pjoin('/usr/local/bin', 'cast-agent')
cast_client_bin_path = pjoin(symlinks_prefix, 'cast')
cast_agent_bin_path = pjoin(symlinks_prefix, 'cast-agent')

node_binary_path = system_node_binary_path or pjoin(node_install_prefix, 'bin/node')
shebang_line = '#!%s' % (node_binary_path)
Expand Down Expand Up @@ -132,7 +149,7 @@ def populate_cast_config(target, source, env):
"""
target_path = str(target[0])

config = default_config % { 'data_root': base_install_prefix,
config = default_config % { 'data_root': cast_data_prefix,
'service_dir_enabled': 'services-enabled'
}
fp = open(target_path, 'w')
Expand All @@ -143,7 +160,7 @@ def populate_cast_config(target, source, env):

# Install node
extract_node = env.Command('.extract_node', '', 'mkdir -p build/node/; tar -xzvf %s -C build/node/ --strip-components=1' % (node_tarball))
configure_node = env.Command('.configure_node', '', './configure --prefix=%s' % (node_install_prefix), chdir = 'build/node/')
configure_node = env.Command('.configure_node', '', './configure --prefix="%s"' % (node_install_prefix), chdir = 'build/node/')
install_node = env.Command('.build_node', '','make install', chdir = 'build/node/')

Depends(configure_node, extract_node)
Expand All @@ -155,11 +172,18 @@ replace_cast_lines = env.Command('.replace_lines', '', replace_lines)
# Copy cast files into the install prefix
copy_cast_files = env.Command('.%s' % (cast_install_prefix), cast_paths, copy_tree)

noop = env.Command([pjoin(cast_install_prefix, 'bin/cast'), pjoin(cast_install_prefix, 'bin/cast-agent')], '', noop)

# Symlink Cast scripts to /usr/local/bin
symlink_cast_client = env.Command(cast_client_bin_path, pjoin(cast_install_prefix, 'bin/cast'), symlink)
symlink_cast_agent = env.Command(cast_agent_bin_path, pjoin(cast_install_prefix, 'bin/cast-agent'), symlink)
symlink_cast_client = env.Command(cast_client_bin_path, '', 'ln -s "%s" "%s"' % (
pjoin(cast_install_prefix, 'bin/cast'),
cast_client_bin_path))
symlink_cast_agent = env.Command(cast_agent_bin_path, '', 'ln -s "%s" "%s"' % (
pjoin(cast_install_prefix, 'bin/cast-agent'),
cast_agent_bin_path))

# Create data_root and services-enabled directory
create_data_root_dir = env.Command(cast_data_prefix, '', Mkdir(cast_data_prefix))
create_services_enabled_dir = env.Command(services_enabled_directory, '',
Mkdir(services_enabled_directory))

# Populate default cast config
populate_cast_config = env.Command(cast_config_path, '', populate_cast_config)
Expand All @@ -168,7 +192,9 @@ Depends(symlink_cast_client, copy_cast_files)
Depends(symlink_cast_agent, copy_cast_files)
Depends(replace_cast_lines, copy_cast_files)

install_cast = [ copy_cast_files, noop, replace_cast_lines, populate_cast_config ]
install_cast = [ copy_cast_files, create_data_root_dir,
services_enabled_directory, replace_cast_lines,
populate_cast_config ]

if not no_symlinks:
install_cast.extend([ symlink_cast_client, symlink_cast_agent ])
Expand Down
7 changes: 5 additions & 2 deletions tests/dist/test-dist-command.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,14 @@ exports['test_dist_command_works'] = function() {
var versionString = version.toString().replace('-dev', '');
var tarballname = sprintf('%s.tar.gz', versionString);
var tarballPath = path.join(cwd, 'dist', tarballname);
var tarballMd5SumPath = path.join(cwd, 'dist',
sprintf('%s.md5sum', tarballname));

// Make sure the distribution tarball doesn't exist
assert.ok(!test.fileExists(tarballPath));
exec('scons dist', function(err, stdout, stderr) {
// Make sure the distribution tarball has been created
exec('scons dist --no-deps', function(err, stdout, stderr) {
// Make sure the distribution tarball and md5sum file has been created
assert.ok(test.fileExists(tarballPath));
assert.ok(test.fileExists(tarballMd5SumPath));
});
};
Loading

0 comments on commit 28cd733

Please sign in to comment.