-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.ps1
105 lines (78 loc) · 2.83 KB
/
build.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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#!/usr/bin/env pwsh
#
# Copyright (c) .NET Foundation and contributors. All rights reserved.
# Licensed under the MIT license. See LICENSE file in the project root for full license information.
# If this script fails, it is probably because docker drive sharing isn't enabled
$Time = [System.Diagnostics.Stopwatch]::StartNew()
function PrintElapsedTime {
Log $([string]::Format("Elapsed time: {0}.{1}", $Time.Elapsed.Seconds, $Time.Elapsed.Milliseconds))
}
function Log {
Param ([string] $s)
Write-Output "###### $s"
}
function Check {
Param ([string] $s)
if ($LASTEXITCODE -ne 0) {
Log "Failed: $s"
throw "Error case -- see failed step"
}
}
$DockerOS = docker version -f "{{ .Server.Os }}"
$ImageName = "dotnetcore/pitstoppro"
$TestImageName = "dotnetcore/pitstoppro:test"
$DistImageName = "dotnetcore/pitstoppro:dist"
$Dockerfile = "Dockerfile"
$Version = "0.0.3"
PrintElapsedTime
Log "Build application image"
docker build --no-cache --pull -t $ImageName -f $Dockerfile --build-arg Version=$Version .
PrintElapsedTime
Check "docker build (application)"
Log "Build test runner image"
docker build --pull --target testrunner -t $TestImageName -f $Dockerfile --build-arg Version=$Version .
PrintElapsedTime
Check "docker build (test runner)"
Log "Build distRunner image"
docker build --pull --target distrunner -t $DistImageName -f $Dockerfile --build-arg Version=$Version .
PrintElapsedTime
Check "docker build (pack runner)"
$TestResults = "TestResults"
$TestResultsDir = Join-Path $PSScriptRoot $TestResults
$TestResultsDirExists = (Test-Path -Path $TestResultsDir)
Log "Check if $TestResults directory exists: $TestResultsDirExists"
if (!$TestResultsDirExists) {
Log "Create $TestResults folder"
mkdir $TestResultsDir
gci . TestResults -ad
}
Log $TestResultsDir
$DistResults = "dist"
$DistDir = Join-Path $PSScriptRoot $DistResults
$DistDirExists = (Test-Path -Path $DistDir)
Log "Check if $DistDir directory exists: $DistDirExists"
if (!$DistDirExists) {
Log "Create $DistDir folder"
mkdir $DistDir
gci . DistDir -ad
}
Log $DistDir
Log "Run test container with test runner image"
if ($DockerOS -eq "linux") {
Log "Environment: Linux containers"
docker run --rm -v ${TestResultsDir}:/app/test/${TestResults} $TestImageName
docker run --rm -v ${DistDir}:/app/distMount $DistImageName
}
else {
Log "Environment: Windows containers"
docker run --rm -v ${TestResultsDir}:C:\app\test\${TestResults} $TestImageName
}
PrintElapsedTime
$testfiles = gci $TestResultsDir *.trx | Sort-Object -Property LastWriteTime | select -last 1
Log "Docker image built: $ImageName"
Log "Test log file:"
Write-Output $testfiles
$distfiles = gci $DistDir *.nupkg | Sort-Object -Property LastWriteTime | select -last 1
Log "Docker image built: $ImageName"
Log "Dist file:"
Write-Output $distfiles