@@ -9,12 +9,13 @@ use lib "$FindBin::Bin/local/lib/perl5";
99
1010use Cwd qw( realpath getcwd) ;
1111use IO::File;
12+ use JSON::PP qw( encode_json) ;
1213use Data::Dumper;
1314use Digest::MD5;
1415use Getopt::Long;
1516use HTTP::Tiny;
1617use Config::Tiny;
17- use YAML::Tiny qw( LoadFile DumpFile ) ;
18+ use YAML::Tiny qw( LoadFile Dump ) ;
1819use File::Basename qw( basename fileparse) ;
1920use File::Spec::Functions qw( catfile) ;
2021use File::Temp qw( tempfile tmpnam tempdir) ;
@@ -29,11 +30,15 @@ GetOptions(
2930my $recipe_dir = realpath(" $FindBin::Bin /../recipe" );
3031my $repo_dir = realpath(" $FindBin::Bin /../repo" );
3132my $repo_base_dir = realpath(" $FindBin::Bin /../.." );
32- my $archive_dir = realpath(" $FindBin::Bin /../archive" );
33+ my $archive_dir = realpath(" $FindBin::Bin /../archive" );
3334my $git_clone_cmd = realpath(" $FindBin::Bin /git-clone" );
3435
35- my $env = {};
36- my $yamls = [];
36+ my $env = {};
37+ my $yamls = [];
38+ my $workspace = {
39+ folders => [],
40+ settings => {},
41+ };
3742
3843sub handle_recipe {
3944 my $data = shift ;
@@ -54,12 +59,12 @@ sub handle_recipe {
5459 for my $k ( keys %$data ) {
5560 my $repo = $data -> {$k }{location };
5661 my $dest_dir = $data -> {$k }{directory } || do {
57- ( my $dir = $repo ) =~ s { .*/} {} ;
58- " $repo_base_dir /$dir " ;
62+ " $repo_base_dir /@{[basename($repo )]}" ;
5963 };
6064 if ( $dest_dir !~ m {\A /} ) {
6165 $dest_dir = " $repo_base_dir /$dest_dir " ;
6266 }
67+ ( my $basename = $dest_dir ) =~ s { .*/} {} ;
6368
6469 if ( $k eq ' core' ) {
6570 $env -> {MT_HOME_PATH } = $dest_dir ;
@@ -69,18 +74,18 @@ sub handle_recipe {
6974 my $branch = $data -> {$k }{branch } || ' ' ;
7075
7176 for my $pr ( split /\s +/, $pull_reqs ) {
72- my ($pr_repo , $pr_id ) = ($pr =~ m { ([^/]+)/(pull/\d +)} );
77+ my ( $pr_repo , $pr_id ) = ( $pr =~ m { ([^/]+)/(pull/\d +)} );
7378 next unless $pr_repo && $pr_id ;
74- $branch = $pr_id . ' /head' if basename( $dest_dir ) eq $pr_repo ;
79+ $branch = $pr_id . ' /head' if $basename eq $pr_repo ;
7580 }
7681
7782 {
7883 my %repos = map { $_ => 1 } split /\s +/, $repos ;
7984 for my $r ( keys %repos ) {
80- my ($bn , $br ) = $r =~ m { ([^/]+)#(.*)$}
85+ my ( $bn , $br ) = $r =~ m { ([^/]+)#(.*)$}
8186 or next ;
8287
83- next unless basename( $dest_dir ) eq $bn ;
88+ next unless $basename eq $bn ;
8489
8590 $branch = $br ;
8691 delete $repos {$r };
@@ -97,6 +102,9 @@ sub handle_recipe {
97102 print STDERR " $k :$res " ;
98103 }
99104
105+ push @volumes , " - '$dest_dir :/src/$basename :\$ {DOCKER_VOLUME_MOUNT_FLAG:-rw}'" ;
106+ push @{ $workspace -> {folders } }, { path => $basename , };
107+
100108 next if $k eq ' core' ;
101109
102110 my $plugin_dir = $dest_dir ;
@@ -120,7 +128,8 @@ sub handle_recipe {
120128 }
121129
122130 for my $l (@$links ) {
123- push @volumes , " - '$plugin_dir /$l :/var/www/cgi-bin/mt/$l '" ;
131+ push @volumes ,
132+ " - '$plugin_dir /$l :/var/www/cgi-bin/mt/$l :\$ {DOCKER_VOLUME_MOUNT_FLAG:-rw}'" ;
124133 }
125134 }
126135
@@ -146,12 +155,13 @@ YAML
146155}
147156
148157for my $recipe ( split /\s +/, $recipes ) {
149- my $recipe_file = ( $recipe =~ m { ^[/\. ]} && -e $recipe )
158+ my $recipe_file
159+ = ( $recipe =~ m { ^[/\. ]} && -e $recipe )
150160 ? realpath($recipe )
151161 : do {
152- $recipe =~ s {\. yaml\z } {} ;
153- $recipe .= ' .yaml' ;
154- " $recipe_dir /$recipe " ;
162+ $recipe =~ s {\. yaml\z } {} ;
163+ $recipe .= ' .yaml' ;
164+ " $recipe_dir /$recipe " ;
155165 };
156166
157167 # get recipe
@@ -282,8 +292,25 @@ for my $a ( split /\s+/, $archives ) {
282292 handle_recipe( { $basename => { directory => $directory , }, } );
283293}
284294
295+ {
296+ my ( $ws_fh , $ws_file ) = tmpnam();
297+ print $ws_fh encode_json($workspace );
298+ close $ws_fh ;
299+
300+ my ( $fh , $file ) = tmpnam();
301+ print $fh Dump({
302+ version => " 3" ,
303+ services => {
304+ map {
305+ $_ => { volumes => [" $ws_file :/src/mt.code-workspace" ,], },
306+ } qw( mt httpd)
307+ },
308+ });
309+ push @$yamls , $file ;
310+ }
311+
285312if (@$yamls ) {
286- $env -> {DOCKER_COMPOSE_YML_OVERRIDE } = join ( ' ' , map {" -f $_ " } @$yamls );
313+ $env -> {DOCKER_COMPOSE_YAML_OVERRIDE } = join ( ' ' , map {" -f $_ " } @$yamls );
287314}
288315
289316# output args for make command
0 commit comments