API-Docker
view release on metacpan or search on metacpan
lib/API/Docker/API/Images.pm view on Meta::CPAN
sub search {
my ($self, $term, %opts) = @_;
croak "Search term required" unless $term;
my %params;
$params{term} = $term;
$params{limit} = $opts{limit} if defined $opts{limit};
$params{filters} = $self->_normalise_filters($opts{filters})
if defined $opts{filters};
return $self->client->get('/images/search',
params => \%params,
%{ $self->_request_options },
);
}
sub prune {
my ($self, %opts) = @_;
my %params;
$params{filters} = $self->_normalise_filters($opts{filters})
if defined $opts{filters};
return $self->client->post('/images/prune', undef,
params => \%params,
%{ $self->_request_options },
);
}
sub get {
my ($self, $name, %opts) = @_;
croak "Image name required" unless $name;
# `raw` and `on_chunk` are the same promise made twice -- hand the response
# bytes over undecoded -- so only one of them is sent: with a callback there
# is no return value for `raw` to describe.
return $self->client->get("/images/$name/get",
%{ $self->_request_options },
exists $opts{on_chunk} ? ( on_chunk => $opts{on_chunk} ) : ( raw => 1 ));
}
sub get_all {
my ($self, @names) = @_;
# The list form has nowhere to put an option: get_all('a', 'b') is names all
# the way down, and a trailing `on_chunk => sub {...}` in it would be two
# more image names as far as this method can tell. So options ride behind
# the ArrayRef form, which already exists for exactly one list.
my %opts;
if (ref $names[0] eq 'ARRAY') {
my $list = shift @names;
croak __PACKAGE__ . '->get_all takes options as pairs after the ArrayRef '
. 'of names; got an odd number of them' if @names % 2;
%opts = @names;
@names = @$list;
}
croak "At least one image name required" unless @names;
# `names` is a repeated query parameter -- names=a&names=b -- and nothing
# else is accepted: measured against Podman 5.4.2, the comma-joined spelling
# answers 500 with 'parsing reference "alpine:3,registry:2": invalid
# reference format'. An ArrayRef param value is exactly that repetition;
# _request escapes each element with its own _uri_encode, which leaves `/`
# and `:` raw so an image reference survives intact.
return $self->client->get('/images/get', params => { names => \@names },
%{ $self->_request_options },
exists $opts{on_chunk} ? ( on_chunk => $opts{on_chunk} ) : ( raw => 1 ));
}
sub load {
my ($self, $tar, %opts) = @_;
croak "Tar archive required (raw bytes or a scalar ref)" unless defined $tar;
my %params;
$params{quiet} = $opts{quiet} ? 1 : 0 if defined $opts{quiet};
my $raw = ref $tar eq 'SCALAR' ? $$tar : $tar;
return $self->client->_request('POST', '/images/load',
raw_body => $raw,
content_type => 'application/x-tar',
params => \%params,
%{ $self->_request_options },
exists $opts{on_event} ? ( on_event => $opts{on_event} ) : ( ndjson => 1 ),
);
}
sub commit {
my ($self, %opts) = @_;
croak "container required" unless $opts{container};
my %params;
$params{container} = $opts{container};
$params{repo} = $opts{repo} if defined $opts{repo};
$params{tag} = $opts{tag} if defined $opts{tag};
$params{comment} = $opts{comment} if defined $opts{comment};
$params{author} = $opts{author} if defined $opts{author};
$params{pause} = $opts{pause} ? 1 : 0 if defined $opts{pause};
# `changes` is a repeated query parameter on the wire, but the engine parses
# each value as a Dockerfile snippet and a snippet may span lines, so one
# newline-joined value carries a list just as well. Measured against Podman
# 5.4.2: changes=LABEL%20a%3Db%0AEXPOSE%208080 and two separate changes=
# pairs produce the same image. The joined form is used because it fits the
# transport's one-value-per-key params encoder.
if (defined $opts{changes}) {
$params{changes} = ref $opts{changes} eq 'ARRAY'
? join("\n", @{$opts{changes}})
: $opts{changes};
}
return $self->client->post('/commit', $opts{config},
params => \%params,
%{ $self->_request_options },
);
}
sub build_prune {
my ($self, %opts) = @_;
( run in 1.358 second using v1.01-cache-2.11-cpan-54e63673c56 )