-
Notifications
You must be signed in to change notification settings - Fork 21
/
Build.Docker.ps1
89 lines (69 loc) · 2.46 KB
/
Build.Docker.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
Push-Location $PSScriptRoot
. ./Build.Common.ps1
$IsCIBuild = $null -ne $env:APPVEYOR_BUILD_NUMBER
$IsPublishedBuild = ($env:APPVEYOR_REPO_BRANCH -eq "main" -or $env:APPVEYOR_REPO_BRANCH -eq "dev") -and $null -eq $env:APPVEYOR_PULL_REQUEST_HEAD_REPO_BRANCH
$version = Get-SemVer(@{ $true = $env:APPVEYOR_BUILD_VERSION; $false = "99.99.99" }[$env:APPVEYOR_BUILD_VERSION -ne $NULL])
$framework = "net8.0"
$image = "datalust/seqcli"
$archs = @(
@{ rid = "x64"; platform = "linux/amd64" },
@{ rid = "arm64"; platform = "linux/arm64/v8" }
)
$endToEndVersion = "preview"
function Execute-Tests
{
& dotnet test ./test/SeqCli.Tests/SeqCli.Tests.csproj -c Release -f $framework /p:Configuration=Release /p:VersionPrefix=$version
if ($LASTEXITCODE -ne 0) { exit 1 }
cd ./test/SeqCli.EndToEnd/
docker pull "datalust/seq:$endToEndVersion"
docker tag "datalust/seq:$endToEndVersion" datalust/seq:latest
& dotnet run -f $framework -- --docker-server
if ($LASTEXITCODE -ne 0)
{
cd ../..
exit 1
}
cd ../..
}
function Build-DockerImage($arch)
{
$rid = "linux-$($arch.rid)"
& dotnet publish src/SeqCli/SeqCli.csproj -c Release -f $framework -r $rid --self-contained /p:VersionPrefix=$version /p:PublishSingleFile=true
if($LASTEXITCODE -ne 0) { exit 2 }
& docker buildx build --platform "$($arch.platform)" -f dockerfiles/seqcli/$rid.Dockerfile -t "$image-ci:$version-$($arch.rid)" .
if($LASTEXITCODE -ne 0) { exit 3 }
}
function Publish-DockerImage($arch)
{
$ErrorActionPreference = "SilentlyContinue"
if ($IsCIBuild) {
Write-Output "$env:DOCKER_TOKEN" | docker login -u $env:DOCKER_USER --password-stdin
if ($LASTEXITCODE) { exit 3 }
}
& docker push "$image-ci:$version-$($arch.rid)"
if($LASTEXITCODE -ne 0) { exit 3 }
$ErrorActionPreference = "Stop"
}
function Publish-DockerManifest($archs)
{
$images = ""
foreach ($arch in $archs) {
$images += "$image-ci:$version-$($arch.rid) "
}
# We use `invoke-expression` here so each tag is treated as a separate arg
invoke-expression "docker manifest create $image-ci:$version $images"
if ($LASTEXITCODE) { exit 4 }
docker manifest push $image-ci:$version
if ($LASTEXITCODE) { exit 4 }
}
Execute-Tests
foreach ($arch in $archs) {
Build-DockerImage($arch)
if ($IsPublishedBuild) {
Publish-DockerImage($arch)
}
}
if ($IsPublishedBuild) {
Publish-DockerManifest($archs)
}
Pop-Location