-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBuildWithVersioning.ps1
62 lines (53 loc) · 2.18 KB
/
BuildWithVersioning.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
param (
[string]$target = "local"
)
#Assumes you have the project buildversionsapi running on your buildversionsapi.local on port 8080
#
$hostname=""
$url = "http://buildversionsapi.${target}"
$registryHost = "registry.${target}:5000"
if($target -eq "local") {
$url = $url + ":8080"
}
$curl = "curl.exe"
$configuration = "production"
$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"
"Not responding to request ${url}/Ping"
return
}
foreach($name in @(
"BuildVersions",
"BuildVersionsApi"
))
{
$lowerName = $name.ToLower()
$branch = git rev-parse --abbrev-ref HEAD
$commit = git log -1 --pretty=format:"%H"
$description = "${branch}: ${commit}"
$json = "{""ProjectName"":""${name}"",""VersionElement"":""Revision""}"
"Sending json: " + $json
"To: " + "${url}/api/BuildVersion/Increment/v1"
$buildVersion = $null
$buildVersion = &${curl} -s -X 'PUT' "${url}/api/BuildVersion/Increment/v1" -H 'accept: application/json' -H 'Content-Type: application/json' -d "$json" | ConvertFrom-Json
$buildVersion
$semanticVersion = $buildVersion.semanticVersion
$version = $buildVersion.version
if([string]::IsNullOrEmpty($semanticVersion) -or [string]::IsNullOrEmpty($description))
{
"Could not connect to git repo or buildversionsapi"
"Please check that you are in the correct folder and that"
"BuildVersionsApi is working correctly in your Kubernetes"
return
}
"Current build: ${registryHost}/${lowerName}:${semanticVersion}"
"Version: ${semanticVersion}"
"Description: ${description}"
"Configuration: ${configuration}"
#docker build --progress=plain --no-cache -f ./${name}/Dockerfile --force-rm -t ${env:REGISTRYHOST}/${lowerName}:${semanticVersion} --build-arg Version="${version}" --build-arg Configuration="${configuration}" --build-arg Description="${description}" .
docker build -f ./${name}/Dockerfile --force-rm -t ${registryHost}/${lowerName}:${semanticVersion} --build-arg Version="${version}" --build-arg Configuration="${configuration}" --build-arg Description="${description}" .
docker push ${registryHost}/${lowerName}:${semanticVersion}
}