April 16, 2016

Get a free SSL certificate

Sometimes when you work on PoC for web-based projects using HTTPS, you may want to have a SSL certificate for testing. You may simply create a self-signed certificate from IIS, however, when you visit the web site installed with self-signed certificate, you'll see a warning page you must be quite familiar with


There's a certificate authority called Let’s Encrypt, who's offering free SSL certificate valid for 3 months. That means you'll need to renew the certificate every 3 months, but that's quite enough for PoC. You can use Let's Encrypt client to obtain your cert via some command lines. I'm not a fan of command line, but fortunately I found a website at https://www.sslforfree.com/ built upon Let's Encrypt. Following some simple (but a bit tricky for Windows users) steps, you can get your free cert.
  1. Go to the website, input the domain you would like to create the cert for and click Create Free SSL Certificate

  2. Choose the way of verifying you are the owner of the domain. I haven't tried Automatic FTP Verification so I'll simply walk through Manual Verification and click Manually Verify Domain





  3. Assuming you are a Windows user, set up a IIS web site. The web site has to be publicly exposed on the internet and whitelist 66.133.109.36 (at the time of writing this post, it is this IP address) as mentioned in the page and bind the domain to the web site
  4. Click Download File #1, you will get a text file for further uploading. The file name and content will be different every time you request for the cert
  5. Create a folder in the root of the website named .well-known. Notice that you may get a warning message to stop you.


    Instead use the folder name .well-known., the folder will be created successfully and the last dot will disappear
  6. Create a folder named acme-challenge under .well-known and copy the downloaded file to acme-challenge
  7. Click the link (for instance, http://test.petekcchen.com/.well-known/acme-challenge/mRIcor-5_-TPKeZJALHjCP4RdZMuchs-3u4XmfHT840) provided on the page, you may see 404 since the downloaded file does not have extension and it will be ignored by IIS. So go to your IIS website, add a MIME type as below
    then you'll be able to see the result

  8. Click Download SSL Certificate and the site service will communicate with Let's Encrypt to get the cert for you
  9. Click Download All SSL Certificate Files and you'll get a zip file named sslforfree.zip containing ca_bundle.crtcertificate.crt and private.key

    You can then install certificate.crt on IIS and configure the HTTPS binding. It will work perfectly.

April 3, 2016

TeamCity - 安裝分散式Build Agent

TeamCity在安裝完成時預設只會安裝1個build agent(以下簡稱BA),在之前的文章中也提到了如何安裝額外的BA,不管是Professional或是Enterprise版本,TC最多可以使用3個BA,除非以付費方式額外購買BA的授權(以目前官網報價1個BA含10個build configurations需美金299元)。

之前所介紹的BA安裝都是在本機上執行,但其實並非一定要安裝在本機上,也可以安裝在不同主機上,TC可以分散式的方式管理BA。在實務上,我遇到兩種情況讓我做分散式BA。
  1. 一個雙核VM,上面已有2個BA,為了增加效率,我把第3個BA安裝在另一個VM上,原本的VM就不需耗費太多額外資源(建置程式碼、跑單元測試或整合測試及自動佈署網站等)。
  2. 把BA安裝在data center中專門部署用的VM裡,讓BA可以直接打包系統發佈到production,加快部署速度。
設定分散式BA很簡單,只需要兩個主要步驟。
  1. 在另一台主機安裝BA。可參考TeamCity - 安裝額外的Build Agent一文,安裝過程一樣,差別只在於設定BA屬性時,serverUrl需指到TC所在位址,如http://192.168.1.11:80


  2. 在TC中授權新安裝的BA。安裝完BA後可以在Agents頁面看到Unauthorized有1個BA







    授權成功後可以看到Connected變為3


    點選buildagent3可以看到BA所在主機的相關資訊



March 14, 2016

TeamCity - 手動安裝Build Agent

TeamCity - 安裝額外的Build Agent中提到了使用Windows安裝檔方式安裝Build Agent,過程中仍需些微地以手動方式修改設定檔。我們也可以完全手動方式安裝Build Agent,當然安裝過程相對地又更複雜些。

先至Agents頁面,點選Install Build Agents下載安裝檔


手動安裝需點選Zip file distribution下載安裝檔(buildAgent.zip)。預設安裝好的第一個Build Agent路徑位於C:\TeamCity\buildAgent,所以如果安裝的是第二個Build Agent,建議解壓縮在C:\TeamCity\buildAgent2,以此類推。

C:\TeamCity\buildAgent2\conf\buildAgent.dist.properties更名為buildAgent.properties並修改serverUrlname以及ownPort



開啟C:\TeamCity\buildAgent2\launcher\conf\wrapper.conf並修改wrapper.java.command(可直接參考C:\TeamCity\buildAgent\launcher\conf\wrapper.conf)、wrapper.ntservice.namewrapper.ntservice.displaynamewrapper.ntservice.description



最後以管理員權限依序執行C:\TeamCity\buildAgent2\bin下的install.batservice.install.batservice.start.bat,稍等一下即可在Agents頁面看到第二個Build Agent。

March 13, 2016

TeamCity - 安裝額外的Build Agent

TeamCity(以版本9.1.6為例)在安裝完成後,預設會同時安裝並啟動一個Build Agent,在TeamCity Professional中,最多可允許使用三個Build Agent(但可額外購買Build Agent來增加限制數量)。一個Build Agent在同一時間只能處理一個Build Job,如果同時有多個Build Job需要處理而只有一個Build Job,就只能按照先後順序來處理。所以我們通常會安裝額外的Build Agent同時處理多個Build Job,例如目前我的團隊在執行的一個專案中便用了四個Build Agent。

安裝Build Agent可以透過手動或是自動安裝(實際上是半自動,梢後說明)的方式進行,不論哪種方式,都需先至Agents頁面,點選Install Build Agents安下載安裝檔

自動安裝需點選MS Windows Installer下載安裝檔(agentInstaller.exe)。




預設安裝好的第一個Build Agent路徑位於C:\TeamCity\buildAgent,所以如果安裝的是第二個Build Agent,建議安裝在C:\TeamCity\buildAgent2



接下來先暫停,我們需要先手動修改位於C:\TeamCity\buildAgent2\launcher\conf\wrapper.conf的設定檔。修改的部份為wrapper.ntservice.namewrapper.ntservice.displaynamewrapper.ntservice.description如下


接下來再回到安裝畫面修改serverUrlnameownPort。serverUrl為TeamCity的位址,name為Build Agent名稱,而ownPort為Build Agent所使用的連接埠,預設為9090,如果預設安裝好的Build Agent已使用這個port number,這邊就需要做修改。






安裝完成後稍等一下即可在Agents頁面看到第二個Build Agent。


March 7, 2016

Git Extensions not working in Visual Studio 2015

I'm not a fan of git command line so I use Git Extensions to conduct all the git operations as possible and I've been using it for 2 years. It's really a great tool. Recently I start using VS 2015 in one of my projects and after installation, I can't seem to find Git Extentions in the context menu or toolbar. It's just gone!

OK so I took a look at the official site and found it unsupported for VS 2015 and it's a known issue.

Luckily, there's a VS 2015 extension to this issue. After installing it, I see Git Extensions tool buttons appear in the toolbar. If you still can't see it, right click on the toolbar and see if it's unchecked.