-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmake.ps1
296 lines (249 loc) · 9.39 KB
/
make.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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
<#
.SYNOPSIS
Builds kubeadm components from upstream kubernetes, including the controlplane.
.DESCRIPTION
Run the script to build kubeadm images and binaries for windows from upstream kubernetes, including the controlplane.
.NOTES
Environment variables:
- CNI_PLUGINS_VERSION (default: 1.1.1)
- FLANNEL_VERSION (default: 0.21.1)
- CONTAINERD_VERSION (default: 1.6.16)
- ETCD_VERSION (default: 3.5.3)
- KUBE_VERSION (default: 1.26.1)
- COREDNS_VERSION (default: 1.10.1)
- BUILDKIT_VERSION (default: 0.11.2)
- NERDCTL_VERSION (default: 1.2.0)
- GOLANG_VERSION (default: 1.19.5)
- HELM_VERSION (default: 3.11.1)
- GIT_VERSION (default: 2.39.1)
.EXAMPLE
make.ps1 -Tag v0.0.1-alpha
#>
param (
# [CmdletBinding]
[parameter()] [string]$Tag
)
$ErrorActionPreference = 'Stop'
# Set-StrictMode -Version Latest
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls -bor [Net.SecurityProtocolType]::Tls11 -bor [Net.SecurityProtocolType]::Tls12
Import-Module -WarningAction Ignore -Name "$PSScriptRoot\utils.psm1"
# --- bail if we are not administrator ---
$adminRole = [Security.Principal.WindowsBuiltInRole]::Administrator
$currentRole = [Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()
if (-NOT $currentRole.IsInRole($adminRole)) {
Write-FatalLog "You need to be administrator to perform this build"
}
#######################################
### COMMON
#######################################
$Registry = "docker.io"
$Org = "embryonik"
$GithubOrg = "embryonik-io"
$InputDir = ('C:/{0}/bin' -f $Org)
#######################################
### COMPONENTS
#######################################
$Images = @("kubelet", "kube-apiserver", "kube-scheduler", "kube-controller-manager", "kube-proxy", "etcd")
$Binaries = @("kubelet", "kube-apiserver", "kube-scheduler", "kube-controller-manager", "kube-proxy", "kubeadm", "etcd")
$Components = @("kubelet", "kube-apiserver", "kube-scheduler", "kube-controller-manager", "kube-proxy", "etcd", "etcdctl", "etcdutl")
#######################################
### VERSIONS
#######################################
$CNI_PLUGINS_VERSION="1.1.1"
$FLANNEL_VERSION="0.21.1"
$CONTAINERD_VERSION="1.6.16"
$ETCD_VERSION="3.5.7"
$KUBE_VERSION="1.24.10"
$COREDNS_VERSION="1.10.1"
$BUILDKIT_VERSION="0.11.2"
$NERDCTL_VERSION="1.2.0"
$GOLANG_VERSION="1.19.5"
$HELM_VERSION="3.11.0"
$GIT_VERSION="2.39.1"
if (-not $Tag) {
$env:BUILD_TAG="dev"
}
$env:BUILD_TAG=$Tag
if (-not $env:CNI_PLUGINS_VERSION) {
$env:CNI_PLUGINS_VERSION=$CNI_PLUGINS_VERSION
}
if (-not $env:FLANNEL_VERSION) {
$env:FLANNEL_VERSION=$FLANNEL_VERSION
}
if (-not $env:CONTAINERD_VERSION) {
$env:CONTAINERD_VERSION=$CONTAINERD_VERSION
}
if (-not $env:ETCD_VERSION) {
$env:ETCD_VERSION=$ETCD_VERSION
}
if (-not $env:KUBE_VERSION) {
$env:KUBE_VERSION=$KUBE_VERSION
}
if (-not $env:COREDNS_VERSION) {
$env:COREDNS_VERSION=$COREDNS_VERSION
}
if (-not $env:BUILDKIT_VERSION) {
$env:BUILDKIT_VERSION=$BUILDKIT_VERSION
}
if (-not $env:NERDCTL_VERSION) {
$env:NERDCTL_VERSION=$NERDCTL_VERSION
}
if (-not $env:GOLANG_VERSION) {
$env:GOLANG_VERSION=$GOLANG_VERSION
}
if (-not $env:HELM_VERSION) {
$env:HELM_VERSION=$HELM_VERSION
}
if (-not $env:GIT_VERSION) {
$env:GIT_VERSION=$GIT_VERSION
}
$SRC_PATH = (Resolve-Path "$PSScriptRoot").Path
Push-Location $SRC_PATH
# $SRC_DIR=$(Get-Location).Path
Invoke-Expression -Command "$PSScriptRoot\version.ps1"
function Invoke-BinaryBuilder {
param (
# [CmdletBinding]
[parameter()] [array]$Binaries,
[parameter()] [array]$OutputDir,
[parameter()] [string]$Version,
[parameter()] [string]$Org
)
# Invoke-Expression -Command "$PSScriptRoot\version.ps1"
Write-Host "List of binaries to build ($Binaries)"
Write-Host "App Version: $env:TAG"
# foreach ($BINARY in $Binaries) {
try {
Write-Host -ForegroundColor Yellow "Starting binary build of $BINARY $Version`n"
# -Org $Org
Push-Location -Path $SRC_PATH
.\build.ps1 -Version $Version -Binary $BINARY -OutputDir $InputDir -Commit $env:COMMIT
} catch {
Write-Host -NoNewline -ForegroundColor Red "[Error] while building binary: ${BINARY}: "
Write-Host -ForegroundColor Red "$_`n"
Pop-Location
exit 1
# }
Write-Host -ForegroundColor Green "Successfully built binary: $BINARY $Version`n"
}
}
# TODO add calico support
function Export-Binaries {
param (
[parameter()] [array]$Components,
[parameter()] [string]$OutDir,
[parameter()] [ValidateSet("flannel")][string]$Cni = "flannel"
)
Invoke-Expression -Command "$PSScriptRoot\version.ps1"
Write-Host "CNI: $Cni"
Write-Host "App Version: $env:TAG"
if ($Components.Count -eq 0) {
Write-Host "Using Default Components List"
$Components = @("kubelet", "kube-apiserver", "kube-scheduler", "kube-controller-manager", "kube-proxy", "etcd", "etcdctl", "etcdutl", "coredns", "cni")
}
Write-Host "Components: $Components"
$null = New-Item -Type Directory -Path $OutDir -ErrorAction Ignore
# package flannel
if ($Cni.Equals("flannel")) {
curl.exe -LO https://github.com/flannel-io/flannel/releases/download/v${env:FLANNEL_VERSION}/flanneld.exe
Copy-Item flanneld.exe $OutDir\
Write-Host -ForegroundColor Green "staged flanneld binary"
$Components += "flanneld"
}
# TODO handle calico
if ($Cni.Equals("calico")) {
Write-Host "calico is not yet supported"
exit 1
}
# TODO add sanitizer for $Cni input and append to $ASSETS
Write-Host -ForegroundColor Yellow "checking for build artifacts [$Components] in $OutDir"
foreach ($item in $Components) {
if (-not ("$OutputDir\$item.exe")) {
Write-Error "required build artifact is missing: $item.exe"
throw
}
# if ($item.Contains('\')) {
# Write-Host "binary is " ($item -replace "^.*?\\")
# }
}
Write-Host -ForegroundColor Green "all required build artifacts are present"
Write-Host -ForegroundColor Green "artifacts have been successfully staged in: $OutDir"
}
function Invoke-ImageBuilder {
param (
[parameter()] [array]$Images,
[parameter()] [string]$InputDir,
[parameter()] [string]$Version,
[parameter()] [string]$Registry,
[parameter()] [string]$Org
)
Invoke-Expression -Command "$PSScriptRoot\version.ps1"
Write-Host "Images: $Images"
Write-Host "Version: $env:TAG"
foreach ($IMAGE in $Images) {
try {
if ($IMAGE -eq "etcd") {
$etcd="etcd."
}
$IMAGE = ('{0}/{1}:{2}-windows-{3}' -f $DockerOrg, $IMAGE, $env:TAG, $env:SERVERCORE_VERSION)
Write-Host -ForegroundColor Yellow "Starting nerdctl build of ${IMAGE}`n"
nerdctl build `
--build-arg SERVERCORE_VERSION=$env:SERVERCORE_VERSION `
--build-arg VERSION=$Version `
--build-arg MAINTAINERS=$env:MAINTAINERS `
--build-arg ORG=$DockerOrg `
--build-arg IMAGE=$IMAGE `
--build-arg REGISTRY=$Registry `
-t $IMAGE `
-f ('{0}Dockerfile' -f $etcd) .
} catch {
Write-Host -NoNewline -ForegroundColor Red "[Error] while building image: ${IMAGE}: "
Write-Host -ForegroundColor Red "$_`n"
exit 1
}
Write-Host -ForegroundColor Green "Successfully built ${IMAGE}`n"
}
}
function Publish-Images {
# TODO Implement me
}
if ($args[0] -eq "build" -or $args.Count -eq 0) {
Write-Host "building all image and binary artifacts"
Invoke-BinaryBuilder -Org $Org -OutputDir $InputDir -Version $Tag -Binaries $Binaries
# Export-Binaries -Components $Components -OutDir $InputDir
# Invoke-ImageBuilder -Images $Images -InputDir $InputDir -Registry $Registry -Org $Org -Version $Tag
}
if ($args[0] -eq "binaries") {
Invoke-BinaryBuilder -Org $Org -OutputDir $InputDir -Version $Version -Binaries $Binaries
}
if ($args[0] -eq "package") {
# BinaryBuilder -Org $Org -OutputDir $InputDir -Version $Version -Binaries $Binaries
Export-Binaries -Components $Components -OutDir $InputDir
}
if ($args[0] -eq "publish") {
Write-Host "publish is not yet implemented"
exit 1
# Write-Host "Building all artifacts"
# Invoke-BinaryBuilder -Org $Org -OutputDir $InputDir -Version $Version -Binaries $Binaries
# Export-Binaries -Components $Components -OutDir $InputDir
# Invoke-ImageBuilder -Images $Images -InputDir $InputDir -Registry $Registry -Org $Org -Version $Version
# Write-Host "Preparing to publish images"
# Publish-Images -Components $Components
# exit
}
if ($args[0] -eq "clean") {
$confirm = Read-Host -Prompt "Are you sure you want to prune Docker images and volumes?: y/n"
if ($confirm -eq "Y" -or $confirm -eq "y") {
nerdctl image prune --force
nerdctl volume prune --force
Write-Host -ForegroundColor Blue "Successfully pruned Docker images and volumes"
exit
} else {
Write-Host -ForegroundColor Red "Will not prune Docker images and volumes, exiting now."
exit 1
}
}
# if ($Components.Contains($($args[0]))) {
# Invoke-BinaryBuilder -Org $Org -OutputDir $InputDir -Version $Version -Binaries $args
# exit
# }