-
Notifications
You must be signed in to change notification settings - Fork 3
/
prepare_dockerfiles.ps1
42 lines (35 loc) · 1.5 KB
/
prepare_dockerfiles.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
33
34
35
36
37
38
39
40
41
42
# This file is used to copy all .csproj files present in solution during dockerfile build in order to be able to dotnet restore them
# so Docker is able to cache nuget package download process.
# If you add/remove project from solution you need to run this file in order to include changes in dockerfiles.
function Prepare-Dockerfile($dockerfile)
{
Write-Host $project
Write-Host $dockerfile
$projects = Get-ChildItem ./**/*.csproj
$output = "";
$fetching_projects = $false;
$outdockerfile = "./${dockerfile}"
Write-Host $outdockerfile
foreach($line in Get-Content -Encoding UTF8 $outdockerfile) {
if($line -match "#PUT_PROJECTS_BELOW_THIS_LINE"){
$output += "#PUT_PROJECTS_BELOW_THIS_LINE`n"
$fetching_projects = $true;
foreach($proj in $projects)
{
$output += "COPY "
$output += ($proj.FullName | Resolve-Path -Relative).Replace("\", "/")
$output += " "
$output += ($proj.FullName | Resolve-Path -Relative).Replace("\", "/")
$output += "`n"
}
} elseif($line -match "#END_PUT_PROJECTS_BELOW_THIS_LINE") {
$output += "#END_PUT_PROJECTS_BELOW_THIS_LINE`n"
$fetching_projects = $false
} elseif($fetching_projects -match $false) {
$output += $line;
$output += "`n";
}
}
$output | Out-File -Encoding UTF8 $outdockerfile
}
Prepare-Dockerfile "Dockerfile"