This repository has been archived by the owner on Jun 18, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 57
/
CreateDockerPackage.ps1
85 lines (69 loc) · 3.25 KB
/
CreateDockerPackage.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
param (
[Parameter(Mandatory=$true, ParameterSetName = "Exe")]
[Parameter(Mandatory=$true, ParameterSetName = "Dll")]
[string] $CodePackageDirectoryPath,
[Parameter(Mandatory=$true, ParameterSetName = "Exe")]
[Parameter(Mandatory=$true, ParameterSetName = "Dll")]
[string] $DockerPackageOutputDirectoryPath,
[Parameter(Mandatory=$false, ParameterSetName = "Exe")]
[string] $ApplicationExeName,
[Parameter(Mandatory=$false, ParameterSetName = "Dll")]
[string] $DotnetCoreDllName
)
if(!(Test-Path -Path $CodePackageDirectoryPath))
{
Write-Error "CodePackageDirectoryPath does not exist."
exit 1
}
if(!(Test-Path -Path $DockerPackageOutputDirectoryPath))
{
Write-Host $DockerPackageOutputDirectoryPath "does not exist. Creating directory.."
New-Item -ItemType directory $DockerPackageOutputDirectoryPath | Out-Null
Write-Host "Created " $DockerPackageOutputDirectoryPath
}
$DockerPublishPath = Join-Path $DockerPackageOutputDirectoryPath -ChildPath "publish"
if(!(Test-Path -Path $DockerPublishPath))
{
New-Item -ItemType directory $DockerPublishPath | Out-Null
Write-Host "Created " $DockerPublishPath
}
Write-Host "Copying all files from " $CodePackageDirectoryPath " to " $DockerPublishPath
$SourceCopyPath = Join-Path $CodePackageDirectoryPath -ChildPath "*"
Copy-Item -Path $SourceCopyPath -Destination $DockerPublishPath -Recurse -Force
Write-Host "Files successfully copied."
Remove-Item $CodePackageDirectoryPath -Recurse -Force
Write-Host "Removed " $CodePackageDirectoryPath
$ServiceFabricDataInterfacesPath = Join-Path $DockerPublishPath -ChildPath "Microsoft.ServiceFabric.Data.Interfaces.dll"
if(Test-Path -Path $ServiceFabricDataInterfacesPath)
{
Remove-Item $ServiceFabricDataInterfacesPath -Force
Write-Host "Microsoft.ServiceFabric.Data.Interfaces.dll removed."
}
Get-ChildItem $DockerPublishPath | Where-Object{$_.Name -Match "System.Fabric.*.dll"} | Remove-Item -Force
Write-Host "Removed System.Fabric.*.dll"
$initScriptPath = Join-Path $DockerPublishPath -ChildPath "init.bat"
if ($ApplicationExeName)
{
$initScriptContents = [System.IO.Path]::GetFileNameWithoutExtension($ApplicationExeName) + ".exe"
}
elseif ($DotnetCoreDllName)
{
$initScriptContents = "dotnet " + [System.IO.Path]::GetFileNameWithoutExtension($DotnetCoreDllName) + ".dll"
}
else
{
$warning = "Modify init.bat inside " + $DockerPublishPath + " to include the name of your startup executable."
Write-Warning $warning
}
Write-Host "Creating init.bat for docker package"
New-Item -ItemType file $initScriptPath -Value $initScriptContents -Force | Out-Null
$dockerfilePath = Join-Path $DockerPackageOutputDirectoryPath -ChildPath "Dockerfile"
$dockerfileContents = 'FROM mcr.microsoft.com/windows/servercore:ltsc2019
ADD https://raw.githubusercontent.com/microsoft/service-fabric-scripts-and-templates/master/docker/service-fabric-reliableservices-windowsservercore/InstallPreReq.ps1 /
RUN powershell -File C:\InstallPreReq.ps1
RUN setx PATH "%PATH%;C:\sffabricbin;C:\sffabricruntimeload" /M
ADD publish/ /
CMD C:\init.bat'
Write-Host "Creating Dockerfile"
New-Item -ItemType file $dockerfilePath -Value $dockerfileContents -Force | Out-Null
Write-Host "Docker package successfully created at " $DockerPackageOutputDirectoryPath