Skip to content
This repository was archived by the owner on Sep 20, 2024. It is now read-only.

Commit

Permalink
starting to store build results in datastore
Browse files Browse the repository at this point in the history
  • Loading branch information
adam-singer committed Apr 25, 2014
1 parent fae2075 commit de0919b
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 5 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,4 @@ test/dummyLibraries/allLibs/packages
test/dummyLibraries/mixedLibs/packages
test/dummyLibraries/noLibs/packages
test/dummyLibraries/packages
config.json
48 changes: 46 additions & 2 deletions bin/client_builder.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import "dart:io";
import "dart:convert";

import 'package:args/args.dart';
import 'package:logging/logging.dart';
Expand All @@ -25,15 +26,34 @@ void main(args) {
dartSdk = results['sdk'];
}

String configPath;
if (results['config'] == null) {
print("You must provide a value for 'config'.");
_printUsage(parser);
return;
} else {
configPath = results['config'];
}

String package = results['package'];
Version version = new Version.parse(results['version']);
_initClient(dartSdk, package, version);
_initClient(dartSdk, configPath, package, version);
return;
}

void _initClient(String dartSdk, String packageName, Version version) {
void _initClient(String dartSdk, String configPath, String packageName,
Version version) {
Logger.root.info("Starting build of ${packageName} ${version}");
Package package = new Package(packageName, [version]);
String configFile = new File(configPath).readAsStringSync();
Map config = JSON.decode(configFile);
String rsaPrivateKey = new File(config["rsaPrivateKey"]).readAsStringSync();
GoogleComputeEngineConfig googleComputeEngineConfig =
new GoogleComputeEngineConfig(config["projectId"], config["projectNumber"],
config["serviceAccountEmail"], rsaPrivateKey);
PackageBuildInfoDataStore packageBuildInfoDataStore
= new PackageBuildInfoDataStore(googleComputeEngineConfig);

try {
package.buildDocumentationCacheSync(versionConstraint: version);
package.initPackageVersion(version);
Expand All @@ -46,10 +66,28 @@ void _initClient(String dartSdk, String packageName, Version version) {
// else was successful.
package.createPackageBuildInfo(version, true);
package.copyPackageBuildInfo(version);

// TODO: Factor out into Package class
// all time stamps need to be in UTC/Iso8601 format.
var now = new DateTime.now().toUtc().toIso8601String();
PackageBuildInfo packageBuildInfo =
new PackageBuildInfo(package.name, version, now, true);
packageBuildInfoDataStore.save(packageBuildInfo).then((r) {
Logger.root.info("r = $r");
});
} catch (e) {
Logger.root.severe(("Not able to build ${package.toString()}"));
package.createPackageBuildInfo(version, false);
package.copyPackageBuildInfo(version);

// TODO: Factor out into Package class
// all time stamps need to be in UTC/Iso8601 format.
var now = new DateTime.now().toUtc().toIso8601String();
PackageBuildInfo packageBuildInfo =
new PackageBuildInfo(package.name, version, now, false);
packageBuildInfoDataStore.save(packageBuildInfo).then((r) {
Logger.root.info("r = $r");
});
}
}

Expand All @@ -73,11 +111,17 @@ ArgParser _createArgsParser() {
}
});

// TODO: move to config.json
parser.addOption(
'sdk',
help: 'Path to the sdk. Required.',
defaultsTo: null);

parser.addOption(
'config',
help: 'Path to the config. Required.',
defaultsTo: null);

//
// Client options
//
Expand Down
2 changes: 1 addition & 1 deletion lib/carte_de_jour.dart
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ String buildStartupScript(String startupScriptTemplatePath) {
var template = mustache.parse(startupScriptTemplate);
var startupScript = template.renderString({
'user_name': 'financeCoding',
'dart_application': r'bin/client_builder.dart --verbose --sdk $DARTSDK --package $PACKAGE --version $VERSION'
'dart_application': r'bin/client_builder.dart --verbose --sdk $DARTSDK --config bin/config.json --package $PACKAGE --version $VERSION'
}, htmlEscapeValues: false);
return startupScript;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/src/package.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class Package {
Map toJson() {
Map map = {};
map['name'] = name;
map['versions'] = versions;
map['versions'] = versions.map((e)=>e.toString()).toList();
map['uploaders'] = uploaders;
return map;
}
Expand Down
4 changes: 3 additions & 1 deletion lib/startup_script.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ fetch_latest_dart_sdk
export DARTSDK=$(curl http://metadata/computeMetadata/v1beta1/instance/attributes/dartsdk)
export PACKAGE=$(curl http://metadata/computeMetadata/v1beta1/instance/attributes/package)
export VERSION=$(curl http://metadata/computeMetadata/v1beta1/instance/attributes/version)
sudo -E -H -u {{user_name}} bash -c 'cd ~/ && git clone https://github.com/financeCoding/dart-carte-du-jour.git'
sudo -E -H -u {{user_name}} bash -c 'cd ~/ && git clone https://github.com/{{user_name}}/dart-carte-du-jour.git'
sudo -E -H -u {{user_name}} bash -c 'cd ~/ && gsutil cp gs://dart-carte-du-jour/configurations/config.json ~/dart-carte-du-jour/bin/config.json'
sudo -E -H -u {{user_name}} bash -c 'cd ~/ && gsutil cp gs://dart-carte-du-jour/configurations/rsa_private_key.pem ~/dart-carte-du-jour/bin/rsa_private_key.pem'
sudo -E -H -u {{user_name}} bash -c 'cd ~/ && rm -rf ~/pub-cache; source /etc/profile && cd ~/dart-carte-du-jour && pub install && dart {{dart_application}}'
shutdown_instance

0 comments on commit de0919b

Please sign in to comment.