Skip to content

Commit d49b75f

Browse files
committed
fix: use COPY instead of here-strings for source files in Dockerfile
Docker RUN collapses PowerShell here-strings (@'...'@) to single lines, breaking the parser. Extract hash-password and efmigrate source files to separate directories and COPY them into the build stages.
1 parent 2e45bbe commit d49b75f

5 files changed

Lines changed: 57 additions & 69 deletions

File tree

cloudformation/scenarios/localgov-ims/docker/Dockerfile

Lines changed: 5 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -42,45 +42,12 @@ RUN msbuild src\LocalGovIms.sln `
4242

4343
WORKDIR C:\hash-password
4444

45+
# Copy hash-password source files (avoids PowerShell here-string issues in Docker)
46+
COPY hash-password/ C:\hash-password\
47+
4548
# Download the NuGet package for ASP.NET Identity
4649
RUN nuget install Microsoft.AspNet.Identity.Core -Version 2.2.4 -OutputDirectory packages
4750

48-
# Write the C# source
49-
RUN Set-Content -Path Program.cs -Value @' `
50-
using System; `
51-
using Microsoft.AspNet.Identity; `
52-
class Program { `
53-
static void Main() { `
54-
var password = Console.ReadLine(); `
55-
var hasher = new PasswordHasher(); `
56-
Console.Write(hasher.HashPassword(password)); `
57-
} `
58-
} `
59-
'@
60-
61-
# Write the project file
62-
RUN Set-Content -Path HashPassword.csproj -Value @' `
63-
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> `
64-
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" /> `
65-
<PropertyGroup> `
66-
<OutputType>Exe</OutputType> `
67-
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion> `
68-
<OutputPath>bin\</OutputPath> `
69-
<AssemblyName>hash-password</AssemblyName> `
70-
</PropertyGroup> `
71-
<ItemGroup> `
72-
<Reference Include="Microsoft.AspNet.Identity.Core"> `
73-
<HintPath>packages\Microsoft.AspNet.Identity.Core.2.2.4\lib\net45\Microsoft.AspNet.Identity.Core.dll</HintPath> `
74-
</Reference> `
75-
<Reference Include="System" /> `
76-
</ItemGroup> `
77-
<ItemGroup> `
78-
<Compile Include="Program.cs" /> `
79-
</ItemGroup> `
80-
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> `
81-
</Project> `
82-
'@
83-
8451
RUN msbuild HashPassword.csproj /p:Configuration=Release /verbosity:minimal
8552

8653
# Copy to tools directory
@@ -119,39 +86,8 @@ RUN dotnet restore ; `
11986

12087
WORKDIR C:\efmigrate
12188

122-
# Write the project file referencing the GOV.UK Pay Infrastructure project
123-
RUN Set-Content -Path efmigrate.csproj -Value @' `
124-
<Project Sdk="Microsoft.NET.Sdk"> `
125-
<PropertyGroup> `
126-
<OutputType>Exe</OutputType> `
127-
<TargetFramework>net6.0</TargetFramework> `
128-
<ImplicitUsings>enable</ImplicitUsings> `
129-
</PropertyGroup> `
130-
<ItemGroup> `
131-
<ProjectReference Include="..\src\Infrastructure\Infrastructure.csproj" /> `
132-
</ItemGroup> `
133-
</Project> `
134-
'@
135-
136-
# Write the migration runner
137-
RUN Set-Content -Path Program.cs -Value @' `
138-
using Microsoft.EntityFrameworkCore; `
139-
using Microsoft.Extensions.DependencyInjection; `
140-
`
141-
var connectionString = args.FirstOrDefault(a => a.StartsWith("--connection="))?.Substring("--connection=".Length) `
142-
?? throw new ArgumentException("Usage: efmigrate --connection=<connection-string>"); `
143-
`
144-
Console.WriteLine("Running EF Core migrations for GOV.UK Pay integration..."); `
145-
`
146-
// Build DbContext with the provided connection string `
147-
var optionsBuilder = new DbContextOptionsBuilder<LocalGovIms.Integration.GovUKPay.Infrastructure.GovUkPayDbContext>(); `
148-
optionsBuilder.UseSqlServer(connectionString); `
149-
`
150-
using var context = new LocalGovIms.Integration.GovUKPay.Infrastructure.GovUkPayDbContext(optionsBuilder.Options); `
151-
context.Database.Migrate(); `
152-
`
153-
Console.WriteLine("EF Core migrations completed successfully."); `
154-
'@
89+
# Copy efmigrate source files (avoids PowerShell here-string issues in Docker)
90+
COPY efmigrate/ C:\efmigrate\
15591

15692
RUN dotnet publish efmigrate.csproj -c Release -o C:\efmigrate-out
15793

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
using Microsoft.EntityFrameworkCore;
2+
3+
var connectionString = args.FirstOrDefault(a => a.StartsWith("--connection="))?.Substring("--connection=".Length)
4+
?? throw new ArgumentException("Usage: efmigrate --connection=<connection-string>");
5+
6+
Console.WriteLine("Running EF Core migrations for GOV.UK Pay integration...");
7+
8+
var optionsBuilder = new DbContextOptionsBuilder<LocalGovIms.Integration.GovUKPay.Infrastructure.GovUkPayDbContext>();
9+
optionsBuilder.UseSqlServer(connectionString);
10+
11+
using var context = new LocalGovIms.Integration.GovUKPay.Infrastructure.GovUkPayDbContext(optionsBuilder.Options);
12+
context.Database.Migrate();
13+
14+
Console.WriteLine("EF Core migrations completed successfully.");
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
<PropertyGroup>
3+
<OutputType>Exe</OutputType>
4+
<TargetFramework>net6.0</TargetFramework>
5+
<ImplicitUsings>enable</ImplicitUsings>
6+
</PropertyGroup>
7+
<ItemGroup>
8+
<ProjectReference Include="..\src\Infrastructure\Infrastructure.csproj" />
9+
</ItemGroup>
10+
</Project>
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
2+
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" />
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
6+
<OutputPath>bin\</OutputPath>
7+
<AssemblyName>hash-password</AssemblyName>
8+
</PropertyGroup>
9+
<ItemGroup>
10+
<Reference Include="Microsoft.AspNet.Identity.Core">
11+
<HintPath>packages\Microsoft.AspNet.Identity.Core.2.2.4\lib\net45\Microsoft.AspNet.Identity.Core.dll</HintPath>
12+
</Reference>
13+
<Reference Include="System" />
14+
</ItemGroup>
15+
<ItemGroup>
16+
<Compile Include="Program.cs" />
17+
</ItemGroup>
18+
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
19+
</Project>
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
using System;
2+
using Microsoft.AspNet.Identity;
3+
class Program {
4+
static void Main() {
5+
var password = Console.ReadLine();
6+
var hasher = new PasswordHasher();
7+
Console.Write(hasher.HashPassword(password));
8+
}
9+
}

0 commit comments

Comments
 (0)