Jelajahi Sumber

add gicommit and release procedure

shayne_lo 2 bulan lalu
induk
melakukan
e2152bf5bd
5 mengubah file dengan 215 tambahan dan 3 penghapusan
  1. 1 1
      DEV_Build.ps1
  2. 1 0
      Dockerfile
  3. 2 2
      EVCB_OCPP.DBAPI/Controllers/HomeController.cs
  4. 110 0
      Prerelease_Build.ps1
  5. 101 0
      Release_Build.ps1

+ 1 - 1
DEV_Build.ps1

@@ -18,7 +18,7 @@ $registryname="evdevcontainerregistry"
 $fullregistryname="evdevcontainerregistry.azurecr.io"
 #第一次建立專案請先設定專案名稱
 $imagerepositoryname="dbapi"
-$dev_prefix = "dbapiEBUS_test_"
+$dev_prefix = "DockerEBUS_test_"
 
 $username = az account show --query user.name
 $username = $username.TrimStart("""").Split('@')[0]

+ 1 - 0
Dockerfile

@@ -30,5 +30,6 @@ WORKDIR /app
 COPY --from=publish /app/publish .
 
 COPY entrypoint.sh .
+COPY gitcommit /app/gitcommit
 RUN chmod +x /app/entrypoint.sh
 CMD ["/app/entrypoint.sh"]

+ 2 - 2
EVCB_OCPP.DBAPI/Controllers/HomeController.cs

@@ -8,9 +8,9 @@ namespace EVCB_OCPP.DBAPI.Controllers
         {
             string sshaString = "";
 
-            if (System.IO.File.Exists("ssha"))
+            if (System.IO.File.Exists("gitcommit"))
             {
-                sshaString = System.IO.File.ReadAllText("ssha");
+                sshaString = System.IO.File.ReadAllText("gitcommit");
             }
             return Ok($"Git commit:{sshaString}");
             //return View();

+ 110 - 0
Prerelease_Build.ps1

@@ -0,0 +1,110 @@
+# 設定 ASCII 藝術字的內容
+$asciiArt = @"
+  _____  _____  ______ _____  ______ _      ______           _____ ______ 
+ |  __ \|  __ \|  ____|  __ \|  ____| |    |  ____|   /\    / ____|  ____|
+ | |__) | |__) | |__  | |__) | |__  | |    | |__     /  \  | (___ | |__   
+ |  ___/|  _  /|  __| |  _  /|  __| | |    |  __|   / /\ \  \___ \|  __|  
+ | |    | | \ \| |____| | \ \| |____| |____| |____ / ____ \ ____) | |____ 
+ |_|    |_|  \_\______|_|  \_\______|______|______/_/    \_\_____/|______|
+"@
+
+# 顯示 ASCII 藝術字
+Write-Host $asciiArt
+
+#第一次建立專案請先設定ACR Name
+$registryname="evdevcontainerregistry"
+$fullregistryname="evdevcontainerregistry.azurecr.io"
+#第一次建立專案請先設定專案名稱
+$imagerepositoryname="dbapi"
+#target tag can be {projectname}_RC or RC on pre-release stage
+$default_dev_prefix = "DockerEBUS_test_"
+$target_tag="DockerEBUS_RC"
+
+#檢查是否有尚未commit的更新
+$status = git status --porcelain
+if (-not $status) {
+	Write-Output "All changes committed"
+} else {
+    Write-Output "There are uncommitted changes"
+	exit
+}
+
+#檢查remote是否有新commit未處理
+git fetch --tags -f
+$status = git status --porcelain -b
+if (($status -match "ahead") -or ($status -match "behind") -or ($status -match "gone") )
+{
+	Write-Output "git branch not synced"
+	exit
+}
+else {
+    Write-Output "git branch is synced"
+}
+
+#podman acr登入
+Write-Host "ACR Login....."
+$token = az acr login --name $registryname --expose-token --output tsv --query accessToken
+$user = "00000000-0000-0000-0000-000000000000"
+podman login $fullregistryname -u $user -p $token
+
+$source_tag = Read-Host "Please type the source tag that you want to do RC."
+#預設跟Dev_build一樣
+if (-not $source_tag) {
+	$username = az account show --query user.name
+	$username = $username.TrimStart("""").Split('@')[0]
+	$source_tag=$default_dev_prefix+$username
+}
+$sourcetag_response = Read-Host "Do you want to do the RC tag with $source_tag ?(Y/N)"
+while($sourcetag_response -eq "N")
+{
+	$source_tag = Read-Host "Please type the source tag that you want to do RC."
+	#預設跟Dev_build一樣
+	if (-not $source_tag) {
+		$source_tag=$default_dev_prefix+$username
+	}
+	$sourcetag_response = Read-Host "Do you want to do the RC tag with $source_tag ?(Y/N)"
+}
+
+
+$fulltag=$registryname+".azurecr.io/"+$imagerepositoryname+":"+$targettag
+$source_imagename = $imagerepositoryname+":"+$source_tag
+$target_imagename = $imagerepositoryname+":"+$target_tag
+$source_fulltag = $registryname+".azurecr.io/"+$imagerepositoryname+":"+$source_tag
+$target_fulltag = $registryname+".azurecr.io/"+$imagerepositoryname+":"+$target_tag
+
+$final_response = Read-Host "Final confirmation: Do you want to assign the RC tag name "$target_imagename" to the existing tag with "$source_imagename"?(Y/N)"
+if($final_response -eq "N")
+{
+	write-host "Please restart the process."
+}
+else
+{
+	#取得目前RC的message
+	$rc_message = git tag -l --format='%(contents)' $target_tag
+	if (!$rc_message)
+	{
+		$rc_message = ""
+	}
+	#暫存RC message
+	$filePath = Join-Path -Path (Get-Location) -ChildPath "rc_message.txt"
+	[System.IO.File]::WriteAllLines($filePath, $rc_message)
+	#刪除遠端git的RC tag
+	git push --delete origin $target_tag
+	#刪除本地端git的RC tag
+	git tag --delete $target_tag
+	#標註目前commit為RC
+	git tag -a $target_tag -F "rc_message.txt" --edit
+	#更新遠端tag
+	git push --follow-tags
+	#刪除暫存檔
+	Remove-Item "rc_message.txt"
+	
+	#解除image鎖定
+	az acr repository update --name $registryname --image $target_imagename --delete-enabled true --write-enabled true
+	podman pull $source_fulltag
+	podman image tag $source_fulltag $target_fulltag
+	podman push $target_fulltag
+
+	#鎖定image
+	az acr repository update --name $registryname --image $target_imagename --delete-enabled false --write-enabled false
+}

+ 101 - 0
Release_Build.ps1

@@ -0,0 +1,101 @@
+
+# 設定 ASCII 藝術字的內容
+$asciiArt = @"
+
+  _____  ______ _      ______           _____ ______ 
+ |  __ \|  ____| |    |  ____|   /\    / ____|  ____|
+ | |__) | |__  | |    | |__     /  \  | (___ | |__   
+ |  _  /|  __| | |    |  __|   / /\ \  \___ \|  __|  
+ | | \ \| |____| |____| |____ / ____ \ ____) | |____ 
+ |_|  \_\______|______|______/_/    \_\_____/|______|
+                                                     
+                                                     
+                                                                     
+"@
+
+# 顯示 ASCII 藝術字
+Write-Host $asciiArt
+#第一次建立專案請先設定ACR Name
+$registryname="evdevcontainerregistry"
+$fullregistryname="evdevcontainerregistry.azurecr.io"
+#第一次建立專案請先設定專案名稱
+$imagerepositoryname="dbapi"
+#來源TAG
+$source_tag="DockerEBUS_RC"
+$targetTagPrefix="DockerEBUS_v"
+
+#檢查remote是否有新commit未處理
+git fetch --tags -f
+$status = git status --porcelain -b
+if (($status -match "ahead") -or ($status -match "behind") -or ($status -match "gone") )
+{
+	Write-Output "git branch not synced"
+	exit
+}
+else {
+    Write-Output "git branch is synced"
+}
+
+#podman acr登入
+Write-Host "ACR Login....."
+$token = az acr login --name $registryname --expose-token --output tsv --query accessToken
+$user = "00000000-0000-0000-0000-000000000000"
+podman login $fullregistryname -u $user -p $token
+
+$sourcetag_response = Read-Host "Do you want to do release tag with $source_tag ?(Y/N)"
+while($sourcetag_response -ne "Y")
+{
+	$source_tag = Read-Host "Please type the source tag that you want to do newtag."
+	$sourcetag_response = Read-Host "Do you want to do release tag with $source_tag ?(Y/N)"
+}
+	
+$target_tag = Read-Host "Please type the release tag version (make sure that the same as tagname from azure devops)."
+$target_tag = $targetTagPrefix + $target_tag
+$targettag_response = Read-Host "Please confirm the release tag $target_tag (Y/N)."
+
+while($targettag_response -ne "Y")
+{
+	$target_tag = Read-Host "Please type the release tag version (make sure that the same as tagname from azure devops)."
+	$target_tag = $targetTagPrefix + $target_tag
+	$targettag_response = Read-Host "Please confirm the release tag $target_tag (Y/N)."
+}
+
+
+
+$fulltag=$registryname+".azurecr.io/"+$imagerepositoryname+":"+$targettag
+$source_imagename = $imagerepositoryname+":"+$source_tag
+$target_imagename = $imagerepositoryname+":"+$target_tag
+$source_fulltag = $registryname+".azurecr.io/"+$imagerepositoryname+":"+$source_tag
+$target_fulltag = $registryname+".azurecr.io/"+$imagerepositoryname+":"+$target_tag
+
+$final_response = Read-Host "Final confirmation: Do you want to assign the new tag name "$target_imagename" to the existing tag with "$source_imagename"?(Y/N)"
+if($final_response -ne "Y")
+{
+	write-host "Please restart the process."
+}
+else
+{
+	#取得目前RC的message
+	$rc_message = git tag -l --format='%(contents)' $source_tag
+	if ($status -match "unknown revision or path not in the working tree")
+	{
+		Write-Host "source tag missing"
+		exit
+	}
+	#暫存RC message
+	$filePath = Join-Path -Path (Get-Location) -ChildPath "rc_message.txt"
+	[System.IO.File]::WriteAllLines($filePath, $rc_message)
+	#標註RC為新的tag
+	git tag -a $target_tag -F "rc_message.txt" $source_tag
+	#更新遠端tag
+	git push --follow-tags
+	#刪除暫存檔
+	Remove-Item "rc_message.txt"
+	
+	podman pull $source_fulltag
+	podman image tag $source_fulltag $target_fulltag
+	podman push $target_fulltag
+
+	#鎖定image
+	az acr repository update --name $registryname --image $target_imagename --delete-enabled false --write-enabled false
+}