Browse Source

1. add new build scripts
2. display ssha on http

Robert 9 months ago
parent
commit
c254d0a45e
5 changed files with 293 additions and 7 deletions
  1. 66 0
      DEV_Build.ps1
  2. 1 0
      Dockerfile
  3. 15 7
      EVCB_OCPP.WSServer/Service/MapApiServce.cs
  4. 110 0
      Prerelease_Build.ps1
  5. 101 0
      Release_Build.ps1

+ 66 - 0
DEV_Build.ps1

@@ -0,0 +1,66 @@
+# 設定 ASCII 藝術字的內容
+$asciiArt = @"
+  _____  ________      ________ _      ____  _____  __  __ ______ _   _ _______ 
+ |  __ \|  ____\ \    / /  ____| |    / __ \|  __ \|  \/  |  ____| \ | |__   __|
+ | |  | | |__   \ \  / /| |__  | |   | |  | | |__) | \  / | |__  |  \| |  | |   
+ | |  | |  __|   \ \/ / |  __| | |   | |  | |  ___/| |\/| |  __| | . ` |  | |   
+ | |__| | |____   \  /  | |____| |___| |__| | |    | |  | | |____| |\  |  | |   
+ |_____/|______|   \/   |______|______\____/|_|    |_|  |_|______|_| \_|  |_|   
+                                                                                
+                                                                                
+"@
+
+# 顯示 ASCII 藝術字
+Write-Host $asciiArt
+
+#第一次建立專案請先設定ACR Name
+$registryname="evdevcontainerregistry"
+$fullregistryname="evdevcontainerregistry.azurecr.io"
+#第一次建立專案請先設定專案名稱
+$imagerepositoryname="server"
+$dev_prefix = "Docker_test_"
+
+$username = az account show --query user.name
+$username = $username.TrimStart("""").Split('@')[0]
+
+$tagname= $dev_prefix + $username
+
+$fulltag=$fullregistryname+"/"+$imagerepositoryname+":"+$tagname
+$imagename = $imagerepositoryname+":"+$tagname
+
+
+$response = read-host  "please confirm that what you are currently uploading is a test version[ $fulltag ]. (y/n)"
+
+
+if ($response -eq "y") {
+ write-host "upload processing....."
+
+
+ #解除image鎖定
+ az acr repository update --name $registryname --image $imagename --delete-enabled true --write-enabled true
+
+ $ssha = git rev-parse --short head
+
+ 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
+ 
+ #wite ssha to file
+ $ssha | Out-File ssha
+ 
+ podman build ./ -t  $fulltag --label [gitcommit=$ssha,author=$username]
+ podman push $fulltag
+ 
+ #remove ssha file
+ Remove-Item ssha
+
+ #鎖定image
+ az acr repository update --name $registryname --image $imagename --delete-enabled false --write-enabled false
+} else {
+ write-host "please modify the parameters with scripts."
+}
+
+
+
+

+ 1 - 0
Dockerfile

@@ -48,5 +48,6 @@ FROM base AS final
 WORKDIR /app
 COPY --from=publish /app/publish .
 COPY entrypoint.sh /app/entrypoint.sh
+COPY ssha /app/ssha
 RUN chmod +x /app/entrypoint.sh
 CMD ["/app/entrypoint.sh"]

+ 15 - 7
EVCB_OCPP.WSServer/Service/MapApiServce.cs

@@ -19,14 +19,22 @@ public static class MapApiServceExtention
 
         var helpFunc = () =>
         {
+            string sshaString = "";
+
+            if (File.Exists("ssha"))
+            {
+                sshaString = File.ReadAllText("ssha");
+            }
+
             return string.Join("\r\n", new[] {
-                    "Command help!!",
-                    "lcn : List Customer Name",
-                    "gc : GC Collect",
-                    "lc : List Clients",
-                    "silent : silent",
-                    "show : show log"
-                });
+                $"Git commit:{sshaString}",
+                "Command help!!",
+                "lcn : List Customer Name",
+                "gc : GC Collect",
+                "lc : List Clients",
+                "silent : silent",
+                "show : show log"
+            });
         };
         webApplication.MapGet("/", helpFunc);
         webApplication.MapGet("/help", helpFunc);

+ 110 - 0
Prerelease_Build.ps1

@@ -0,0 +1,110 @@
+# 設定 ASCII 藝術字的內容
+$asciiArt = @"
+  _____  _____  ______ _____  ______ _      ______           _____ ______ 
+ |  __ \|  __ \|  ____|  __ \|  ____| |    |  ____|   /\    / ____|  ____|
+ | |__) | |__) | |__  | |__) | |__  | |    | |__     /  \  | (___ | |__   
+ |  ___/|  _  /|  __| |  _  /|  __| | |    |  __|   / /\ \  \___ \|  __|  
+ | |    | | \ \| |____| | \ \| |____| |____| |____ / ____ \ ____) | |____ 
+ |_|    |_|  \_\______|_|  \_\______|______|______/_/    \_\_____/|______|
+"@
+
+# 顯示 ASCII 藝術字
+Write-Host $asciiArt
+
+#第一次建立專案請先設定ACR Name
+$registryname="evdevcontainerregistry"
+$fullregistryname="evdevcontainerregistry.azurecr.io"
+#第一次建立專案請先設定專案名稱
+$imagerepositoryname="server"
+#target tag can be {projectname}_RC or RC on pre-release stage
+$default_dev_prefix = "Docker_test_"
+$target_tag="Docker_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
+$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="dockerimageflow"
+#來源TAG
+$source_tag="Docker_RC"
+$targetTagPrefix="Docker_v"
+
+#檢查remote是否有新commit未處理
+git fetch
+$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
+}