Dist-Zilla-Plugin-Docker-API

 view release on metacpan or  search on metacpan

lib/Dist/Zilla/Plugin/Docker/API/Client.pm  view on Meta::CPAN

    my $auth = exists $arg{auth} ? $arg{auth} : $self->auth_for_image_ref($image_ref);

    my $events;
    eval {
        $events = $self->docker->images->push($image_ref, auth => $auth);
    };

    if (my $err = $@) {
        # API::Docker 0.004 croaks on a push failure instead of handing back the
        # errorDetail event in the returned array (against Docker an
        # API::Docker::Error::Stream with ->events, on Podman it may be a plain
        # HTTP error). Pull the message off the stream event when it is there,
        # otherwise report the exception itself (api-docker #12).
        my $message = "$err";
        if (ref $err && $err->can('events')) {
            for my $event (@{ $err->events }) {
                next unless $event->{errorDetail};
                $message = $event->{errorDetail}{message};
                last;
            }
        }
        $self->logger_fatal->("Push error: " . $message);
    }

    # A success still returns the raw array; keep scanning it, defensively, in
    # case an engine reports a failure inside a 200 stream.
    for my $event (@{$events // []}) {
        if ($event->{errorDetail}) {
            $self->logger_fatal->("Push error: " . $event->{errorDetail}{message});
        }
    }
}

sub inspect_image {
    my ($self, $image_ref) = @_;

    return $self->docker->images->inspect($image_ref);
}

# Ask the *registry* whether a reference is already published, through the
# engine's GET /distribution/{name}/json. Credentials are optional: without
# any, the lookup is anonymous, which is what a public image needs.
#
# API::Docker's exists() croaks instead of answering "no" when the engine has
# no /distribution route -- rootless Podman has none, measured -- and that
# croak is deliberately not caught here. "This engine cannot answer" is not
# the same as "the tag is free", and only the caller can decide what to do
# about the difference.
sub remote_tag_exists {
    my ($self, $image_ref) = @_;

    my $auth = $self->auth_for_image_ref($image_ref);

    return $self->docker->distribution->exists(
        $image_ref,
        defined $auth ? ( auth => $auth ) : (),
    ) ? 1 : 0;
}

# Pre-flight for the release push: hand the engine, through POST /auth, the
# very credentials push_image would use for this reference and let the
# registry judge them. A rejected credential croaks; the caller is meant to
# make that fatal before anything is built.
#
# Returns undef when no credential could be resolved for the reference. That
# is not a failure -- an anonymous push to a public registry is a legal thing
# to do, and system->auth croaks on an empty AuthConfig, so there would be
# nothing to ask about.
sub verify_auth_for_image_ref {
    my ($self, $image_ref) = @_;

    my $auth = $self->auth_for_image_ref($image_ref);
    return undef unless $auth;

    return $self->docker->system->auth(auth => $auth);
}

1;

__END__

=pod

=encoding UTF-8

=head1 NAME

Dist::Zilla::Plugin::Docker::API::Client - Thin adapter around API::Docker

=head1 VERSION

version 0.104

=head1 SUPPORT

=head2 Issues

Please report bugs and feature requests on GitHub at
L<https://github.com/Getty/p5-dist-zilla-plugin-docker-api/issues>.

=head1 CONTRIBUTING

Contributions are welcome! Please fork the repository and submit a pull request.

=head1 AUTHOR

Torsten Raudssus <getty@cpan.org>

=head1 COPYRIGHT AND LICENSE

This software is copyright (c) 2026 by Torsten Raudssus <torsten@raudssus.de> L<https://raudssus.de/>.

This is free software; you can redistribute it and/or modify it under
the same terms as the Perl 5 programming language system itself.

=cut



( run in 1.417 second using v1.01-cache-2.11-cpan-007c89162af )