Skip to content

Commit

Permalink
Merge pull request #2843 from habitat-sh/pkg-export-channels
Browse files Browse the repository at this point in the history
Approved by: @nobody from Nowhere
Merged by: The Sentinels
  • Loading branch information
thesentinels authored Jul 28, 2017
2 parents 8bf57ea + c621ce2 commit e3bdccd
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 11 deletions.
12 changes: 12 additions & 0 deletions components/hab/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,18 @@ pub fn get() -> App<'static, 'static> {
"The export format (ex: docker, aci, mesos, or tar)")
(@arg PKG_IDENT: +required +takes_value
"A package identifier (ex: core/redis, core/busybox-static/1.42.2)")
(@arg DEPOT_URL: --url -u +takes_value {valid_url}
"Retrieve the container's package from the specified Depot \
(default: https://bldr.habitat.sh/v1/depot)")
(@arg CHANNEL: --channel -c +takes_value
"Retrieve the container's package from the specified release channel \
(default: stable)")
(@arg HAB_DEPOT_URL: --("hab-url") -U +takes_value {valid_url}
"Retrieve the Habitat toolchain for the container from the specified Depot \
(default: https://bldr.habitat.sh/v1/depot)")
(@arg HAB_CHANNEL: --("hab-channel") -C +takes_value
"Retrieve the Habitat toolchain for the container from the specified release \
channel (default: stable)")
)
(@subcommand hash =>
(about: "Generates a blake2b hashsum from a target at any given filepath")
Expand Down
43 changes: 35 additions & 8 deletions components/hab/src/command/pkg/export.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,16 @@ impl ExportFormat {
}
}

pub fn start(ui: &mut UI, ident: &PackageIdent, format: &ExportFormat) -> Result<()> {
inner::start(ui, ident, format)
pub fn start(
ui: &mut UI,
url: &str,
channel: &str,
hab_url: &str,
hab_channel: &str,
ident: &PackageIdent,
format: &ExportFormat,
) -> Result<()> {
inner::start(ui, url, channel, hab_url, hab_channel, ident, format)
}

pub fn format_for(ui: &mut UI, value: &str) -> Result<ExportFormat> {
Expand All @@ -44,15 +52,17 @@ pub fn format_for(ui: &mut UI, value: &str) -> Result<ExportFormat> {

#[cfg(target_os = "linux")]
mod inner {
use std::env;
use std::ffi::OsString;
use std::path::Path;
use std::str::FromStr;

use common::command::package::install;
use common::ui::{Status, UI};
use hcore::url::DEPOT_URL_ENVVAR;
use hcore::channel::DEPOT_CHANNEL_ENVVAR;
use hcore::fs::{cache_artifact_path, FS_ROOT_PATH};
use hcore::package::{PackageIdent, PackageInstall};
use hcore::url::default_depot_url;

use {PRODUCT, VERSION};
use command::pkg::exec;
Expand Down Expand Up @@ -93,7 +103,15 @@ mod inner {
}
}

pub fn start(ui: &mut UI, ident: &PackageIdent, format: &ExportFormat) -> Result<()> {
pub fn start(
ui: &mut UI,
url: &str,
channel: &str,
hab_url: &str,
hab_channel: &str,
ident: &PackageIdent,
format: &ExportFormat,
) -> Result<()> {
let format_ident = format.pkg_ident();
match PackageInstall::load(format.pkg_ident(), None) {
Ok(_) => {}
Expand All @@ -104,8 +122,8 @@ mod inner {
)?;
install::start(
ui,
&default_depot_url(),
None, // TODO: Support channels for export
hab_url,
Some(hab_channel),
&format_ident.to_string(),
PRODUCT,
VERSION,
Expand All @@ -116,6 +134,8 @@ mod inner {
}
}
let pkg_arg = OsString::from(&ident.to_string());
env::set_var(DEPOT_URL_ENVVAR, url);
env::set_var(DEPOT_CHANNEL_ENVVAR, channel);
exec::start(&format_ident, &format.cmd(), vec![pkg_arg])
}
}
Expand All @@ -140,7 +160,15 @@ mod inner {
Err(e)
}

pub fn start(ui: &mut UI, _ident: &PackageIdent, _format: &ExportFormat) -> Result<()> {
pub fn start(
ui: &mut UI,
_url: &str,
_channel: &str,
_hab_url: &str,
_hab_channel: &str,
_ident: &PackageIdent,
_format: &ExportFormat,
) -> Result<()> {
let subcmd = env::args().nth(1).unwrap_or("<unknown>".to_string());
let subsubcmd = env::args().nth(2).unwrap_or("<unknown>".to_string());
ui.warn(
Expand All @@ -151,6 +179,5 @@ mod inner {
Err(Error::SubcommandNotSupported(
format!("{} {}", subcmd, subsubcmd),
))

}
}
24 changes: 21 additions & 3 deletions components/hab/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#![cfg_attr(feature="clippy", feature(plugin))]
#![cfg_attr(feature="clippy", plugin(clippy))]

Expand Down Expand Up @@ -324,10 +325,27 @@ fn sub_pkg_exec(m: &ArgMatches, cmd_args: Vec<OsString>) -> Result<()> {
}

fn sub_pkg_export(ui: &mut UI, m: &ArgMatches) -> Result<()> {
let ident = PackageIdent::from_str(m.value_of("PKG_IDENT").unwrap())?; // Required via clap
let format = &m.value_of("FORMAT").unwrap(); // Required via clap
let ident = PackageIdent::from_str(m.value_of("PKG_IDENT").unwrap())?;
let format = &m.value_of("FORMAT").unwrap();
let env_or_default = henv::var(DEPOT_URL_ENVVAR).unwrap_or(DEFAULT_DEPOT_URL.to_string());
let url = m.value_of("DEPOT_URL").unwrap_or(&env_or_default);
let channel = m.value_of("CHANNEL")
.and_then(|c| Some(c.to_string()))
.unwrap_or(channel::default());
let hab_url = m.value_of("HAB_DEPOT_URL").unwrap_or(&env_or_default);
let hab_channel = m.value_of("HAB_CHANNEL")
.and_then(|c| Some(c.to_string()))
.unwrap_or(channel::default());
let export_fmt = command::pkg::export::format_for(ui, &format)?;
command::pkg::export::start(ui, &ident, &export_fmt)
command::pkg::export::start(
ui,
&url,
&channel,
&hab_url,
&hab_channel,
&ident,
&export_fmt,
)
}

fn sub_pkg_hash(m: &ArgMatches) -> Result<()> {
Expand Down

0 comments on commit e3bdccd

Please sign in to comment.