-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathbuild.ps1
More file actions
111 lines (92 loc) · 3.8 KB
/
Copy pathbuild.ps1
File metadata and controls
111 lines (92 loc) · 3.8 KB
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
105
106
107
108
109
110
111
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
# SPDX-License-Identifier: Apache-2.0
param (
[string]$Major = "1",
[string]$Minor = "3",
[string]$Patch = "0",
[string]$Out = "out",
# Target OS/architecture for the build. Defaults to windows/amd64.
# Set these to cross-compile from Windows for other targets, e.g.
# powershell -file .\build.ps1 -GoOS linux -GoArch arm64
# to build a Linux arm64 wrapper to deploy to a Linux fleet.
[string]$GoOS = "windows",
[ValidateSet("amd64", "arm64")]
[string]$GoArch = "amd64"
)
$ComputeTypes = @("managed-ec2", "anywhere", "managed-containers")
$AppName = "amazon-gamelift-servers-game-server-wrapper"
$AppPackage = "github.com/amazon-gamelift/$AppName"
$FileExt = if ($GoOS -eq "windows") { ".exe" } else { "" }
$OutFolder = "$Out\$GoOS\$GoArch\"
$BuildDir = "src"
$ServerSdkUrl = "https://github.com/amazon-gamelift/amazon-gamelift-servers-go-server-sdk/releases/download/v5.6.0/GameLift-Go-ServerSDK-5.6.0.zip"
$ServerSdkFileName = "gamelift-server-sdk.zip"
$ServerSdkExtractDir = "src/ext/gamelift-servers-server-sdk"
function Clean {
Write-Host "Cleaning output directory..."
Remove-Item -Recurse -Force $Out -ErrorAction SilentlyContinue
Remove-Item -Recurse -Force $ServerSdkExtractDir -ErrorAction SilentlyContinue
Remove-Item -Force $ServerSdkFileName -ErrorAction SilentlyContinue
}
function DownloadGameLiftSDK {
Write-Host "Downloading server SDK for Amazon GameLift Servers..."
New-Item -ItemType Directory -Path $ServerSdkExtractDir -Force | Out-Null
if (Test-Path $ServerSdkFileName) {
Remove-Item -Force $ServerSdkFileName
}
if (Test-Path $ServerSdkExtractDir) {
Remove-Item -Recurse -Force $ServerSdkExtractDir
}
Invoke-WebRequest -Uri $ServerSdkUrl -OutFile $ServerSdkFileName
Expand-Archive -Path $ServerSdkFileName -DestinationPath $ServerSdkExtractDir -Force
}
function Build {
Clean
DownloadGameLiftSDK
Write-Host "Building $AppName for $GoOS/$GoArch..."
New-Item -ItemType Directory -Path $OutFolder -Force | Out-Null
$Env:CGO_ENABLED = "0"
$Env:GOOS = $GoOS
$Env:GOARCH = $GoArch
$BuildCmd = @(
"go build",
"-C $BuildDir",
"-trimpath",
"-v",
"-ldflags `"",
"-X '$AppPackage/internal.version=$Major.$Minor.$Patch'",
"`"",
"-o ..\$OutFolder\$AppName\$AppName$FileExt",
"."
) -join " "
Invoke-Expression $BuildCmd
foreach ($Type in $ComputeTypes) {
$ComputeTypeOutFolder = "$OutFolder\gamelift-servers-$Type\"
New-Item -ItemType Directory -Path $ComputeTypeOutFolder -Force | Out-Null
Copy-Item "$OutFolder\$AppName\$AppName$FileExt" "$ComputeTypeOutFolder\$AppName$FileExt" -Force
Copy-Item "src\template\template-$Type-config.yaml" "$ComputeTypeOutFolder\config.yaml" -Force
# The container Dockerfile is only needed for the managed-containers target.
if ($Type -eq "managed-containers") {
Copy-Item "src\template\Dockerfile" "$ComputeTypeOutFolder\Dockerfile" -Force
}
}
# Cleanup unnecessary Wrapper folder and ServerSDK file
Remove-Item -Recurse -Force "$OutFolder\$AppName" -ErrorAction SilentlyContinue
Remove-Item -Force $ServerSdkFileName
}
function Test {
Build
# Cross-compiled test binaries can't run on the build host, so only run
# tests when building for the host platform (windows/amd64).
if ($GoOS -eq "windows" -and $GoArch -eq "amd64") {
Write-Host "Running tests..."
$Env:GOOS = "windows"
$Env:GOARCH = "amd64"
Invoke-Expression "go test -C $BuildDir ./..."
}
else {
Write-Host "Skipping tests: cross-compiling for $GoOS/$GoArch (cannot run non-host test binaries)."
}
}
# Default action
Test