Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add a git-module that can pull source from a git repo #26

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions examples/http_load/index.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
default:
name: httpload
git: git://github.com/timbunce/http_load.git
git-branch: master
summary: a http load tester
version: 1.0

4 changes: 4 additions & 0 deletions examples/http_load/scripts/build
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash

mkdir -p $DESTDIR/usr/{bin,share/man/man1}
make install BINDIR=$DESTDIR/usr/bin MANDIR=$DESTDIR/usr/share/man/man1
6 changes: 6 additions & 0 deletions examples/nginx/index.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
default:
name: nginx
http: http://nginx.org/download/nginx-1.2.6.tar.gz
version: 1.2.6

# cpan-module will fetch directly from CPAN
3 changes: 3 additions & 0 deletions examples/nginx/scripts/build
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/sh
./configure --prefix=/opt/nginx --without-pcre --without-http_gzip_module --without-http_rewrite_module
make install DESTDIR=$DESTDIR
2 changes: 2 additions & 0 deletions root/usr/share/multipkg/default.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ default:
version: '0.0001'
shebangmunge: 1
os_specific: no
xfercmd: '/usr/bin/curl -s -o %s %u'
git-branch: master

rpm:
autoreqprov: no
Expand Down
4 changes: 3 additions & 1 deletion source/lib/Seco/CPAN.pm
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ BEGIN {

sub _init {
my $self = shift;
mkdir $self->depositdir;
$self->tmpdir(tempdir(CLEANUP => 0))
unless(-d $self->tmpdir);
return 1;
Expand Down Expand Up @@ -93,8 +94,9 @@ sub pull {
system('cp', $tarball, $self->depositdir);
return undef if($? >> 8);
$tarball =~ s/^.*\///;
$name =~ s/::/-/g;
return { tarball => $self->depositdir . "/" . $tarball,
name => $name,
name => 'cpan-' . $name,
version => $version };
}

Expand Down
55 changes: 55 additions & 0 deletions source/lib/Seco/Git.pm
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package Seco::Git;

# created at : 2013-03-21 15:56:19
# author : Jianing Yang <jianingy.yang AT gmail DOT com>

use strict;
use base qw(Seco::Class);

use File::Copy qw(copy);
use File::Temp qw/tempfile tempdir/;
use Cwd;
use Getopt::Long qw/:config require_order gnu_compat/;
use Git;

BEGIN {
__PACKAGE__->_accessors(branch => undef,
depositdir => undef,
tmpdir => undef);
__PACKAGE__->_requires(qw/depositdir/);
}

sub _init {
my $self = shift;

mkdir $self->depositdir
unless(-d $self->depositdir);

$self->tmpdir(tempdir(CLEANUP => 0))
unless(-d $self->tmpdir);

return 1;
}

# Clone the source repository to a local directory
sub clone {
my ($repo, $target, $opts) = @_;
info("Cloning from $repo to $target");
my $out = Git::command('clone', '-b', $opts->{B}, $repo, $target);
info($out);
}

sub pull {
my $self = shift;
my $repo = shift;

my $basedir = $self->tmpdir . "/build";
mkdir $basedir unless(-d $basedir);

my $target = $self->depositdir . '/source';
my $out = Git::command('clone', '-b', $self->branch, $repo, $target);

return { sourcedir => $target };
}

1;
52 changes: 52 additions & 0 deletions source/lib/Seco/HTTP.pm
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package Seco::HTTP;

# created at : 2013-03-21 15:56:19
# author : Jianing Yang <jianingy.yang AT gmail DOT com>

use strict;
use base qw(Seco::Class);

use File::Copy qw(copy);
use File::Temp qw/tempfile tempdir/;
use Cwd;
use Getopt::Long qw/:config require_order gnu_compat/;

BEGIN {
__PACKAGE__->_accessors(xfercmd => undef,
depositdir => undef,
tmpdir => undef);
__PACKAGE__->_requires(qw/depositdir/);
}

sub _init {
my $self = shift;

mkdir $self->depositdir
unless(-d $self->depositdir);

$self->tmpdir(tempdir(CLEANUP => 0))
unless(-d $self->tmpdir);

return 1;
}

sub pull {
my $self = shift;
my $url = shift;

my $basedir = $self->tmpdir . "/build";
mkdir $basedir unless(-d $basedir);

my $tarball = $self->depositdir . '/source.tar.gz';
my $xfercmd = $self->xfercmd;

$xfercmd =~ s/%s/$tarball/;
$xfercmd =~ s/%u/$url/;

system($xfercmd);
return undef if($? >> 8);

return { tarball => $tarball };
}

1;
75 changes: 60 additions & 15 deletions source/lib/Seco/Multipkg.pm
Original file line number Diff line number Diff line change
Expand Up @@ -413,32 +413,29 @@ sub runcmd {
return @last;
}

sub build {
sub fetch {
my $self = shift;
my $target;

chdir $self->info->directory;
my $realbuild = $self->builddir;
# build cpan module
if ( $target = $self->info->data->{'cpan-module'} ) {

# check for cpan-module
if ( my $module = $self->info->data->{'cpan-module'} ) {
eval { require Seco::CPAN; };
die "Seco::CPAN required to install cpan modules" if ($@);
$self->infomsg("Fetching $module from CPAN");
mkdir $self->tmpdir . "/cpan";
my $cpan = Seco::CPAN->new(
$self->infomsg("Fetching $target from CPAN");
my $agent = Seco::CPAN->new(
depositdir => ( $self->tmpdir . "/cpan" ),
tmpdir => $self->tmpdir
);
my $hash = $cpan->pull($module)
or die "Unable to pull $module: $!";
my $loc = $hash->{tarball};

my $hash = $agent->pull($target)
or die "Unable to pull $target: $!";
my $name = lc $hash->{name};
$name =~ s/::/-/g;
my $loc = $hash->{tarball};
my $version = $hash->{version};
my $prefix = 'cpan';

if ( "$prefix-$name" ne $self->info->data->{name} ) {
$self->forceok( "Package wants to be called $prefix-$name, "
if ( $name ne $self->info->data->{name} ) {
$self->forceok( "Package wants to be called $name, "
. "you asked for "
. $self->info->data->{name}
. "\n" );
Expand All @@ -447,7 +444,55 @@ sub build {
$self->info->data->{sourcetar} = $loc;
$self->info->data->{version} = $version;

}
# build from http
elsif ( $target = $self->info->data->{'http'} ) {

eval { require Seco::HTTP; };
die "Seco::HTTP required to build package from web: $@" if ($@);
$self->infomsg("Fetching $target");
my $agent = Seco::HTTP->new(
xfercmd => $self->info->data->{xfercmd},
depositdir => ( $self->tmpdir . "/source" ),
tmpdir => $self->tmpdir
);

my $hash = $agent->pull($target)
or die "Unable to pull $target: $!";
my $loc = $hash->{tarball};

$self->info->data->{sourcetar} = $loc;

}
# build from git
elsif ( $target = $self->info->data->{'git'} ) {

eval { require Seco::Git; };
die "Seco::Git required to build package from web: $@" if ($@);
$self->infomsg("Fetching $target");
my $agent = Seco::Git->new(
branch => $self->info->data->{'git-branch'},
depositdir => ( $self->tmpdir . "/git" ),
tmpdir => $self->tmpdir
);

my $hash = $agent->pull($target)
or die "Unable to pull $target: $!";
my $loc = $hash->{sourcedir};

$self->info->data->{sourcedir} = $loc;

}
}

sub build {
my $self = shift;

chdir $self->info->directory;
my $realbuild = $self->builddir;

# fetch source from remote
$self->fetch();

# build the source if there is any
if ( $self->info->data->{sourcedir} and -d $self->info->data->{sourcedir} ) {
Expand Down