diff --git a/Changes b/Changes index 3c3b3aa37..283d7402e 100644 --- a/Changes +++ b/Changes @@ -4,6 +4,7 @@ * None [ BUG FIXES ] + * GH #1851: Generate Dockerfile inside the resolved application directory. * GH #1794: Add support for HTTP QUERY method. Old style plugins that register query will die at load, and apps with their own sub query will get a redefine warning. (Mohammad S Anwar) diff --git a/lib/Dancer2/CLI/Gen.pm b/lib/Dancer2/CLI/Gen.pm index 69e775599..64099681e 100644 --- a/lib/Dancer2/CLI/Gen.pm +++ b/lib/Dancer2/CLI/Gen.pm @@ -172,7 +172,7 @@ sub run { } if( $self->docker ) { - push @$files_to_copy, [ path( $self->parent_command->_dist_dir, 'docker/Dockerfile' ), "$app_name/Dockerfile" ]; + push @$files_to_copy, [ path( $self->parent_command->_dist_dir, 'docker/Dockerfile' ), path( $app_path, 'Dockerfile' ) ]; } my $vars = { diff --git a/t/e2e/cli/gen.t b/t/e2e/cli/gen.t index ca8d48196..43f6a7d61 100644 --- a/t/e2e/cli/gen.t +++ b/t/e2e/cli/gen.t @@ -279,6 +279,35 @@ subtest 'the application directory is named after the dashed app name (fixed)' = } }; +subtest '-c puts Dockerfile inside the application directory' => sub { + # File::Share needs the source module loaded to find this checkout's + # Dockerfile template when the command runs outside the repository. + local $ENV{'PERL5OPT'} = join ' ', ( $ENV{'PERL5OPT'} || () ), '-MDancer2'; + + for my $directory ( undef, 'custom-app' ) { + my $cwd = path('.')->absolute; + my $work = path( tempdir( CLEANUP => 1 ) ); + $work->child('out')->mkpath; + my @directory = defined $directory ? ( '-d', $directory ) : (); + + chdir $work->stringify or die "cannot chdir to $work: $!"; + my $res = gen( '-a', 'Docker::App', '-c', '--path', 'out', @directory ); + chdir $cwd->stringify or die "cannot chdir back to $cwd: $!"; + + my $generated = $work->child( 'out', $directory // 'Docker-App' ); + is( $res->{'status'}, 0, 'generating a Docker application succeeds' ) + or diag "STDERR:\n$res->{stderr}\nSTDOUT:\n$res->{stdout}"; + ok( $generated->child('Dockerfile')->is_file, + "Dockerfile is inside $generated" ); + like( slurp( $generated->child('Dockerfile') ), qr{^WORKDIR /srv/Docker::App\r?$}m, + 'the Dockerfile template is rendered for the application' ); + ok( !$work->child('Docker::App')->exists, + 'no directory named after the raw application name is created' ); + like( slurp( $generated->child('MANIFEST') ), qr/^Dockerfile\r?$/m, + 'MANIFEST lists Dockerfile relative to the application directory' ); + } +}; + subtest 'MANIFEST.SKIP gets the relative dashed name (fixed)' => sub { # This used to build the appended line from the full filesystem path the # app was generated into, so it could never match anything -- MANIFEST.SKIP