<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Kanglin on Medium]]></title>
        <description><![CDATA[Stories by Kanglin on Medium]]></description>
        <link>https://medium.com/@kislxhotmail?source=rss-838e2995b9a0------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*jsF1SoqTIEGrqAazcPtdKA.jpeg</url>
            <title>Stories by Kanglin on Medium</title>
            <link>https://medium.com/@kislxhotmail?source=rss-838e2995b9a0------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 06 Dec 2026 17:08:48 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@kislxhotmail/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[透過分析 Git Tag 後去跑 Azure CI 時讓 npm build 特定的 command]]></title>
            <link>https://medium.com/@kislxhotmail/%E9%80%8F%E9%81%8E%E5%88%86%E6%9E%90-git-tag-%E5%BE%8C%E5%8E%BB%E8%B7%91-azure-ci-%E6%99%82%E8%AE%93-npm-build-%E7%89%B9%E5%AE%9A%E7%9A%84-command-64486585e652?source=rss-838e2995b9a0------2</link>
            <guid isPermaLink="false">https://medium.com/p/64486585e652</guid>
            <category><![CDATA[azure-pipelines]]></category>
            <category><![CDATA[powershell]]></category>
            <category><![CDATA[ci]]></category>
            <category><![CDATA[git-tags]]></category>
            <category><![CDATA[npm]]></category>
            <dc:creator><![CDATA[Kanglin]]></dc:creator>
            <pubDate>Thu, 25 Jul 2024 15:33:14 GMT</pubDate>
            <atom:updated>2024-07-25T15:33:14.495Z</atom:updated>
            <content:encoded><![CDATA[<p>抓到痛點去優化是多麽讓人開心的事情啊</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*q2hyalXm11x95e0c6R4aTQ.jpeg" /></figure><h3>Background</h3><p>最近在分析 Azure DevOps Release ( CI ) 效能時發現前端在跑 npm build 時，有時候明明只需要跑某個特定專案的 command 就好，但是每次跑 CI 就是預設 build 全部的專案，為了提升出 build 的效率，決定透過對 tag 做特定字元的判斷後，切成 version 跟 args，然後在 npm build 時將取出來的 args 組合成符合 package.json 裡的 npm command。</p><h3>Issue with Tag Splitting and Directory Creation in PowerShell on Windows OS</h3><p>該專案的 Azure agent 用 windows os，所以我這次用 powershell 來寫：</p><p><strong>原本的定義</strong><br>yy-1.1.1 =&gt; 這樣代表的是該 tag 是 yy專案，目前的 version 是 1.1.1<br><strong>修改成</strong><br>yy-1.1.1|yy01 =&gt; 這樣代表的是該 tag 是 yy專案，目前的 version 是 1.1.1，並且只想出 yy01 的 build</p><p>沒想到，這樣子的設定在 powershell 的 split 後轉成變數沒問題，但是在 azure agent 為當下 tag 建立資料夾時會因為 windows os 本身對於字元的限制，它不允許 |成為資料夾的名稱，後來改用 _解決了這個問題。</p><h3>task — GitTagVersion&amp;Args</h3><blockquote>如果有 hit 到特殊字元 _ 時，將 args 切出來，並將其 output 成 variables。</blockquote><pre>steps:<br>- powershell: |<br>   $tag_version=($env:Build_SourceBranch -replace &#39;refs/tags/yy-&#39;,&#39;&#39;)<br>   $version = $tag_version<br>   $args = &quot;&quot;<br>   <br>   # Check if the tag_version contains an underscore and split it if present<br>   if ($tag_version -match &quot;_&quot;) {<br>       $parts = $tag_version -split &#39;_&#39;, 2<br>       $version = $parts[0]<br>       $args = $parts[1]<br>   }<br>   <br>   # Update the build number in Azure DevOps<br>   echo &quot;##vso[build.updatebuildnumber]$version&quot;<br>   write-host &quot;Version: $version&quot;<br>   <br>   # Set the args variable in Azure DevOps if present, otherwise set it to &#39;None&#39;<br>   if ($args) {<br>       write-host &quot;Args: $args&quot;<br>       echo &quot;##vso[task.setvariable variable=args]$args&quot;<br>   } else {<br>       write-host &quot;Args: None&quot;<br>       echo &quot;##vso[task.setvariable variable=args]None&quot;<br>   }<br><br>  displayName: &#39; GitTagVersion V2&#39;</pre><h3>task — run npm build with arg</h3><blockquote>透過 condition 去判斷 args 是否為 None</blockquote><pre>steps:<br>- task: Npm@1<br>  displayName: &#39;npm build ( using tag )&#39;<br>  inputs:<br>    command: custom<br>    workingDir: &#39;$(Build.SourcesDirectory)&#39;<br>    verbose: false<br>    customCommand: &#39;run build:$(args)&#39;<br>    customRegistry: useFeed<br>  condition: ne(variables[&#39;args&#39;], &#39;None&#39;)</pre><h3>task — run npm build without arg</h3><pre>steps:<br>- task: Npm@1<br>  displayName: &#39;npm build ( using default )&#39;<br>  inputs:<br>    command: custom<br>    workingDir: &#39;$(Build.SourcesDirectory)&#39;<br>    verbose: false<br>    customCommand: &#39;run build:yy-all&#39;<br>    customRegistry: useFeed<br>  condition: eq(variables[&#39;args&#39;], &#39;None&#39;)</pre><h4>最後心得</h4><p>雖然這篇短短幾行，但是當初為了解決這個需求，要將 npm / pipeline variables / windows os folder naming rule / steps condition / powershell 等等的物件理解後並成功解決問題，著實花了不少時間，不過看到原本出 build 要花 20 mins 以上到如今只需要 7 ~ 8 分鐘，非常的開心。</p><p>不過實際上還有針對 CI 流程做優化的坑（因為使用 Azure DevOps Classic editor 的關係 ），之後有機會再上另一篇去講述。</p><h4>主要參考</h4><ul><li><a href="https://learn.microsoft.com/en-us/azure/devops/pipelines/process/set-variables-scripts?view=azure-devops&amp;tabs=powershell#about-tasksetvariable">Set variables in scripts - Azure Pipelines</a></li><li><a href="https://learn.microsoft.com/zh-tw/azure/devops/pipelines/process/expressions?view=azure-devops#ne">運算式 - Azure Pipelines</a></li><li><a href="https://learn.microsoft.com/en-us/azure/devops/pipelines/process/conditions?view=azure-devops#job-example-2">Pipeline conditions - Azure Pipelines</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=64486585e652" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Migrating a GitHub Repository to Azure DevOps]]></title>
            <link>https://medium.com/@kislxhotmail/migrating-a-github-repository-to-azure-devops-117970da250a?source=rss-838e2995b9a0------2</link>
            <guid isPermaLink="false">https://medium.com/p/117970da250a</guid>
            <category><![CDATA[azure-devops]]></category>
            <category><![CDATA[mistakes]]></category>
            <category><![CDATA[git]]></category>
            <dc:creator><![CDATA[Kanglin]]></dc:creator>
            <pubDate>Thu, 25 Jul 2024 10:22:33 GMT</pubDate>
            <atom:updated>2024-07-25T10:22:33.691Z</atom:updated>
            <content:encoded><![CDATA[<h4>不就改個 remote url 再推上去就好啦</h4><h3>Background</h3><p>原本是自己寫的一個 repo，放在 GitHub 上，後來因應需求轉移到 Azure DevOps Git Repo 上，將原本還不甚熟悉的地方了解後寫成這篇筆記。</p><h3>Information</h3><p>[github] git@github.com:Kanglinwu/sre_backend.git<br>[azure repo] git@ssh.dev.azure.com:v3/demo/infraPage</p><h3>整個調整流程跟備註</h3><h4>確認原本的 remote url</h4><pre>git remote -v <br>origin git@github.com:Kanglinwu/sre_backend.git (fetch)<br>origin git@github.com:Kanglinwu/sre_backend.git (push)</pre><h4>調整 remote url</h4><pre>git remote set-url origin git@ssh.dev.azure.com:v3/demo/infraPage<br>git remote -v<br>origin git@ssh.dev.azure.com:v3/demo/infraPage (fetch)<br>origin git@ssh.dev.azure.com:v3/demo/infraPage (push)</pre><h4>嘗試 git push</h4><pre>git push origin HEAD:main<br>! [rejected]<br>main -&gt; main (fetch first)<br>error: failed to push some refs to &#39;git@ssh.dev.azure.com:v3/demo/infraPage&#39; hint: Updates were rejected because the remote contains work that you do hint: not have locally. This is usually caused by another repository pushing hint: to the same ref. You may want to first integrate the remote changes hint: (e.g., &#39;git pull...&#39;) before pushing again.<br>hint: See the &#39;Note about fast-forwards&#39; in &#39;git push --help&#39; for details.</pre><h4>告警提示要我先做 fetch，做到這裡時，我決定保留原本的 github 為 origin，另外建立一個名為 azure 的 remote url。</h4><pre>git remote add azure git@ssh.dev.azure.com:v3/demo/infraPage<br>git remote set-url origin git@github.com:Kanglinwu/sre_backend.git<br>git remote -v<br>azure git@ssh.dev.azure.com:v3/demo/infraPage (fetch)<br>azure git@ssh.dev.azure.com:v3/demo/infraPage (push)<br>origin git@github.com:Kanglinwu/sre_backend.git (fetch)<br>origin git@github.com:Kanglinwu/sre_backend.git (push)</pre><h4>做 git fetch</h4><pre>git fetch azure<br>warning: no common commits<br>remote: Azure Repos<br>remote: Found 3 objects to send. (27 ms)<br>Unpacking objects: 100% (3/3), 740 bytes | 740.00 KiB/s, done.<br>From ssh.dev.azure.com:v3/demo/infraPage<br> * [new branch]      main       -&gt; azure/main</pre><h4>在 main branch 做 merge，卻遇到 fatal 告警</h4><pre>git merge azure/main<br>fatal: refusing to merge unrelated histories</pre><h4>這次在 merge 時加上 allow</h4><pre>git merge azure/main --allow-unrelated-histories<br>CONFLICT (add/add): Merge conflict in README.md<br>Auto-merging README.md<br>Automatic merge failed; fix conflicts and then commit the result.</pre><blockquote>提示要我先解決衝突，<strong><em>我發現是在建立新的 Azure DevOps git repo 時，我勾選了自動 create readme file 導致兩邊都有 readme file</em></strong><em>，所以調整完衝突後</em>，重新 commit &amp; push</blockquote><pre>git add README.md<br>git commit -m &quot;init&quot;<br>git push azure HEAD:main<br>Enumerating objects: 217, done.<br>Counting objects: 100% (217/217), done.<br>Delta compression using up to 2 threads<br>Compressing objects: 100% (198/198), done.<br>Writing objects: 100% (215/215), 192.18 KiB | 955.00 KiB/s, done.<br>Total 215 (delta 123), reused 8 (delta 0)<br>remote: Analyzing objects... (215/215) (408 ms)<br>remote: Validating commits... (21/21) done (1 ms)<br>remote: Storing packfile... done (36 ms)<br>remote: Storing index... done (45 ms)<br>To ssh.dev.azure.com:v3/demo/infraPage<br>   e9945a1..7b328b0  HEAD -&gt; main</pre><p><strong>最終完成了將目前專案丟一份到 Azure DevOps Git Repo 上，同時保留了 GitHub 原本的 remote url</strong></p><h3>不了解的地方</h3><blockquote><em>為什麼在第一次將 remote url 從 GitHub 指到 Azure DevOps Git Repo 後，一定要先 git fetch 才能 git push？</em></blockquote><p><em>chatGPT的回答：錯誤訊息表示 Azure 上的遠端儲存庫包含本機儲存庫中不存在的變更。要解決此問題，需要將這些變更整合到本機分支中，然後才能成功推送變更。</em></p><p>所以我一剛開始在建立 Azure DevOps Git Repo 時，只要不選擇自動 create readme file，它就不會這樣顯示，我後來再重新跑一次建立的流程時，發現當沒有勾選 create readme file，Azure DevOps Git Repo 會自動提示該 repo 是 empty，並提供了 user command for Push an existing repository from command line。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/962/1*kabxw4PBLFkx5gJD0XyOJQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*m3ETcvxZucsONd-njqJniA.png" /></figure><blockquote>做完 git fetch 後，想要做 git merge azure/main 時遇到的那個 fatal 是什麼？</blockquote><p><em>chatGPT的回答：When you encounter the error fatal: refusing to merge unrelated histories, it means that the branches do not share a common commit history. If your goal is to merge two repositories that were independently created (and thus have unrelated histories), the only way to proceed is to use the — allow-unrelated-histories option.</em></p><p>我目前的理解是：對於 git 來說，原先的 GitHub repo 跟我後來建立的 Azure DevOps Git Repo 是兩個獨立的 repository，並且兩邊的 commit history 沒有關聯，所以依據這樣的條件，唯一可以 merge 的方式是在 merge 時加上 <em>allow-unrelated-histories。</em></p><h3>最後感想</h3><p>一個不小心，多點了一個 create readme，就讓我重新學習並寫出這篇。<br>提醒自己，在每個問題出現後，先問問自己，這個問題為什麼會出現，有需要解決他嗎？</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=117970da250a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Managing multiple AWS CLI profiles with different credentials]]></title>
            <link>https://medium.com/@kislxhotmail/managing-multiple-aws-cli-profiles-with-different-credentials-ba8d4fd2eae3?source=rss-838e2995b9a0------2</link>
            <guid isPermaLink="false">https://medium.com/p/ba8d4fd2eae3</guid>
            <category><![CDATA[aws-cli]]></category>
            <category><![CDATA[profile]]></category>
            <dc:creator><![CDATA[Kanglin]]></dc:creator>
            <pubDate>Wed, 24 Jul 2024 02:47:40 GMT</pubDate>
            <atom:updated>2024-07-24T02:47:40.755Z</atom:updated>
            <content:encoded><![CDATA[<h4>用 profile 快速切換成不同憑證</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MfWDlFQZ3aIVD6vBPkHTWA.png" /></figure><p>使用 AWS CLI 設定檔可以有效地管理不同的憑證。以下是設定、更新多個 AWS CLI 設定檔以及在多個 AWS CLI 設定檔之間切換的方法：</p><h4>Step1、建立 profile</h4><p>透過 aws cli 的 command aws configure -profile 建立存放 AccessKey &amp; SecretKey 的 profile。舉例目前我要建立兩個 profiles，一個是 profile1 ，另一個是 profile2 。</p><pre># create profile1<br>aws configure --profile profile1<br><br># create profile2<br>aws configure --profile profile2</pre><p>在建立時，依照提示輸入對應的 AWS Access Key ID、AWS Secret Access Key、Default region name、Default output format。</p><h4>Step2、使用 profile</h4><p>使用 AWS CLI Command 時，可以帶上 profile flag 就能透過 step1 設定好的 profile 去撈 AWS。</p><pre># using profile1<br>aws s3 ls --profile profile1<br><br># using profile2<br>aws s3 ls --profile profile2</pre><h3>Step3、設定預設 AccessKey &amp; SecretKey</h3><p>如果很常使用特定的一個 profile，可以透過更新 credentials file 裡的 [default] 區塊，將你比較常用的 AccessKey &amp; SecretKey copy 到該區塊。<em>（通常 credentials file 會在 ~/.aws 裡）</em></p><pre>[default]<br>aws_access_key_id = YOUR_ACCESS_KEY_ID<br>aws_secret_access_key = YOUR_SECRET_ACCESS_KEY<br><br>[profile1]<br>aws_access_key_id = YOUR_ACCESS_KEY_ID<br>aws_secret_access_key = YOUR_SECRET_ACCESS_KEY<br><br>[profile2]<br>aws_access_key_id = YOUR_ACCESS_KEY_ID<br>aws_secret_access_key = YOUR_SECRET_ACCESS_KEY</pre><h4>Step4、透過 command 重新設定 profile</h4><p>如果要更新 profile 內容，可以透過修改 .aws folder 裡的 file 也可以透過 command 方式執行。</p><pre>aws configure --profile profile1</pre><p>command line 就會再次跳出提示並附上目前的 value，需要調整就貼上新值，如果不需要調整就 enter 繼續下一個。</p><h4><strong>總結：</strong></h4><p>透過使用多個 profile，可以輕鬆管理不同群組的 AWS 憑證，使用 AWS CLI 命令中的 — profile flag 去使用不同的憑證，以確保無縫切換和管理自己的 AWS 環境。</p><h4><strong>主要參考：</strong></h4><p><a href="https://docs.aws.amazon.com/cli/v1/userguide/cli-configure-files.html">Configuration and credential file settings</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ba8d4fd2eae3" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[AWS S3 lifecycle]]></title>
            <link>https://medium.com/@kislxhotmail/aws-s3-lifecycle-95e9bfe31e64?source=rss-838e2995b9a0------2</link>
            <guid isPermaLink="false">https://medium.com/p/95e9bfe31e64</guid>
            <category><![CDATA[lifecycle]]></category>
            <category><![CDATA[aws-s3]]></category>
            <dc:creator><![CDATA[Kanglin]]></dc:creator>
            <pubDate>Tue, 23 Jul 2024 16:40:34 GMT</pubDate>
            <atom:updated>2024-07-23T16:45:59.403Z</atom:updated>
            <content:encoded><![CDATA[<h4>筆記及實作</h4><p>想要透過 lifecycle rule 讓 1天以上的 objects 被標記為 expired，並刪除。</p><h3><strong>設定之前</strong></h3><p>在還沒有設定 lifecycle rule 之前，到該 bucket 的 object 裡面去 Properties 子頁面裡會看到 Object management overview 裡針對 Expiration rule &amp; Expiration date 會顯示 - ，代表現在這個 object 沒有被標注 expired。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bgdX0iTIxagOEGuEkW4c1A.png" /><figcaption>screenshot for bucket — click the 20240723.md to see the object details</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-6D_NxPqGMqPygY7patgIA.png" /><figcaption>screenshot for a object on target bucket — scroll down to see the Object management overview</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2Fi7Zdv-9-0xbvu6JH0RxQ.png" /><figcaption>redbox — current value</figcaption></figure><h3>設定細節</h3><p>一、到 bucket 的 Management 子頁面裡的 Lifecyle rules 裡點選 button 建立新的 lifecycle button rule。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*p0IzQ4M2j7Rop1HBCQylfQ.png" /><figcaption>screenshot for `create lifecycle rule` button</figcaption></figure><p>二、建立 rule 1 — 當 object 建立時間超過一天時，將其標註為 expired，因為是展示用，並沒有特別寫 filter，直接全部套用即可。</p><p>Lifecycle rule name: append-expired-time-after-1day <br>Choose a rule scope: Apply to all objects in the buckets <br>Lifecycle rule actions: Expire current version of objects <br>Expire current versions of objects: 1</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vzgkoFdOFXMPmmcyLd7KlQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*caLewoSBl9eKAolNjAyfeQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*j4tUbkRJLMnDuNDNEIUfkQ.png" /></figure><p>三、建立 rule 2–當 object 被標註為 expired 時，將其永久刪除。</p><p>Lifecycle rule name: delete-expired-object<br>Choose a rule scope: Apply to all objects in the buckets <br>Lifecycle rule actions: Delete expired object delete marker or incomplete multipart uploads <br>Delete expired object delete markers or incomplete multipart uploads:<strong> </strong>將兩個 option 均勾選</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*33g66OV5hX2oohBFzYFstg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4tvolnunRY97g0XM3V-JYA.png" /></figure><h3>設定後</h3><p>雖然 lifecycle rule 已經建立，但是它不會立即套用到每個 object，所以會有延遲（一天跑一次，細節請參考主要參考2）。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PPeKPXHfViCGs4dHYfVIiQ.png" /><figcaption>設定好兩個 rule 後的畫面</figcaption></figure><p>當 lifecycle 被排程觸發後，便可以在那些超過一天的 object 裡，看到已經被標記成 expired</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xLF4uTwCsmGJTCv9wklJnA.png" /></figure><p>但是這樣的設計，在建立好 rule 時那些 object 會先 trigger 到 rule 1（將其標註成 expired ），過一天後，才會 trigger 到 rule 2（將其永久刪除）。</p><h3><strong>主要參考：</strong></h3><p>https://repost.aws/knowledge-center/s3-empty-bucket-lifecycle-rule<br>https://repost.aws/knowledge-center/s3-lifecycle-rule-delay</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=95e9bfe31e64" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Azure CICD agent — folder meaning]]></title>
            <link>https://medium.com/@kislxhotmail/azure-cicd-agent-folder-meaning-55ed7ea96500?source=rss-838e2995b9a0------2</link>
            <guid isPermaLink="false">https://medium.com/p/55ed7ea96500</guid>
            <category><![CDATA[cicd]]></category>
            <category><![CDATA[azure-devops]]></category>
            <category><![CDATA[meaning]]></category>
            <category><![CDATA[agents]]></category>
            <dc:creator><![CDATA[Kanglin]]></dc:creator>
            <pubDate>Mon, 22 Jul 2024 01:51:10 GMT</pubDate>
            <atom:updated>2024-07-22T01:51:10.815Z</atom:updated>
            <content:encoded><![CDATA[<h3>Azure CICD agent — folder meaning</h3><p>可以透過每次的 cicd 裡的 Initialize job 去知道這一次的 job 是用哪一組 agent 裡的哪一個 folder</p><p>範例：</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qr9HNJLqb0am0u9yym_BbA.png" /><figcaption>screenshot of log on azure devops</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*k-5E5Dis8BHcS5axlxupvg.png" /><figcaption>screenshot of agent folder</figcaption></figure><p>個別的 folder 的定義：</p><pre>a =  (Artifacts Directory)<br>The a directory stands for artifacts. This is where the build artifacts are stored. After a build is completed, the outputs (e.g., compiled binaries, package files, etc.) are placed in this directory. These artifacts can then be published and used in subsequent stages of the pipeline, such as release or deployment stages.<br>---<br>s = (Sources Directory)<br>The s directory stands for sources. This is where the source code is checked out. When a build pipeline runs, the source code from the repository is cloned or fetched into this directory. All the build tasks that need access to the source code will typically operate within this directory.<br>---<br>b = (Binaries Directory)<br>The b directory stands for binaries. This directory is used to store intermediate build outputs and binaries. During the build process, temporary files, object files, and other intermediate outputs are often placed here.<br>---<br>TestResults<br>The TestResults directory is used to store the results of test executions. When tests are run as part of the build pipeline, the results (e.g., test logs, coverage reports, test result files) are saved in this directory. These results can then be published to the Azure DevOps portal for review.</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=55ed7ea96500" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Azure load balance DNAT note]]></title>
            <link>https://medium.com/@kislxhotmail/azure-load-balance-dnat-note-593f6f49a7d1?source=rss-838e2995b9a0------2</link>
            <guid isPermaLink="false">https://medium.com/p/593f6f49a7d1</guid>
            <dc:creator><![CDATA[Kanglin]]></dc:creator>
            <pubDate>Wed, 10 Apr 2024 12:47:58 GMT</pubDate>
            <atom:updated>2024-04-10T12:47:58.751Z</atom:updated>
            <content:encoded><![CDATA[<h3>Create the Load Balancer to provide the DNAT</h3><p>在建立 Load Balancer 時，針對 incoming traffic 有兩種方式可以建立，無論哪種方式都需要先設定好 Frontend IP Configuration ( 對外 IP )</p><h3><strong>Load balancing rules</strong></h3><ul><li>一定要吃 backend pool</li><li>只會有一個對外 port</li><li>需要建立 health probe</li><li>但是不知道 load balance 的 policy 為何</li></ul><h3><strong>Inbound NAT rules</strong></h3><ul><li>可以使用單一 instance</li><li>如果 Destination 選用 backend pool, 且有多個 backend server 在 pool 時，他會轉成像 port-mapping 的方式</li></ul><pre># backend pool - [&#39;10.0.0.1/32&#39;, &#39;10.0.0.2/32&#39;] <br># backend port - TCP/1433 <br># frontend ip - [&#39;8.8.8.8&#39;] <br># frontend port - TCP/1433  <br><br>建立好後，會轉成像這樣 <br><br>8.8.8.8:1433 -&gt; DNAT -&gt; 10.0.0.1:1433 <br>8.8.8.8:143? -&gt; DNAT -&gt; 10.0.0.2:1433</pre><h3><strong>官方針對兩者差異的解釋</strong></h3><p>Inbound NAT rules are used to specify a backend resource to route traffic to. For example, configuring a specific load balancer port to send RDP traffic to a specific VM. Load-balancing rules are used to specify a pool of backend resources to route traffic to, balancing the load across each instance. For example, a load balancer rule can route TCP packets on port 80 of the load balancer across a pool of web servers.</p><p><a href="https://learn.microsoft.com/en-us/azure/load-balancer/load-balancer-faqs#how-do-i-configure-my-load-balancer-with-an-azure-sql-server-always-on-availability-group-">reference link</a></p><h3>Reminder</h3><p>建立好 load balance rules 後，相對應的 instance 會浮現出綁定 public ip via load balance 的紀錄，於是，也需要對應的調整 NSG，讓要透過 8.8.8.8 進來的 user 能夠成功連結。</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=593f6f49a7d1" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Manually adjust the auto-increment value on mysql]]></title>
            <link>https://medium.com/@kislxhotmail/manually-adjust-the-auto-increment-value-on-mysql-c74bbfa4ac1c?source=rss-838e2995b9a0------2</link>
            <guid isPermaLink="false">https://medium.com/p/c74bbfa4ac1c</guid>
            <category><![CDATA[mysql]]></category>
            <category><![CDATA[operations]]></category>
            <dc:creator><![CDATA[Kanglin]]></dc:creator>
            <pubDate>Mon, 03 Apr 2023 19:44:11 GMT</pubDate>
            <atom:updated>2023-04-03T19:44:11.792Z</atom:updated>
            <content:encoded><![CDATA[<h3>Manually adjust the auto-increment value on MySQL</h3><p>This scenario describes a situation in which a database table (a_table) is being updated with data every day and the primary key, or ID, is increasing with each update. To avoid having the primary key start at a large number, the auto-increment needs to be decreased.</p><pre># Flask<br>from flask_sqlalchemy import SQLAlchemy<br>db = SQLAlchemy()<br><br># DB models<br>class get_a_table(db.Model):<br>  __bind_key__ = &#39;local&#39;<br>  __tablename__ = &#39;a_table&#39;<br>  id = db.Column(db.Integer, primary_key=True)p<br>  a_name = db.Column(db.String(50))<br>  a_ip = db.Column(db.String(50))<br>  a_service = db.Column(db.String(60))<br>  a_pool = db.Column(db.Text)<br>  a_env = db.Column(db.Integer)<br><br># Delete row when env == 4<br>db.session.query(get_a_table).filter(get_a_table.env==4).delete()<br><br># Everyday will add new rows via list  - result<br>for i in result:<br>  db.session.add(get_a_table(**i))</pre><p>I tried to adjust the auto-increment via command — <br>alter table a_table AUTO_INCREMENT=1;<br>But this will not work because the current row’s primary key is greater than 1.</p><p><strong>so here is my workaround —</strong></p><blockquote>Be careful, IN THIS TABLE, I DON”T USE ANY relationship.</blockquote><ol><li>BACKUP / ROLLBACK the table command, just incase.</li><li>CREATE new temp table and clone the infrastructure from origin table.</li><li>define the auto-index start from 0 ( id ), and copy the rows from origin to temp_table meanwhile adjust the primary key by :=</li><li>DROP the origin table</li><li>RENAME TABLE temp_table to origin_table</li></ol><pre># [1]<br># backup <br>mysqldump -u &lt;username&gt; -p a_database a_table &gt; a_table_backup.sql<br># rollback<br>mysql -u &lt;username&gt; -p a_database &lt; a_table_backup.sql</pre><pre>-- [2]<br>CREATE TABLE a_table_temp LIKE a_table;</pre><pre>-- [3]<br>SET @id := 0;<br>INSERT INTO a_table_temp (id, a_name, a_ip, a_service, a_pool, a_env)<br>SELECT @id := @id + 1, a_name, a_ip, a_service, a_pool, a_env<br>FROM a_table<br>ORDER BY id;</pre><pre>-- [4]<br>DROP TABLE a_table;</pre><pre>-- [5] <br>RENAME TABLE a_table_temp TO a_table;</pre><p>After the above workaround, my auto-increment value decreased, which is all I wanted to share today. Thank you for reading.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c74bbfa4ac1c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to configure Access to Multiple Clusters for Kubectl]]></title>
            <link>https://medium.com/@kislxhotmail/how-to-configure-access-to-multiple-clusters-for-kubectl-5ab8e33eba30?source=rss-838e2995b9a0------2</link>
            <guid isPermaLink="false">https://medium.com/p/5ab8e33eba30</guid>
            <category><![CDATA[cluster]]></category>
            <category><![CDATA[kubectl]]></category>
            <category><![CDATA[kubernetes]]></category>
            <dc:creator><![CDATA[Kanglin]]></dc:creator>
            <pubDate>Sun, 05 Mar 2023 16:39:56 GMT</pubDate>
            <atom:updated>2023-03-05T16:39:56.795Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/487/1*ykSHLVXWsAk0CS_5VivvcA.png" /></figure><p>Refer to <a href="https://kubernetes.io/docs/tasks/access-application-cluster/configure-access-multiple-clusters/">https://kubernetes.io/docs/tasks/access-application-cluster/configure-access-multiple-clusters/</a></p><h3>By default, kubectl will use the config in the .kube folder.</h3><p>When you execute the following command, you will generate the config on the .kube folder, such as -</p><pre>kubectl config --kubeconfig=config set-cluster development --server=https://1.2.3.4 --certificate-authority=fake-ca-file<br>kubectl config --kubeconfig=config set-context dev-frontend --cluster=development --namespace=frontend --user=developer<br>kubectl config --kubeconfig=config set-credentials developer --client-certificate=fake-cert-file --client-key=fake-key-seefile</pre><pre>apiVersion: v1<br>clusters:<br>- cluster:<br>    certificate-authority: fake-ca-file<br>    server: https://1.2.3.4<br>  name: development<br>contexts:<br>- context:<br>    cluster: development<br>    namespace: frontend<br>    user: developer<br>  name: dev-frontend<br>current-context: &quot;&quot;<br>kind: Config<br>preferences: {}<br>users:<br>- name: developer<br>  user:<br>    client-certificate: fake-cert-file<br>    client-key: fake-key-seefile</pre><h3>But if you have more and more clusters to handle, for me, I don’t want to use the above command to update the config, so here is my workaround.</h3><ol><li>Create multiple folders for each cluster; for example, I have cluster-a, cluster-b, and cluster-c, so I will create folders with the same names.</li><li>Put the cluster-x config in the cluster-x folder, keeping the file name as config. Now you should have three folders, each with one file (config) that includes the correct values for clusters/users/contexts/current-context.</li><li>Now, you might use the following command to generate your config in the .kube folder.</li></ol><pre>KUBECONFIG=~/.kube/cluster-a/config:.kube/cluster-b/config:.kube/cluster-c/config kubectl config view --merge --flatten &gt; ~/.kube/config</pre><ul><li>After above command, you will generate the config on .kube folder</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/272/1*b4e2QaKnF9bdqp0l39N0gg.png" /></figure><ul><li>And you can use the following command to check your kubectl config setting, because it has finished!</li></ul><pre>kubectl config get-contexts</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5ab8e33eba30" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[About Helm]]></title>
            <link>https://medium.com/@kislxhotmail/about-helm-6d880595d437?source=rss-838e2995b9a0------2</link>
            <guid isPermaLink="false">https://medium.com/p/6d880595d437</guid>
            <category><![CDATA[metricbeat]]></category>
            <category><![CDATA[elk]]></category>
            <category><![CDATA[helm]]></category>
            <category><![CDATA[sre]]></category>
            <dc:creator><![CDATA[Kanglin]]></dc:creator>
            <pubDate>Thu, 02 Mar 2023 13:15:28 GMT</pubDate>
            <atom:updated>2023-03-02T13:15:28.488Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/487/1*Ino3RG0HQsrMLUcQKnsGVw.png" /></figure><p>Using metricbeat as an example.</p><p>Refer to <a href="https://github.com/elastic/helm-charts/blob/main/metricbeat/README.md#installing">Metricbeat Helm Chart</a></p><p>Outline — <br>1. By default, without any custom options.<br>2. If you want to choose the version by yourself …<br>3. You need to change some configurations let it working, but how do you get the default values.yaml?<br>4. Do you want to check the current values for your release locally?<br>5. After you have edited the custom_values.yaml, how do you install Metricbeat with your custom_values.yaml?<br>6. How can I download the helm template, adjust it, and then use it?</p><p>By default, without any custom options.</p><pre># Add the Elastic Helm charts repo<br>&gt; helm repo add elastic https://helm.elastic.co<br><br># verify<br>&gt; helm repo list | grep elastic<br>elastic         https://helm.elastic.co<br><br># install the Metricbeat<br>&gt; helm install metricbeat elastic/metricbeat</pre><p>If you want to choose the version by yourself …</p><pre># Using helm search to check avaiablible version<br>&gt; helm search repo elastic/metricbeat --versions<br>NAME                    CHART VERSION   APP VERSION     DESCRIPTION<br>elastic/metricbeat      8.5.1           8.5.1           Official Elastic helm chart for Metricbeat<br>elastic/metricbeat      7.17.3          7.17.3          Official Elastic helm chart for Metricbeat<br>elastic/metricbeat      7.17.1          7.17.1          Official Elastic helm chart for Metricbeat<br>elastic/metricbeat      7.16.3          7.16.3          Official Elastic helm chart for Metricbeat<br>elastic/metricbeat      7.16.2          7.16.2          Official Elastic helm chart for Metricbeat<br>elastic/metricbeat      7.16.1          7.16.1          Official Elastic helm chart for Metricbeat<br>elastic/metricbeat      7.15.0          7.15.0          Official Elastic helm chart for Metricbeat<br>elastic/metricbeat      7.14.0          7.14.0          Official Elastic helm chart for Metricbeat<br>elastic/metricbeat      7.13.4          7.13.4          Official Elastic helm chart for Metricbeat<br>elastic/metricbeat      7.13.3          7.13.3          Official Elastic helm chart for Metricbeat<br>elastic/metricbeat      7.13.2          7.13.2          Official Elastic helm chart for Metricbeat<br>elastic/metricbeat      7.13.1          7.13.1          Official Elastic helm chart for Metricbeat<br>elastic/metricbeat      7.13.0          7.13.0          Official Elastic helm chart for Metricbeat<br>elastic/metricbeat      7.12.1          7.12.1          Official Elastic helm chart for Metricbeat<br>elastic/metricbeat      7.12.0          7.12.0          Official Elastic helm chart for Metricbeat<br>elastic/metricbeat      7.11.2          7.11.2          Official Elastic helm chart for Metricbeat<br>elastic/metricbeat      7.11.1          7.11.1          Official Elastic helm chart for Metricbeat<br>elastic/metricbeat      7.10.2          7.10.2          Official Elastic helm chart for Metricbeat<br>elastic/metricbeat      7.10.1          7.10.1          Official Elastic helm chart for Metricbeat<br>elastic/metricbeat      7.10.0          7.10.0          Official Elastic helm chart for Metricbeat<br>elastic/metricbeat      7.9.3           7.9.3           Official Elastic helm chart for Metricbeat<br>elastic/metricbeat      7.9.2           7.9.2           Official Elastic helm chart for Metricbeat<br>elastic/metricbeat      7.9.1           7.9.1           Official Elastic helm chart for Metricbeat<br><br># By default, you will install version 8.5.1, but I will pick up version 7.17.3 for my example.<br>&gt; helm install metricbeat elastic/metricbeat --version 7.17.3</pre><p>But refer this document — <a href="https://github.com/elastic/helm-charts/blob/main/metricbeat/README.md#usage-notes">https://github.com/elastic/helm-charts/blob/main/metricbeat/README.md#usage-notes</a></p><p>You need to change some configurations let it working, but how do you get the default values.yaml?</p><pre># inspects a chart (directory, file, or URL) and displays the contents<br>of the values.yaml file and export to current folder ( name - custom_values.yaml )<br>&gt; helm show values elastic/metricbeat --version 7.17.3 &gt; custom_values.yaml</pre><p>Do you want to check the current values for your release locally?</p><pre># assume local release name is metricbeat<br>&gt; helm get values metricbeat<br><br># or get the manifest<br>&gt; helm get manifest metricbeat</pre><p>After you have edited the custom_values.yaml, how do you install Metricbeat with your custom_values.yaml?</p><pre># Assuming you are already in the same folder as the custom_values.yaml file<br>&gt; helm install metricbeat elastic/metricbeat --version 7.17.3 -f custom_values.yaml</pre><p>How can I download the helm template, adjust it, and then use it?</p><pre># 1 - Get the templates<br>&gt; helm pull elastic/metricbeat --version 7.17.3<br><br># It will download as &quot;metricbeat-7.17.3.tgz&quot; to your current folder.<br><br># 2 - Create the folder <br>&gt; mkdir metricbeat-templates<br><br># 3 - Extract the tgz file<br>&gt; tar -zxvf metricbeat-*.tgz -C metricbeat-templates/ --strip-components=1 --wildcards &quot;metricbeat/templates/*&quot;<br><br># 4 - After you have edited the template YAML, compress it as metricbeat-templates.tar.gz<br>&gt; tar -czvf metricbeat-templates.tar.gz -C ~/metricbeat/metricbeat-templates .<br><br># 5 - Install metricbeat and set values from respective files specified via the command line<br>&gt; helm install metricbeat elastic/metricbeat --version 7.17.3 --set-file metricbeat.config.modules=~/metricbeat/metricbeat-templates</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6d880595d437" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Using Flask to execute AWS Cli command]]></title>
            <link>https://medium.com/@kislxhotmail/using-flask-to-execute-aws-cli-command-f74a0fc93900?source=rss-838e2995b9a0------2</link>
            <guid isPermaLink="false">https://medium.com/p/f74a0fc93900</guid>
            <category><![CDATA[aws-cli]]></category>
            <category><![CDATA[flask]]></category>
            <dc:creator><![CDATA[Kanglin]]></dc:creator>
            <pubDate>Sun, 27 Nov 2022 02:39:42 GMT</pubDate>
            <atom:updated>2022-11-27T02:39:42.223Z</atom:updated>
            <content:encoded><![CDATA[<h3>透過這篇分享能得到: <br>要將跑在docker container上的flask, 能夠透過aws cli的方式, 將aws的資料抓回來使用</h3><p><strong>條列重點:</strong><br>1. <strong>打包DockerImage時安裝並下載AWS CLI V2</strong>:<br>因為是把flask run在docker container裡, 而flask去執行aws cli是透過subprocess的方式, 所以在打包docker image時, 需要先把aws cli下載進image並install, 這樣才能讓在docker container裡的flask透過subprocess去執行aws cli.<br>2. <strong>透過Flask BluePrint去降低需要重新打包的次數</strong>:<br>畢竟是docker container, 你不會想要每改一次code就重新打包一次docker image, 所以用BluePrint的方式, 將需要常更動的route切開來(sub_aws folder), 然後在docker run的時候用-v的方式(mount a volume)將folder mount上去, 這樣你就不需要每次改sub_aws/main_aws.py後都需要重新打包docker.<br>3. <strong>當透過flask route去execute aws configure時:<br></strong>有遇到兩個問題<br>3–1 用aws cli去下aws configure時, aws cli會要你輸入四次input ( account, password, region, default output ), 如何透過subprocess去執行<br>3–1 以flask @app.route(‘/login’) 的方式讓user能夠透過傳遞querystring的方式登入(不安全我知道), 但是不斷fail, 為何?</p><p><strong>細節你都懂時, 你只想直接試試看<br></strong><a href="https://gitlab.com/kanglinwu/flask_aws_cli">kanglin_tw / flask_aws_cli · GitLab</a></p><p><strong>on Dockerfile, how to download AWS Cli and install it?</strong></p><pre># install aws<br>RUN apt-get install -y unzip \<br>    curl \<br>    &amp;&amp; apt-get clean \<br>    &amp;&amp; curl &quot;https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip&quot; -o &quot;awscliv2.zip&quot; \<br>    &amp;&amp; unzip awscliv2.zip \<br>    &amp;&amp; ./aws/install \<br>    &amp;&amp; rm -rf \<br>        awscliv2.zip \<br>    &amp;&amp; apt-get -y purge curl \<br>    &amp;&amp; apt-get -y purge unzip </pre><p><strong>Using the Flask bluePrint</strong></p><p><em>main.py</em></p><pre># Blueprint - import sub_folder<br>from sub_aws.main_aws import app_aws<br><br>app = Flask(__name__)<br><br># Blueprint - register sub_folder<br>app.register_blueprint(app_aws, url_prefix=&#39;/_aws&#39;)</pre><p>sub_aws/main_aws.py</p><pre>from flask import Blueprint<br><br>app_aws = Blueprint(&#39;app_aws&#39;, __name__ )<br><br>@app_aws.route(&#39;/get/ec2/describe-instances&#39;)<br>def query_aws_get_ec2_describe_instances():<br>  return &#39;test&#39;<br></pre><p><strong>Run the docker container with -v</strong> and <strong>Why need to use the BluePrint</strong></p><p>透過git clone把範例資料下載下來後, 在local端裡會有sub_aws這個folder, 這個時候參考git裡面的README去將docker container run起來, in default 你先跑一次/login (要帶上querystring, 參考main.py裡的備註)後就可以透過_aws/get/ec2/describe-instances去撈到aws ec2 describe-instance的資料(注意region).<br>接下來, 你一定會有需要新增的aws cli command你可以寫在main_aws.py裡, 然後因為你docker run是將local端的sub_aws mount上去docker container, 所以修改完main_aws.py的route後, 你應該能直接使用, 不需要在重新打包docker image</p><p><strong>Subprocess</strong></p><pre># Default Flask <br>from flask import Flask, request<br><br>import subprocess<br><br>app = Flask(__name__)<br><br># before call the aws cli function, need to login first<br># full url - http://127.0.0.1:5001/login?_id=xxxxx&amp;_key=xxxxx<br>@app.route(&#39;/login&#39;)<br>def aws_configure_login():<br>    # (i.e. ?user=some-value)<br>    _id = request.args.get(&#39;_id&#39;)<br>    _key = request.args.get(&#39;_key&#39;).replace(&quot; &quot;, &quot;+&quot;) # request.args.get will miss +<br>    p =subprocess.Popen([&#39;aws&#39;, &#39;configure&#39;], stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)<br>    # in this case, aws configure will request 4 times input, so each input needs to use the &quot;\n&quot; to end it ( just like a press Enter )<br>    enter_account = p.communicate(input=f&#39;{_id}\n{_key}\n\njson\n&#39;.encode())<br>    return &#39;login the aws cli success&#39;</pre><p>先用subprocess.Popen去執行aws configure, 然後透過subprocess.Popen.communicate去輸入input, 但是因為aws cli的aws configure後需要輸入四次資料(account, password, region, default output), 所以在input裡每個段string透過\n去模擬press Enter<br>例如: <br>account = kanglinwu<br>password = testpassword<br>region, 不設定<br>default output = json<br>那在communicate裡的input就是<br>&#39;kanglinwu\ntestpassword\n\njson\n&#39;</p><p><strong>QueryString</strong></p><p><a href="http://127.0.0.1:5001/login?_id=xxxxx&amp;_key=xxxxx">http://127.0.0.1:5001/login?_id=xxxxx&amp;_key=xxxxx</a></p><p>透過flask request去抓_id and _key的值<br>但是發現當value裡有&quot;+&quot;時, 會自動被replace成&quot; &quot;, 所以才會有在後端手動將value replace回來的動作, 但是這是for我個人, 所以如果after login後, 在query aws cli result時如果一直失敗, 可以先檢查這一塊</p><p>以上就是今天的分享, 有幫助就幫我拍拍, 感恩<br>有建議或不清楚歡迎私訊LinkedIn — <a href="http://www.linkedin.com/in/kanglinwu">www.linkedin.com/in/kanglinwu</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f74a0fc93900" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>