Skip to content

Commit

Permalink
split functionality into five crates from one
Browse files Browse the repository at this point in the history
* bldr - the initial crate mostly unchanged (for now)
* core - shared functionality between any bldr crate
* depot - contains the depot server
* depot-core - shared functionality between any depot components
* depot-client - an http client to the depot server
  • Loading branch information
reset committed Mar 17, 2016
1 parent 9113240 commit bc84798
Show file tree
Hide file tree
Showing 53 changed files with 4,205 additions and 1,381 deletions.
20 changes: 20 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@ gpg: ## install gpg keys, only run this in a studio
(cd plans && make gpg)

build: image ## run cargo build
$(run) shell cargo build --manifest-path components/core/Cargo.toml
$(run) shell cargo build --manifest-path components/bldr/Cargo.toml
$(run) shell cargo build --manifest-path components/depot-core/Cargo.toml
$(run) shell cargo build --manifest-path components/depot/Cargo.toml
$(run) shell cargo build --manifest-path components/depot-client/Cargo.toml

shell: image ## start a shell for building packages
$(run) shell
Expand All @@ -35,16 +39,32 @@ docs-serve: docs ## serve up the documentation
$(run) -p 9633:9633 shell sh -c 'set -e; cd ./components/bldr/target/doc; python -m SimpleHTTPServer 9633;'

test: image ## run `cargo test`
$(run) shell cargo test --manifest-path components/core/Cargo.toml
$(run) shell cargo test --manifest-path components/bldr/Cargo.toml
$(run) shell cargo test --manifest-path components/depot-core/Cargo.toml
$(run) shell cargo test --manifest-path components/depot/Cargo.toml
$(run) shell cargo test --manifest-path components/depot-client/Cargo.toml

unit: image ## run unit tests with cargo
$(run) shell cargo test --lib --manifest-path components/core/Cargo.toml
$(run) shell cargo test --lib --manifest-path components/bldr/Cargo.toml
$(run) shell cargo test --lib --manifest-path components/depot-core/Cargo.toml
$(run) shell cargo test --lib --manifest-path components/depot/Cargo.toml
$(run) shell cargo test --lib --manifest-path components/depot-client/Cargo.toml

functional: image ## run the functional tests
$(run) shell cargo test --test functional --manifest-path components/core/Cargo.toml
$(run) shell cargo test --test functional --manifest-path components/bldr/Cargo.toml
$(run) shell cargo test --test functional --manifest-path components/depot-core/Cargo.toml
$(run) shell cargo test --test functional --manifest-path components/depot/Cargo.toml
$(run) shell cargo test --test functional --manifest-path components/depot-client/Cargo.toml

clean: ## clean up our docker environment
rm -rf components/bldr/target/debug components/bldr/target/release
rm -rf components/bldr/target/debug components/core/target/release
rm -rf components/bldr/target/debug components/depot-core/target/release
rm -rf components/bldr/target/debug components/depot/target/release
rm -rf components/bldr/target/debug components/depot-client/target/release
$(compose_cmd) stop
$(compose_cmd) rm -f -v
$(docker_cmd) rmi $(dimage) || true
Expand Down
38 changes: 38 additions & 0 deletions components/bldr/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions components/bldr/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,15 @@ urlencoded = "*"
openssl = "*"
walkdir = "*"

[dependencies.bldr_core]
path = "../core"

[dependencies.bldr_depot_core]
path = "../depot-core"

[dependencies.bldr_depot_client]
path = "../depot-client"

[dependencies.wonder]
path = "../../vendor/wonder"

Expand Down
104 changes: 0 additions & 104 deletions components/bldr/src/command/depot.rs

This file was deleted.

12 changes: 7 additions & 5 deletions components/bldr/src/command/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,12 @@
use std::fs;

use fs::PACKAGE_CACHE;
use core::fs::PACKAGE_CACHE;
use core::package::PackageIdent;
use depot_core::data_object;
use depot_client;

use error::BldrResult;
use package::PackageIdent;
use depot::{self, data_object};

static LOGKEY: &'static str = "CI";

Expand All @@ -62,7 +64,7 @@ static LOGKEY: &'static str = "CI";
/// * Fails if it cannot create `/opt/bldr/cache/pkgs`
/// * Fails if it cannot download the package from the upstream
pub fn from_url<P: AsRef<PackageIdent>>(url: &str, ident: &P) -> BldrResult<data_object::Package> {
let package = try!(depot::client::show_package(url, ident.as_ref()));
let package = try!(depot_client::show_package(url, ident.as_ref()));
try!(fs::create_dir_all(PACKAGE_CACHE));
for dep in &package.tdeps {
try!(install(url, &dep));
Expand All @@ -72,7 +74,7 @@ pub fn from_url<P: AsRef<PackageIdent>>(url: &str, ident: &P) -> BldrResult<data
}

fn install<P: AsRef<PackageIdent>>(url: &str, package: &P) -> BldrResult<()> {
let mut archive = try!(depot::client::fetch_package(url, package.as_ref(), PACKAGE_CACHE));
let mut archive = try!(depot_client::fetch_package(url, package.as_ref(), PACKAGE_CACHE));
let package = try!(archive.ident());
try!(archive.unpack());
outputln!("Installed {}", package);
Expand Down
15 changes: 8 additions & 7 deletions components/bldr/src/command/key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,17 @@ use std::path::Path;
use std::process::{Command, Stdio, Child};

use ansi_term::Colour::{Yellow, Red};
use core::package::PackageIdent;
use core::fs::KEY_CACHE;
use core::gpg;
use depot_client;
use time::strptime;
use rpassword::read_password;
use regex::Regex;

use config::Config;
use error::{BldrResult, ErrorKind};
use fs::KEY_CACHE;
use package::{Package, PackageIdent};
use depot;
use util::gpg;
use package::Package;

static LOGKEY: &'static str = "KU"; // "key utils"
static USER_KEY_COMMENT: &'static str = "bldr user key";
Expand Down Expand Up @@ -58,7 +59,7 @@ pub fn upload(config: &Config) -> BldrResult<()> {
match fs::metadata(path) {
Ok(_) => {
outputln!("Uploading {}", config.key());
try!(depot::client::put_key(url, path));
try!(depot_client::put_key(url, path));
}
Err(_) => {
if path.components().count() == 1 {
Expand All @@ -67,7 +68,7 @@ pub fn upload(config: &Config) -> BldrResult<()> {
match fs::metadata(&cached) {
Ok(_) => {
outputln!("Uploading {}.asc", config.key());
try!(depot::client::put_key(url, cached));
try!(depot_client::put_key(url, cached));
}
Err(_) => {
return Err(bldr_error!(ErrorKind::KeyNotFound(config.key().to_string())));
Expand Down Expand Up @@ -116,7 +117,7 @@ pub fn import(config: &Config) -> BldrResult<()> {
try!(fs::create_dir_all(KEY_CACHE));
// docopt requires -u to be set, so we should be safe to unwrap here
let url = config.url().as_ref().unwrap();
let filename = try!(depot::client::fetch_key(&url, &config.key(), KEY_CACHE));
let filename = try!(depot_client::fetch_key(&url, &config.key(), KEY_CACHE));
try!(gpg::import(&filename));
}
}
Expand Down
1 change: 0 additions & 1 deletion components/bldr/src/command/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,4 @@ pub mod install;
pub mod start;
pub mod key;
pub mod upload;
pub mod depot;
pub mod configure;
16 changes: 8 additions & 8 deletions components/bldr/src/command/start.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,17 +48,17 @@
//! See the [documentation on topologies](../topology) for a deeper discussion of how they function.
//!
use ansi_term::Colour::Yellow;

use std::env;

use fs::PACKAGE_CACHE;
use ansi_term::Colour::Yellow;
use core::fs::PACKAGE_CACHE;
use depot_client;

use error::{BldrResult, ErrorKind};
use config::Config;
use package::{Package, PackageIdent};
use package::Package;
use topology::{self, Topology};
use command::install;
use depot;

static LOGKEY: &'static str = "CS";

Expand All @@ -82,12 +82,12 @@ pub fn package(config: &Config) -> BldrResult<()> {
//
// If the operator does not specify a version number they will automatically receive
// updates for any releases, regardless of version number, for the started package.
let latest_pkg: Package = try!(depot::client::show_package(&url, config.package()))
let latest_pkg: Package = try!(depot_client::show_package(&url, config.package()))
.into();
if latest_pkg > package {
outputln!("Downloading latest version from remote: {}", &latest_pkg);
let archive = try!(depot::client::fetch_package(&url,
&PackageIdent::from(latest_pkg),
let archive = try!(depot_client::fetch_package(&url,
&latest_pkg.into(),
PACKAGE_CACHE));
try!(archive.verify());
try!(archive.unpack());
Expand Down
16 changes: 8 additions & 8 deletions components/bldr/src/command/upload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@
use std::path::PathBuf;

use core::package::PackageArchive;
use depot_client;
use hyper::status::StatusCode;

use error::{BldrResult, BldrError, ErrorKind};
use config::Config;
use package::archive::PackageArchive;
use depot;

static LOGKEY: &'static str = "CU";

Expand All @@ -43,21 +43,21 @@ pub fn package(config: &Config) -> BldrResult<()> {
let url = config.url().as_ref().unwrap();
let mut pa = PackageArchive::new(PathBuf::from(config.archive()));
outputln!("Uploading from {}", pa.path.to_string_lossy());
match depot::client::put_package(url, &mut pa) {
match depot_client::put_package(url, &mut pa) {
Ok(()) => (),
Err(BldrError{err: ErrorKind::HTTP(StatusCode::Conflict), ..}) => {
Err(depot_client::Error::HTTP(StatusCode::Conflict)) => {
outputln!("Package already exists on remote; skipping.");
}
Err(BldrError{err: ErrorKind::HTTP(StatusCode::UnprocessableEntity), ..}) => {
Err(depot_client::Error::HTTP(StatusCode::UnprocessableEntity)) => {
return Err(bldr_error!(ErrorKind::PackageArchiveMalformed(format!("{}", pa.path.to_string_lossy()))));
}
Err(e @ BldrError{err: ErrorKind::HTTP(_), ..}) => {
Err(e @ depot_client::Error::HTTP(_)) => {
outputln!("Unexpected response from remote");
return Err(e);
return Err(BldrError::from(e));
}
Err(e) => {
outputln!("The package might exist on the remote - we fast abort, so.. :)");
return Err(e);
return Err(BldrError::from(e));
}
}
outputln!("Complete");
Expand Down
Loading

1 comment on commit bc84798

@chef-delivery
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.