Make/Docker/Image/Hub.pm

filter: Statementstmt 65.9% 29 / 44 Branchbran 0.0% 0 / 4 Conditioncond 0.0% 0 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 90.0% 9 / 10 Podpod n/a totaltotal 62.3% 38 / 61 CC 4 SCAR 19.2
CC
4
Cov
58%
_cache_hash
20.0
BEGIN
1.0
BEGIN
1.0
CRAP 6.8
« Make.pm ↑ Summary Make/Docker/Image.pm »
1 package Beam::Make::Docker::Image::Hub;
2 1 our $VERSION = '0.003';
3 # ABSTRACT: A Beam::Make recipe to pull/update a Docker image from hub.docker.com
4  
5 #pod =head1 SYNOPSIS
6 #pod
7 #pod ### Beamfile
8 #pod nordaaker/convos:
9 #pod $class: Beam::Make::Docker::Image::Hub
10 #pod image: nordaaker/convos
11 #pod
12 #pod =head1 DESCRIPTION
13 #pod
14 #pod This L<Beam::Make> recipe class will update a Docker image by checking
15 #pod Docker Hub for changes.
16 #pod
17 #pod This class inherits all attributes from L<Beam::Make::Docker::Image>.
18 #pod
19 #pod =head1 SEE ALSO
20 #pod
21 #pod L<Beam::Make::Docker::Image>, L<Beam::Make::Docker::Container>, L<Beam::Make>, L<https://docker.com>
22 #pod
23 #pod =cut
24  
25 1 ▶use v5.20;
Subroutine BEGIN: called CC=1 SCAR=0.0
26 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
27 1 ▶use autodie qw( :all );
Subroutine BEGIN: called CC=1 SCAR=0.0
28 1 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
29 1 ▶use Log::Any qw( $LOG );
Subroutine BEGIN: called CC=1 SCAR=0.0
30 1 ▶use JSON::PP qw( decode_json );
Subroutine BEGIN: called CC=1 SCAR=0.0
31 1 ▶use HTTP::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
32 1 ▶use Digest::SHA qw( sha1_base64 );
Subroutine BEGIN: called CC=1 SCAR=0.0
33 1 ▶use experimental qw( signatures postderef );
Subroutine BEGIN: called CC=1 SCAR=0.0
34  
35 1 extends 'Beam::Make::Docker::Image';
36  
37 0 ▶sub _cache_hash( $self ) {
Subroutine _cache_hash: not called CC=4 SCAR=30.0
38 # Check the Docker Hub API to get the image's ID
39 0 my ( $repo, $tag ) = split /:/, $self->image;
40 0 ▶ $tag //= 'latest';
Condition0%0/2
$tag //= "latest"
l!l
00
MC/DC0%0/1
$tag //= "latest"
$tag
Truth table0%0/2
A
A= $tag
Aresult
11
00
41 0 my $token_uri = "https://auth.docker.io/token";
42 0 my $token_data = {
43 service => 'registry.docker.io',
44 scope => sprintf( 'repository:%s:pull', $repo ),
45 };
46 0 my $http = HTTP::Tiny->new;
47 0 $token_uri .= '?' . $http->www_form_urlencode( $token_data );
48 0 my $res = $http->get( $token_uri );
49 0 ▶ die "Could not get token: $res->{content}" unless $res->{success};
Branch: 1 branch
BranchTrueFalseTotal
unless $res->{"success"} 0 0 0
50 0 my $token = decode_json( $res->{content} )->{token};
51 0 my $manifest_uri = sprintf 'https://registry-1.docker.io/v2/%s/manifests/%s',
52 $repo, $tag;
53 0 my %headers = (
54 Authorization => "Bearer $token",
55 Accept => "application/vnd.docker.distribution.manifest.v2+json",
56 );
57 0 $res = $http->get( $manifest_uri, { headers => \%headers } );
58 0 ▶ die "Could not get manifest: $res->{content}" unless $res->{success};
Branch: 1 branch
BranchTrueFalseTotal
unless $res->{"success"} 0 0 0
59 0 my $manifest = decode_json( $res->{content} );
60 0 return sha1_base64( $manifest->{config}{digest} . $self->_config_hash );
61 }
62  
63 1 1;
64  
65 __END__
« Make.pm ↑ Summary Make/Docker/Image.pm »