From b0774fc534a88f0e72f7b46e7a1ac376255c5c9e Mon Sep 17 00:00:00 2001 From: sjh9714 <163989462+sjh9714@users.noreply.github.com> Date: Thu, 15 Oct 2026 10:19:24 +0900 Subject: [PATCH 1/2] Fix Dockerfile destination when generating applications --- Changes | 3 +++ lib/Dancer2/CLI/Gen.pm | 2 +- t/e2e/cli/gen.t | 29 +++++++++++++++++++++++++++++ 3 files changed, 33 insertions(+), 1 deletion(-) diff --git a/Changes b/Changes index 7f1d18c27..480ca0196 100644 --- a/Changes +++ b/Changes @@ -1,5 +1,8 @@ {{$NEXT}} + [ BUG FIXES ] + * GH #1851: Generate Dockerfile inside the resolved application directory. + 2.2.2 2026-09-28 19:45:16-04:00 America/New_York [ SECURITY ] diff --git a/lib/Dancer2/CLI/Gen.pm b/lib/Dancer2/CLI/Gen.pm index 8c6d111de..2e61ef4be 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 fa92569cb..00e8853bb 100644 --- a/t/e2e/cli/gen.t +++ b/t/e2e/cli/gen.t @@ -258,6 +258,35 @@ subtest 'the application directory is named after the dashed app name (fixed)' = 'and an explicit -d is honoured verbatim, even with colons in it' ); }; +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$}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 From 029cfe78e931b48e9a4bce9932dd69234c02e28e Mon Sep 17 00:00:00 2001 From: sjh9714 <163989462+sjh9714@users.noreply.github.com> Date: Fri, 16 Oct 2026 14:48:01 +0900 Subject: [PATCH 2/2] Allow CRLF in the generated Dockerfile assertion --- t/e2e/cli/gen.t | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/t/e2e/cli/gen.t b/t/e2e/cli/gen.t index 00e8853bb..f07afc1b0 100644 --- a/t/e2e/cli/gen.t +++ b/t/e2e/cli/gen.t @@ -278,7 +278,7 @@ subtest '-c puts Dockerfile inside the application directory' => sub { 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$}m, + 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' );