fix: Check for buildx before using docker

This commit is contained in:
Gerald Pinder 2025-02-06 13:18:42 -05:00
parent 46ef12e0bb
commit 0da26e37d5
2 changed files with 18 additions and 2 deletions

View file

@ -57,6 +57,10 @@ impl DockerDriver {
fn setup() -> Result<()> {
trace!("DockerDriver::setup()");
if !Self::has_buildx() {
bail!("Docker Buildx is required to use the Docker driver");
}
let mut lock = DOCKER_SETUP.lock().expect("Should lock");
if *lock {
@ -105,6 +109,13 @@ impl DockerDriver {
drop(lock);
Ok(())
}
#[must_use]
pub fn has_buildx() -> bool {
pipe!(cmd!("docker", "--help") | cmd!("grep", "buildx"))
.status()
.is_ok_and(|status| status.success())
}
}
impl DriverVersion for DockerDriver {

View file

@ -58,7 +58,9 @@ impl DetermineDriver<BuildDriverType> for Option<BuildDriverType> {
blue_build_utils::check_command_exists("podman"),
blue_build_utils::check_command_exists("buildah"),
) {
(Ok(_docker), _, _) if DockerDriver::is_supported_version() => {
(Ok(_docker), _, _)
if DockerDriver::is_supported_version() && DockerDriver::has_buildx() =>
{
BuildDriverType::Docker
}
(_, Ok(_podman), _) if PodmanDriver::is_supported_version() => {
@ -70,7 +72,10 @@ impl DetermineDriver<BuildDriverType> for Option<BuildDriverType> {
_ => panic!(
"{}{}{}{}",
"Could not determine strategy, ",
format_args!("need either docker version {}, ", DockerDriver::VERSION_REQ,),
format_args!(
"need either docker version {} with buildx, ",
DockerDriver::VERSION_REQ,
),
format_args!("podman version {}, ", PodmanDriver::VERSION_REQ,),
format_args!(
"or buildah version {} to continue",