-
Notifications
You must be signed in to change notification settings - Fork 47
/
Create-DockerfileSolutionRestore.ps1
32 lines (23 loc) · 1.38 KB
/
Create-DockerfileSolutionRestore.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
param (
[string]$solution = "serilog-sinks-splunk.sln"
)
$outfile = "DockerfileSolutionRestore.txt"
# This script creates the $outfile file, with Dockerfile commands to restore all the packages for the solution,
# so you can insert them (by hand) into Dockerfiles right before the "COPY . ." line
# to increase build speed by optimizing the use of docker build images cache.
# This script is only needed when adding or removing projects from the solution.
Write-Output "" > $outfile
Add-Content -Path $outfile "# Create this ""restore-solution"" section by running ./Create-DockerfileSolutionRestore.ps1, to optimize build cache reuse"
Select-String -Path $solution -Pattern ', "(.*?\.csproj)"' | ForEach-Object { $_.Matches.Groups[1].Value.Replace("\", "/") } | Sort-Object | ForEach-Object {"COPY [""$_"", """ + $_.Substring(0, $_.LastIndexOf("/") + 1) + """]"} | Out-File -FilePath $outfile -Append
Add-Content -Path $outfile "COPY [""docker-compose.dcproj"", ""./""]"
Add-Content -Path $outfile "COPY [""$solution"", ""./""]"
Add-Content -Path $outfile "RUN dotnet restore ""$solution"""
Add-Content -Path $outfile ""
Add-Content -Path $outfile "# Docker Compose Paths"
Get-ChildItem -Path "./" -Recurse -Filter "Dockerfile" |
Resolve-Path -Relative |
ForEach-Object { $_.Replace("\", "/") }
Sort-Object |
ForEach-Object {" ""$_"""} |
Out-File -FilePath $outfile -Append
Get-Content $outfile