Project: r100

Build now

Configuration

sparrowdo:
  no_sudo: true
  no_index_update: false
  bootstrap: false
  format: default
  repo: https://sparrowhub.io/repo
  image: melezhik/sparrow:ubuntu_arm
  docker: r100
disabled: false
keep_builds: 100
allow_manual_run: true

plugins:
  Sparky::Plugin::Docker: {}

vars:
  -
    name: threads
    type: input
    default: 5

Job

#!raku

use Sparky::JobApi;

use Sparky::JobApi;

class Pipeline

does Sparky::JobApi::Role

{

  method stage-main {

    bash "raku -V > rakuenv.txt";

    Sparky::JobApi.new(:mine).put-file("rakuenv.txt","rakuenv.txt");

    my $badge = "![Sparky](https://sparky.sparrowhub.io/badge/{tags()<SPARKY_PROJECT>}?foo=bar)";

    "badge.txt".IO.spurt($badge);

    Sparky::JobApi.new(:mine).put-file("badge.txt","badge.txt");

    "list.txt".IO.spurt(config()<list><>.join("\n"));

    Sparky::JobApi.new(:mine).put-file("list.txt","list.txt");

    file-delete "tasks.tar";

    say "archiving tasks/ to tasks.tar";

    bash "tar cf {$*CWD}/tasks.tar -C tasks/ .";

    my @list = config()<list><>;

    my $threads = tags()<threads> || 5;

    my $chunk = Int(@list.elems/$threads);

    my $a = 0;

    say "threads: $threads";
    say "chunk: $chunk";

    my @q; # queue

    for 1 .. $threads -> $i {
      my $docker = "r100.$i.test";
      my $j = Sparky::JobApi.new(:project($docker));
      my @slice = $i == $threads ?? @list[$a .. *] !! @list[$a .. $a + $chunk - 1];
      @slice = @slice.sort;
      $j.put-stash(%( list => @slice ));
      $j.put-file("{$*CWD}/tasks.tar","tasks.tar");
      say "slice: {@slice.raku}";
      $a = $a + $chunk;
      $j.queue({
        description => "zef install test", 
        tags => %(
          :stage<test>,
        ),
        sparrowdo => %(
          #:image<melezhik/sparrow:ubuntu_arm>,
          :docker<r100>,
          :no_sudo,
        )
      });
      push @q, $j;
      say "===";
    }

    my $st = self.wait-jobs(@q, %( :900timeout ) );

    die "there are some failed jobs" if $st<FAIL>;

    die "there are some timeouted jobs" if $st<TIMEOUT>;

    say "all jobs succeed";

  }

  method stage-test {

    my $status = True;

    my $my = Sparky::JobApi.new( :mine );

    my $blob = $my.get-file("tasks.tar");

    directory "tasks";

    my $fh = open "tasks/tasks.tar", :w, :bin;
    $fh.write($blob);
    $fh.close;

    bash "tar -xf tasks.tar  && ls -l", %(
      cwd => "{$*CWD}/tasks",
      description => "unpack tasks.tar",
    );

    my @list = $my.get-stash()<list><>;

    for @list.sort -> $m {
      my $s = task-run "tasks/install", %(
        module => $m;
      );
      if $s<success> == 0 {
        $status = False;
        Sparky::JobApi.new(:mine).put-file("log.txt","$m.install.log");
      }
    }

    die "some modules installations have failed" unless $status;

  }

}



Pipeline.new.run;