Skip to content

Commit

Permalink
Merge pull request #101 from chef/install-deps
Browse files Browse the repository at this point in the history
Merged change 3b5166ef-a8f2-4f5c-9228-d6c905e58a8a

From review branch install-deps into master

Signed-off-by: adam <[email protected]>
  • Loading branch information
chef-delivery committed Nov 25, 2015
2 parents 63b15f5 + 3cdf5b5 commit d32f500
Show file tree
Hide file tree
Showing 12 changed files with 489 additions and 257 deletions.
35 changes: 14 additions & 21 deletions plans/Makefile
Original file line number Diff line number Diff line change
@@ -1,30 +1,23 @@
PKGS := glibc libgcc zlib cacerts busybox gnupg openssl runit bldr redis ncurses libedit bzip2 pcre nginx haproxy libaio libltdl libxml2 numactl perl
REPO := http://ec2-52-10-238-149.us-west-2.compute.amazonaws.com

world: gpg
./bldr-build glibc
./bldr-build libgcc
./bldr-build zlib
./bldr-build cacerts
./bldr-build busybox
./bldr-build gnupg
./bldr-build openssl
./bldr-build runit
./bldr-build bldr
./bldr-build redis
./bldr-build ncurses
./bldr-build libedit
./bldr-build bzip2
./bldr-build pcre
./bldr-build nginx
./bldr-build haproxy
./bldr-build libaio
./bldr-build libltdl
./bldr-build libxml2
./bldr-build numactl
./bldr-build perl
@for pkg in $(PKGS); do \
./bldr-build $$pkg; \
done
cp ./chef-public.gpg /opt/bldr/cache/keys/chef-public.asc

publish:
cargo build --release
@for pkg in $(PKGS); do \
../target/release/bldr upload chef/$$pkg -u $(REPO); \
done

gpg:
- gpg --import chef-public.gpg
- gpg --import chef-private.gpg
- gpg --homedir /opt/bldr/cache/gpg --import chef-public.gpg
- gpg --homedir /opt/bldr/cache/gpg --import chef-private.gpg

clean:
rm -rf /opt/bldr/pkgs/*
Expand Down
2 changes: 2 additions & 0 deletions plans/bldr-build
Original file line number Diff line number Diff line change
Expand Up @@ -721,6 +721,8 @@ link_libraries() {
echo $dep_pkg_name >> $pkg_path/DEPS
done

echo "${pkg_derivation}/${pkg_name}/${pkg_version}/${pkg_rel}" >> $pkg_path/IDENT

return 0
}

Expand Down
69 changes: 30 additions & 39 deletions src/bldr/command/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,11 @@
//! * Unpack it
//!
use std::process::Command;
use std::fs;

use fs::{PACKAGE_CACHE, GPG_CACHE};
use error::{BldrResult, ErrorKind};
use util::gpg;
use fs::PACKAGE_CACHE;
use error::BldrResult;
use pkg::Package;
use repo;

static LOGKEY: &'static str = "CI";
Expand All @@ -73,45 +72,37 @@ 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(url: &str,
pub fn from_url(repo: &str,
deriv: &str,
package: &str,
version: &Option<String>,
release: &Option<String>)
-> BldrResult<String> {
name: &str,
version: Option<String>,
release: Option<String>)
-> BldrResult<Package> {
let package = try!(repo::client::show_package(repo, deriv, name, version, release));
try!(fs::create_dir_all(PACKAGE_CACHE));
repo::client::fetch_package(url, deriv, package, version, release, PACKAGE_CACHE)
}

/// Given a package name and a path to a file as an `&str`, verify
/// the files gpg signature.
///
/// # Failures
///
/// * Fails if it cannot verify the GPG signature for any reason
pub fn verify(package: &str, file: &str) -> BldrResult<()> {
try!(gpg::verify(package, file));
Ok(())
let mut installed: Vec<Package> = vec![];
if let Some(ref pkgs) = package.deps {
for pkg in pkgs {
try!(install(repo, &pkg, &mut installed));
}
}
try!(install(repo, &package, &mut installed));
Ok(package)
}

/// Given a package name and a path to a file as an `&str`, unpack
/// the package.
///
/// # Failures
///
/// * If the package cannot be unpacked via gpg
pub fn unpack(package: &str, file: &str) -> BldrResult<()> {
let output = try!(Command::new("sh")
.arg("-c")
.arg(format!("gpg --homedir {} --decrypt {} | tar -C / -x",
GPG_CACHE,
file))
.output());
match output.status.success() {
true => outputln!("Installed {}", package),
false => {
outputln!("Failed to install {}", package);
return Err(bldr_error!(ErrorKind::UnpackFailed));
fn install(repo: &str, package: &Package, acc: &mut Vec<Package>) -> BldrResult<()> {
if acc.contains(&package) {
return Ok(());
}
let archive = try!(repo::client::fetch_package_exact(repo, package, PACKAGE_CACHE));
try!(archive.verify());
let package = try!(archive.unpack());
outputln!("Installed {}", package);
let deps = package.deps.clone();
acc.push(package);
if let Some(ref pkgs) = deps {
for pkg in pkgs {
try!(install(repo, &pkg, acc))
}
}
Ok(())
Expand Down
33 changes: 15 additions & 18 deletions src/bldr/command/start.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,18 +84,18 @@ pub fn package(config: &Config) -> BldrResult<()> {
Ok(mut package) => {
if let Some(ref url) = *config.url() {
outputln!("Checking remote for newer versions...");
let latest_pkg = try!(repo::client::show_package_latest(&url,
&package.derivation,
&package.name,
None));
let latest_pkg = try!(repo::client::show_package(&url,
&package.derivation,
&package.name,
None,
None));
if latest_pkg > package {
outputln!("Downloading latest version from remote: {}", &latest_pkg);
let pkg_file = try!(repo::client::fetch_package_exact(&url,
&latest_pkg,
PACKAGE_CACHE));
try!(install::verify(config.package(), &pkg_file));
try!(install::unpack(config.package(), &pkg_file));
package = try!(Package::from_path(&pkg_file));
let archive = try!(repo::client::fetch_package_exact(&url,
&latest_pkg,
PACKAGE_CACHE));
try!(archive.verify());
package = try!(archive.unpack());
} else {
outputln!("Already running latest.");
};
Expand All @@ -110,14 +110,11 @@ pub fn package(config: &Config) -> BldrResult<()> {
outputln!("Searching for {} in remote {}",
Yellow.bold().paint(config.package()),
url);
let pkg_file = try!(install::from_url(url,
config.deriv(),
config.package(),
config.version(),
config.release()));
try!(install::verify(&config.package(), &pkg_file));
try!(install::unpack(&config.package(), &pkg_file));
let package = try!(Package::from_path(&pkg_file));
let package = try!(install::from_url(url,
config.deriv(),
config.package(),
config.version().clone(),
config.release().clone()));
start_package(package, config)
}
None => {
Expand Down
17 changes: 17 additions & 0 deletions src/bldr/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,23 @@ impl Config {
pub fn repo_addr(&self) -> net::SocketAddrV4 {
net::SocketAddrV4::new(self.listen_addr.0.clone(), self.port.0.clone())
}

pub fn package_id(&self) -> String {
if self.version.is_some() && self.release.is_some() {
format!("{}/{}/{}/{}",
&self.deriv,
&self.package,
self.version.as_ref().unwrap(),
self.release.as_ref().unwrap())
} else if self.version.is_some() {
format!("{}/{}/{}",
self.deriv,
self.package,
self.version.as_ref().unwrap())
} else {
format!("{}/{}", self.deriv, self.package)
}
}
}

#[cfg(test)]
Expand Down
19 changes: 13 additions & 6 deletions src/bldr/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ impl BldrError {
#[derive(Debug)]
/// All the kinds of errors we produce.
pub enum ErrorKind {
ArchiveReadFailed(String),
Io(io::Error),
CommandNotImplemented,
InstallFailed,
Expand All @@ -102,11 +103,12 @@ pub enum ErrorKind {
HTTP(hyper::status::StatusCode),
CannotParseFileName,
PathUTF8,
GPGVerifyFailed,
GPGImportFailed(String),
GPGVerifyFailed(String),
UnpackFailed,
TomlParser(Vec<toml::ParserError>),
MustacheEncoderError(mustache::encoder::Error),
GPGImportFailed,
MetaFileNotFound(pkg::MetaFile),
PermissionFailed,
BadVersion,
RegexParse(regex::Error),
Expand Down Expand Up @@ -147,6 +149,7 @@ impl fmt::Display for BldrError {
// verbose on, and print it.
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
let content = match self.err {
ErrorKind::ArchiveReadFailed(ref e) => format!("Failed to read package archive, {}", e),
ErrorKind::Io(ref err) => format!("{}", err),
ErrorKind::CommandNotImplemented => format!("Command is not yet implemented!"),
ErrorKind::InstallFailed => format!("Could not install package!"),
Expand All @@ -157,7 +160,8 @@ impl fmt::Display for BldrError {
ErrorKind::CannotParseFileName =>
format!("Cannot determine the filename from the given URI"),
ErrorKind::PathUTF8 => format!("Paths must not contain non-UTF8 characters"),
ErrorKind::GPGVerifyFailed => format!("Failed to verify a GPG Signature"),
ErrorKind::GPGImportFailed(ref e) => format!("Failed to import a GPG key, {}", e),
ErrorKind::GPGVerifyFailed(ref e) => format!("Failed to verify GPG Signature, {}", e),
ErrorKind::UnpackFailed => format!("Failed to unpack a package"),
ErrorKind::TomlParser(ref errs) => {
format!("Failed to parse toml:\n{}", toml_parser_string(errs))
Expand All @@ -168,7 +172,8 @@ impl fmt::Display for BldrError {
_ => format!("Mustache encoder error: {:?}", me),
}
}
ErrorKind::GPGImportFailed => format!("Failed to import a GPG key"),
ErrorKind::MetaFileNotFound(ref e) =>
format!("Couldn't read MetaFile: {}, not found", e),
ErrorKind::PermissionFailed => format!("Failed to set permissions"),
ErrorKind::BadVersion => format!("Failed to parse a version number"),
ErrorKind::RegexParse(ref e) => format!("{}", e),
Expand Down Expand Up @@ -249,6 +254,7 @@ impl fmt::Display for BldrError {
impl Error for BldrError {
fn description(&self) -> &str {
match self.err {
ErrorKind::ArchiveReadFailed(_) => "Failed to read contents of package archive",
ErrorKind::Io(ref err) => err.description(),
ErrorKind::CommandNotImplemented => "Command is not yet implemented!",
ErrorKind::InstallFailed => "Could not install package!",
Expand All @@ -258,11 +264,12 @@ impl Error for BldrError {
ErrorKind::HyperError(ref err) => err.description(),
ErrorKind::HTTP(_) => "Received an HTTP error",
ErrorKind::PathUTF8 => "Paths must not contain non-UTF8 characters",
ErrorKind::GPGVerifyFailed => "Failed to verify a GPG Signature",
ErrorKind::GPGImportFailed(_) => "Failed to import a GPG key",
ErrorKind::GPGVerifyFailed(_) => "Failed to verify a GPG Signature",
ErrorKind::UnpackFailed => "Failed to unpack a package",
ErrorKind::TomlParser(_) => "Failed to parse toml!",
ErrorKind::MustacheEncoderError(_) => "Failed to encode mustache template",
ErrorKind::GPGImportFailed => "Failed to import a GPG key",
ErrorKind::MetaFileNotFound(_) => "Failed to read an archive's metafile",
ErrorKind::PermissionFailed => "Failed to set permissions",
ErrorKind::BadVersion => "Failed to parse a version number",
ErrorKind::RegexParse(_) => "Failed to parse a regular expression",
Expand Down
Loading

0 comments on commit d32f500

Please sign in to comment.