feat(init): Add the new/init subcommands (#85)
This commit is contained in:
parent
e3b246ef91
commit
918da22952
19 changed files with 765 additions and 152 deletions
|
|
@ -15,7 +15,7 @@ use blue_build_utils::{
|
|||
};
|
||||
use cached::proc_macro::cached;
|
||||
use log::{debug, info, trace, warn};
|
||||
use miette::{bail, IntoDiagnostic, Result};
|
||||
use miette::{bail, miette, IntoDiagnostic, Result};
|
||||
use once_cell::sync::Lazy;
|
||||
use semver::Version;
|
||||
use serde::Deserialize;
|
||||
|
|
@ -23,19 +23,18 @@ use tempfile::TempDir;
|
|||
|
||||
use crate::{
|
||||
drivers::{
|
||||
opts::{RunOptsEnv, RunOptsVolume},
|
||||
opts::{
|
||||
BuildOpts, BuildTagPushOpts, GetMetadataOpts, PushOpts, RunOpts, RunOptsEnv,
|
||||
RunOptsVolume, TagOpts,
|
||||
},
|
||||
traits::{BuildDriver, DriverVersion, InspectDriver, RunDriver},
|
||||
types::ImageMetadata,
|
||||
types::Platform,
|
||||
},
|
||||
logging::CommandLogging,
|
||||
signal_handler::{add_cid, remove_cid, ContainerId, ContainerRuntime},
|
||||
};
|
||||
|
||||
use super::{
|
||||
opts::{BuildOpts, BuildTagPushOpts, GetMetadataOpts, PushOpts, RunOpts, TagOpts},
|
||||
types::ImageMetadata,
|
||||
BuildDriver, DriverVersion, InspectDriver, RunDriver,
|
||||
};
|
||||
|
||||
#[derive(Deserialize, Debug, Clone)]
|
||||
struct DockerImageMetadata {
|
||||
manifest: DockerImageMetadataManifest,
|
||||
|
|
@ -238,7 +237,14 @@ impl BuildDriver for DockerDriver {
|
|||
trace!("{command:?}");
|
||||
let mut child = command.spawn().into_diagnostic()?;
|
||||
|
||||
write!(child.stdin.as_mut().unwrap(), "{password}").into_diagnostic()?;
|
||||
write!(
|
||||
child
|
||||
.stdin
|
||||
.as_mut()
|
||||
.ok_or_else(|| miette!("Unable to open pipe to stdin"))?,
|
||||
"{password}"
|
||||
)
|
||||
.into_diagnostic()?;
|
||||
|
||||
let output = child.wait_with_output().into_diagnostic()?;
|
||||
|
||||
|
|
@ -399,6 +405,8 @@ fn get_metadata_cache(opts: &GetMetadataOpts) -> Result<ImageMetadata> {
|
|||
|
||||
impl RunDriver for DockerDriver {
|
||||
fn run(opts: &RunOpts) -> std::io::Result<ExitStatus> {
|
||||
trace!("DockerDriver::run({opts:#?})");
|
||||
|
||||
let cid_path = TempDir::new()?;
|
||||
let cid_file = cid_path.path().join("cid");
|
||||
let cid = ContainerId::new(&cid_file, ContainerRuntime::Docker, false);
|
||||
|
|
@ -414,6 +422,8 @@ impl RunDriver for DockerDriver {
|
|||
}
|
||||
|
||||
fn run_output(opts: &RunOpts) -> std::io::Result<std::process::Output> {
|
||||
trace!("DockerDriver::run({opts:#?})");
|
||||
|
||||
let cid_path = TempDir::new()?;
|
||||
let cid_file = cid_path.path().join("cid");
|
||||
let cid = ContainerId::new(&cid_file, ContainerRuntime::Docker, false);
|
||||
|
|
@ -432,7 +442,8 @@ fn docker_run(opts: &RunOpts, cid_file: &Path) -> Command {
|
|||
let command = cmd!(
|
||||
"docker",
|
||||
"run",
|
||||
format!("--cidfile={}", cid_file.display()),
|
||||
"--cidfile",
|
||||
cid_file,
|
||||
if opts.privileged => "--privileged",
|
||||
if opts.remove => "--rm",
|
||||
if opts.pull => "--pull=always",
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue