forked from embryonik-io/kubeadm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.ps1
141 lines (120 loc) · 4.47 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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
#Requires -Version 5.0
param (
[CmdletBinding()]
[parameter()] [string]$Version,
[parameter()] [string]$Commit,
[parameter()] [string]$OutputDir,
# [parameter()] [string]$Org,
[parameter()] [string]$Binary
)
$ErrorActionPreference = 'Stop'
Import-Module -WarningAction Ignore -Name "$PSScriptRoot\utils.psm1"
Invoke-Expression -Command "$PSScriptRoot\version.ps1"
$null = New-Item -Type Directory -Path $OutputDir -ErrorAction Ignore
$env:GOARCH = $env:ARCH
$env:GOOS = 'windows'
$env:CGO_ENABLED = 0
$repo = 'k8s.io/kubernetes'
function Invoke-BinaryBuild {
param (
[parameter()] [string]$Invocation,
[parameter()] [string]$LinkFlags,
[parameter()] [string]$Name
)
if (-Not (Get-Command go)) {
Write-LogFatal "[build] failed to build ($Name.exe), go.exe was not found in PATH"
}
# $GO = $(Get-Command go)
if ($Name.Contains('kube')) {
Write-Host "Building $Name.exe [$env:KUBE_VERSION]"
$tmp = ('{0}\{1}' -f ${env:TEMP} , "github.com\kubernetes\kubernetes")
# $null = New-Item -Type Directory -Path $tmp -ErrorAction Ignore
Push-Location $tmp
}
if ($Name.Contains('etcd')) {
Write-Host "Building $Name.exe [$env:ETCD_VERSION]"
$tmp = ('{0}\{1}' -f ${env:TEMP} , "github.com\etcd-io\etcd")
# $null = New-Item -Type Directory -Path $tmp -ErrorAction Ignore
Push-Location $tmp
}
# if ($Name.Contains('dns')) {
# Write-Host "Building $Name.exe [$env:COREDNS_VERSION]"
# Push-Location coredns
# }
$ldFlags=' -extldflags "-static"'
GOPATH=$tmp go build -ldflags $linkFlags$ldFlags -o "$OutputDir\$Name.exe" $Invocation
# if (-not $?) {
if ($LASTEXITCODE -ne 0) {
Write-LogFatal "[build] go build failed for ($Name.exe)"
Pop-Location
}
Write-Host -ForegroundColor Green "($Name.exe) has been built successfully."
Pop-Location
}
function Invoke-EtcdBuild {
$repo = 'go.etcd.io/etcd'
$name = 'etcd'
$linkFlags = ('-s -w -X {0}/version.GitSHA={0}' -f $repo, $Commit)
Invoke-BinaryBuild -LinkFlags $linkFlags -Invocation "$repo" -Name $name
$linkFlags = ('-s -w -X {0}/etcdctl/version.GitSHA={0}' -f $repo, $Commit)
Invoke-BinaryBuild -LinkFlags $linkFlags -Invocation "$repo\etcdctl" -Name ('{0}ctl' -f $name)
$linkFlags = ('-s -w -X {0}/etcdutl/version.GitSHA={0}' -f $repo, $Commit)
Invoke-BinaryBuild -LinkFlags $linkFlags -Invocation "$repo\etcdutl" -Name ('{0}utl' -f $name)
}
function Invoke-KubectlBuild {
$name = 'kubectl'
Invoke-BinaryBuild -LinkFlags $linkFlags -Invocation "cmd/kubectl" -Name $name
}
function Invoke-KubeletBuild {
$name = 'kubelet'
Invoke-BinaryBuild -LinkFlags $linkFlags -Invocation "cmd/kubelet" -Name $name
}
function Invoke-KubeadmBuild {
$name = 'kubeadm'
Invoke-BinaryBuild -LinkFlags $linkFlags -Invocation "cmd/kubeadm" -Name $name
}
function Invoke-KubeProxyBuild {
$name = 'kube-proxy'
Invoke-BinaryBuild -LinkFlags $linkFlags -Invocation 'cmd/kube-proxy' -Name $name
}
function Invoke-KubeControllerManagerBuild {
$name = 'kube-controller-manager'
Invoke-BinaryBuild -LinkFlags $linkFlags -Invocation "cmd/kube-controller-manager" -Name $name
}
function Invoke-KubeApiserverBuild {
$name = 'kube-apiserver'
Invoke-BinaryBuild -LinkFlags $linkFlags -Invocation "cmd/kube-apiserver" -Name $name
}
function Invoke-KubeSchedulerBuild {
$name = 'kube-scheduler'
Invoke-BinaryBuild -LinkFlags $linkFlags -Invocation "cmd/kube-scheduler" -Name $name
}
function Invoke-CoreDNSBuild {
$repo = 'github.com/coredns/coredns'
$name = 'coredns'
$linkFlags = ('-s -w -X github.com/coredns/coredns/coremain.GitCommit={0}' -f $Commit)
Invoke-BinaryBuild -LinkFlags $linkFlags -Name $name
}
# $newName = $Binary.Replace('-','')
# ('Invoke-{0}Build' -f $newName)
# $invoke = $(Invoke-$Binary.Replace('-','')Build)
# $(Invoke-$Binary.Replace('-','')Build)
# Invoke-kubeproxyBuild
# Invoke-$newName
function Invoke-Builds {
Invoke-Expression -Command "$PSScriptRoot\prepare.ps1"
try {
Invoke-KubeSchedulerBuild
Invoke-KubeApiserverBuild
Invoke-KubeControllerManagerBuild
Invoke-KubeProxyBuild
Invoke-KubeadmBuild
Invoke-KubeletBuild
Invoke-KubectlBuild
Invoke-EtcdBuild
}
catch {
Pop-Location
}
}
Invoke-Builds