App-Actions
view release on metacpan or search on metacpan
lib/App/Actions/Runner/Containers.pm view on Meta::CPAN
# Exit status: Returns a name of at most 63 safe characters, with no hyphen
# or dot at either end; 'local' if none is left.
# Side effects: None.
sub _hostname {
my ($value) = @_;
$value = '' unless defined $value;
$value =~ s/[^A-Za-z0-9.-]/-/g;
# A hostname may not begin or end with a hyphen or a dot, so a job id
# such as _build or build_ loses them. Each end separately, and the
# end after the cut, which can leave one last.
$value =~ s/\A[.-]+//;
$value = substr($value, 0, $NAME_LENGTH);
$value =~ s/[.-]+\z//;
return length $value ? $value : 'local';
}
# Every _name routine above may be called only from this package.
# Sub::Private's mode is process-wide, so it is set to enforce for this one
# call rather than for good, which would change how other modules' :Private
# routines behave.
BEGIN {
local $Sub::Private::config{mode} = 'enforce';
Sub::Private->import(@{ App::Actions::Access->private_names(__PACKAGE__) });
}
1;
__END__
=head1 LIMITATIONS
=over 4
=item * Service credentials are not used: the local Docker login is.
=item * A container that a parallel job started outlives the run when that
job's process is killed, because only the process that started a container
knows its name.
=item * The fault named in a start failure comes from matching Docker's
English messages. A daemon that reports in another language, or a future
Docker that rewords them, gets the quotation without a verdict.
=back
=head1 COMMON PITFALLS
=over 4
=item * B<Always call L</remove_all> at the end of a run>, even after an
error, unless the run keeps its containers. Otherwise containers and
networks are left on the computer.
=item * B<Pass the same C<\@started> list to the start and clean-up
calls.> L</cleanup_job> removes what is in that list, newest first.
=item * B<A service must keep running.> A database image that exits at
once (for example because a required password variable is missing) fails
the job, with its last log lines in the message.
=item * B<Service ports are not published.> Steps reach a service by its
id on the job's network (C<postgres:5432>), not on C<localhost>. Only
C<ports:> mappings in the workflow publish ports on your computer.
=item * B<Container options from the workflow are passed to Docker as they
are.> C<container.options> and C<container.volumes> can mount any folder
of your computer. Run only workflows you trust.
=item * B<Names are cut to 63 characters.> Very long job ids are
shortened, so do not rely on the full id being in the name.
=back
=head1 ENCODING
Container and network names are made ASCII: unsafe characters in job and
service ids are replaced. Image names are ASCII, as Docker requires.
Environment values and C<options> come from the workflow as Perl character
strings and are passed to Docker as UTF-8 bytes, so non-ASCII text and emoji
work in values. The project path is used as bytes. The log lines quoted in
a failure message are what the container printed, as bytes.
=head1 AUTHOR
Nigel Horne, C<njh@nigelhorne.com>
=head1 FORMAL SPECIFICATION
This section describes each routine in the Z notation, a precise
mathematical language for describing programs. You do not need to read it
to use the module: everything here is also said in plain words in the
sections above. It is for readers who want to check exactly what a routine
promises.
How to read it: a box names a routine. The lines above the middle rule
declare the values it works with. A name ending in C<?> is an input, and a
name ending in C<!> is an output. C<ÎState> means the routine changes
nothing, and C<ÎState> means it can change the state. The lines below the
rule are the conditions that are always true when the routine returns.
=head2 new
ââ Containers ââââââââââââââââââââââââââââââââââââââ
â containers : seq NAME -- started and not yet removed
â networks : seq NAME -- created and not yet removed
â counter : â -- resource names issued
ââââââââââââââââââââââââââââââââââââââââââââââââââââ
â containers and networks have no duplicates
ââââââââââââââââââââââââââââââââââââââââââââââââââââ
=head2 name
ââ Name ââââââââââââââââââââââââââââââââââââââââââââ
â ÎContainers
â kind?, suffix? : seq CHAR
â name! : seq CHAR
ââââââââââââââââââââââââââââââââââââââââââââââââââââ
â counter' = counter + 1
( run in 2.676 seconds using v1.01-cache-2.11-cpan-f5f21f1076c )