Created
February 10, 2011 19:17
-
-
Save japhb/821144 to your computer and use it in GitHub Desktop.
Proof of concept Dist::Zilla::Plugin::ScpUpload
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package Dist::Zilla::Plugin::ScpUpload; | |
# ABSTRACT: Release a dist by uploading it with scp | |
use Moose; | |
use Moose::Autobox; | |
with 'Dist::Zilla::Role::Releaser'; | |
use IO::Handle; | |
use IPC::Open3; | |
sub mvp_multivalue_args { return qw(destinations) } | |
sub mvp_aliases { return { destination => 'destinations' } } | |
has destinations => ( | |
is => 'ro', | |
isa => 'ArrayRef', | |
default => sub { [] }, | |
); | |
sub release { | |
my ($self, $archive) = @_; | |
my $source = "$archive"; | |
my @dests = $self->{destinations}->flatten; | |
$self->log_fatal("No destinations to upload to") unless @dests; | |
for my $dest (@dests) { | |
$self->log("Uploading to $dest"); | |
# Inspired by the code in Net::SCP::scp() | |
my @cmd = ('scp', '-pqB', $source, $dest); | |
my ($in, $out, $err) = (IO::Handle->new, IO::Handle->new, IO::Handle->new); | |
local $SIG{CHLD} = 'DEFAULT'; | |
my $pid = open3($in, $out, $err, @cmd); | |
waitpid $pid, 0; | |
$self->log_fatal(<$err>) if $? >> 8; | |
} | |
} | |
__PACKAGE__->meta->make_immutable; | |
no Moose; | |
1; | |
__END__ | |
=head1 SYNOPSIS | |
[ScpUpload] | |
destination = billybob@repo.example.com:/repo/uploads/ | |
destination = billyb@webhome.example.net:~/foo_releases/latest.tar.gz | |
=head1 DESTINATION | |
This C<Releaser> plugin uploads the release tarball to one or more destinations | |
using the system F<scp> binary via L<IPC::Open3>. If any of the copy | |
operations fails, it will exit with the error message from C<scp>; otherwise | |
it will simply note the completion of each upload in turn. | |
B<NOTE:> It is critical that you have already successfully logged into the | |
destination servers using C<ssh>, C<scp>, or C<sftp> before, I<without> a | |
password (using ssh keys). If a password is required, or the C<scp> client | |
asks for approval to handle a new or changed host key, this plugin may hang. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment