-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDeployWithVersioning.ps1
83 lines (66 loc) · 2.13 KB
/
DeployWithVersioning.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
param (
[string]$target = "local"
)
#Assumes you have the project buildversionsapi running on your buildversionsapi.local on port 8080
#
$namespace = "buildversions"
$hostname=""
$url = "http://buildversionsapi.${target}"
$registryHost = "registry:5000"
if($target -eq "local")
{
$url = $url + ":8080"
$kubeconfig = $env:KUBECONFIG
}
else
{
$kubeconfig = $env:KUBECONFIGX
}
$curl = "curl.exe"
$configuration = "production"
$deploy = "Deploy"
$kubeseal = "C:/Apps/kubeseal/kubeseal"
$alive = &${curl} -s "${url}/api/Ping/v1" -H "accept: text/plain"
if($alive -ne """pong""")
{
"You need to do an initial deploy of BuildVersionsApi"
"Please run InitBuildVersion.ps1"
return
}
kubectl apply -f ./deploy/${target}/namespace.yaml --kubeconfig $kubeconfig
foreach($name in @(
"buildversions",
"buildversionsapi"
))
{
$buildVersion = $null
$buildVersion = &${curl} -s "${url}/api/BuildVersion/ReadByName/${name}/v1" | ConvertFrom-Json
$semanticVersion = $buildVersion.semanticVersion
if([string]::IsNullOrEmpty($semanticVersion))
{
"Could not connect to buildversionsapi"
"Please check that BuildVersionsApi is working correctly in your Kubernetes"
return
}
"Current deploy: ${registryHost}/${name}:${semanticVersion}"
cd ./${deploy}/${target}/${name}
kustomize edit set image "${registryHost}/${name}:${semanticVersion}"
if(Test-Path -Path ./secrets/*)
{
"Creating secrets"
kubectl create secret generic ${name}-secret --output json --dry-run=client --from-file=./secrets --kubeconfig $kubeconfig|
&${kubeseal} -n "${namespace}" --controller-namespace kube-system --format yaml --kubeconfig $kubeconfig > "secret.yaml"
}
cd ../../..
kubectl apply -k ./${deploy}/${target}/${name} --kubeconfig $kubeconfig
#Restore secret.yaml and kustomization.yaml since this script alters them temporary
#if([string]::IsNullOrEmpty($env:AGENT_NAME) -and [string]::IsNullOrEmpty($hostname))
#if([string]::IsNullOrEmpty($env:AGENT_NAME))
#{
#}
git checkout ./${deploy}/${target}/${name}/kustomization.yaml
if(Test-Path -Path ./${deploy}/${target}/${name}/secret.yaml)
{
git checkout ./${deploy}/${target}/${name}/secret.yaml
}
}