Changeset 3204 in /cluster/svnroot


Ignore:
Timestamp:
May 19, 2011 4:40:16 PM (10 years ago)
Author:
fitz
Message:

(#631) More work on build-bccd

File:
1 edited

Legend:

Unmodified
Added
Removed
  • bccd-ng/branches/fitz-devel/bin/bccd-build.pl

    r3203 r3204  
    33use strict;
    44use File::Basename;
     5use MIME::Lite;
     6use File::Temp;
    57
     8my $SVNROOT = "http://bccd-ng.cluster.earlham.edu/svn/bccd-ng";
     9
     10# I know Bccd.pm has a similar looking routine, but up until fetching the
     11# auto_build script, I want this to be as independant as possible.
    612sub get_svn_rev( $ ) {
    713        my ($svnurl) = @_;
    814        my $rev;
    915
    10         `svn info $svnurl` =~ m/Revision:\s+(\d+)/;
     16        `svn info $svnurl 2> /dev/null` =~ m/Revision:\s+(\d+)/;
    1117        $rev = $1;
    1218
     
    1824}
    1925
    20 my (@devs, $from, $branch, $user);
    21 my $SVNROOT = "http://bccd-ng.cluster.earlham.edu/svn/bccd-ng";
     26# Instead of using die, which causes a "Mail delivery failure", send an
     27# actual email informing the sender of the error
     28sub die_email( $ ) {
     29        my ($error) = @_;
     30        # TODO Send useful email instead of just dying.
     31        die $error;
     32}
     33
     34# Verify given branch is a valid branch
     35#
     36# Allowed formats for subject:
     37#       - Relative path, in relation to SVNROOT, e.g., tags/bccd-3.0.0 or trunk
     38#       - Relative path, in relation to branches/, e.g., fitz-devel
     39# - Absolute path, no URL spec, e.g., /cluster/svnroot/bccd-ng/tags/bccd-3.0.0
     40# - Absolute, e.g., file:///cluster/svnroot/bccd-ng/tags/bccd-3.0.0
     41sub get_branch_rev( $ ) {
     42        my ($subject) = @_;
     43        my ($branch, $revision);
     44       
     45        if (($revision = get_svn_rev($SVNROOT . "/" . $subject)) != 0) {
     46                $branch = $subject;
     47        } elsif (($revision = get_svn_rev($SVNROOT . "/branches/" . $subject)) != 0) {
     48                $branch = "branches/" . $subject;
     49        } elsif (($revision = get_svn_rev("http://" . $subject)) != 0) {
     50                $branch = $subject;
     51                $branch =~ s/\/cluster\/svnroot\/bccd-ng\///;
     52        } elsif (($revision = get_svn_rev($subject)) != 0) {
     53                $branch = $subject;
     54                $branch =~ s/\a+:\/\/\/cluster\/svnroot\/bccd-ng\///g
     55        } else {
     56                die_email("ERROR: could not get revision number for $subject");
     57        }
     58
     59        return ($branch, $revision);
     60}
     61
     62my (@devs, $from, $subject, $user);
    2263
    2364# Read the message. "From" will be checked to see if the sender is an
     
    3071    s/.*<(.*)>.*/\1/;
    3172    $from = $_;
     73                $user = $from;
    3274    $user =~ s/(.*)@.*/\1/;
    3375  } elsif (m/^Subject: /) {
    3476    s/^Subject: //;
    35     $branch = $_;
     77    $subject = $_;
    3678  }
    3779}
     
    4082# cluster. If they are, then they can commit to the repo, so we assume
    4183# they're clean.
    42 open(LDAP, "/usr/bin/ldapsearch -h cluster.earlham.edu -x -b \"ou=group,dc=cluster,dc=loc\" \"cn=software\"|");
     84open(LDAP, "/usr/bin/env ldapsearch -h cluster.earlham.edu -x -b \"ou=group,dc=cluster,dc=loc\" \"cn=software\"|");
    4385
    4486while (<LDAP>) {
    4587  my ($r, $member);
    4688  if (m/^memberUid/) {
    47     ($r,$user) = split;
    48     push @devs, $user;
     89    ($r,$member) = split;
     90    push @devs, $member;
    4991  }
    5092}
     
    5597# could send from an address that doesn't have the same username as their
    5698# cluster name, so tell them.
    57 if (!grep($from, @devs)) {
    58   my $message = <<<"EOF"
    59 I'm sorry $user, but I did not find you in our list of authorized developers and will not be taking any action on your behalf.
     99if (!grep(/$user/, @devs)) {
     100  my $message = <<EOF;
     101I'm sorry, $user, but I did not find you in our list of authorized developers and will not be taking any action on your behalf.
    60102
    61103If you believe this is in error, try sending from a different address or sending a note to bccd-developers -at- bccd -dot- net informing us of the problem.
    62104
    63 If you know you aren't an authorized developer, but would like to be, also send an email to the developers list telling us who you are and why you would like to be a developer.
     105If you know you aren't an authorized developer, but would like to be, also send an email to the developers telling us who you are and why you would like to be a developer.
    64106
    65107Thanks,
     
    67109EOF
    68110
    69   # XXX POTENTIAL SECURITY HOLES HERE XXX
    70   # If message is sent with a malformed "from" field, bad things could potentially happen
    71   `echo -e $message | mail -s "Re: build-bccd" $from`;
     111        my $msg = MIME::Lite->new(
     112                From    => 'bccd-build@bccd.net',
     113                To      => $from,
     114                Subject => "Re: $subject",
     115                Data    => $message
     116        );
     117        $msg->send;
     118
    72119  exit;
    73120}
    74121
    75122# Otherwise, we can continue with kicking off a build.
     123my ($branch, $revision) = get_branch_rev($subject);
    76124
    77 # -- verify given branch is a valid branch
    78 # Allowed formats for subject:
    79 #       - Relative path, in relation to the svn root (/cluster/svnroot/bccd-ng), e.g., tags/bccd-3.0.0 or trunk
    80 #       - Relative path, in relation to branches/, e.g., fitz-devel
    81 #       - Absolute path, no URL spec, e.g., /cluster/svnroot/bccd-ng/tags/bccd-3.0.0
    82 #       - Absolute, e.g., file:///cluster/svnroot/bccd-ng/tags/bccd-3.0.0
    83 my $revision;
    84 if (($revision = get_svn_rev($SVNROOT . $branch)) != 0) {}
    85 elsif (($revision = get_svn_rev($SVNROOT . "/branches/" . $branch)) != 0) {}
    86 elsif (($revision = get_svn_rev("http://" . $branch)) != 0) {}
    87 elsif (($revision = get_svn_rev($branch)) != 0) {}
    88 else {
    89         die "ERROR: could not get revision number for $branch\n";
    90 }
    91 
    92 my $isoprefix = "bccd-build-" . basename($branch) . "-r" . $revision;
     125my $isoprefix = "bccd-" . basename($branch) . ".r" . $revision;
    93126
    94127# PBS submission script
    95 my $script = <<"EOF"
    96 tmp=`mktemp -d /tmp/bccd-XXXXXXXXXXX`
     128my $script = <<EOF;
     129#!/bin/bash
     130
     131tmp=\$(mktemp -d)
    97132cd \$tmp
    98 svn cat file:///cluster/svnroot/bccd-ng/$branch/bin/build_livecd.pl > build_livecd.pl
     133svn cat $SVNROOT/$branch/bin/auto_build_wrapper.sh > auto_build_wrapper.sh
     134chmod +x auto_build_wrapper.sh
    99135
    100 chmod +x build_livecd.pl
    101 sudo ./build_livecd.pl --arch i386 --suite lenny --outiso $iso_prefix.i386.iso
    102 sudo ./build_livecd.pl --arch amd64 --suite lenny --outiso $iso_prefix.amd64.iso
    103 EOF;
     136for arch in i386 amd64; do
     137        echo "ARCH=\$arch
     138DBUSER=dc_tester
     139WEBSVN=\"$SVNROOT/\"
     140BRANCH=\"$branch/\"
     141BINDIR=\"/bin/\"
     142BLDCD=\"build_livecd.pl\"
     143PATH=\\\$PATH:/sbin:/usr/sbin
     144OUTBASE=/cluster/bccd-ng/testing/from
     145OUTISO=\\\$OUTBASE/$isoprefix.\\\${ARCH}.iso
     146TEMPISO=\\\$(mktemp \\\${OUTISO}.XXXXXXXX)" > build.\${arch}.conf
     147
     148        sudo ./auto_build_wrapper.sh -c ./build.\${arch}.conf
     149done
     150
     151EOF
     152
     153my $tmp = File::Temp->new( TEMPLATE => 'build-bccd.XXXXX',
     154        DIR => '/tmp',
     155        SUFFIX => '.sh',
     156        UNLINK => 0);
     157print $tmp $script;
     158
     159my @qsub = ('qsub', '-q', '@t-voc', '-e', 'edu-grid.org:/home/fitz', '-o', 'edu-grid.org:/home/fitz', $tmp);
     160system(@qsub);
     161
     162# TODO Wait for job to complete, send informative email
     163
     164__END__
Note: See TracChangeset for help on using the changeset viewer.