TotalCloud BuildBot: A Cost-Efficient & Rapid Unity Build Pipeline Open Source Tool (Part 1)

Written by Totalcloudio | Published 2018/03/15
Tech Story Tags: aws | unity-build | build-pipeline | open-source | jenkins

TLDRvia the TL;DR App

Generating Unity builds continuously, for game development, using personal computers is no fun-game. Manually generating them is much more vexing because each build takes a lot of time to configure and compile. Moreover, these builds are slow on personal computers due to high memory utilization and are prone to frequent human errors.

Automating build pipeline and offloading them from the developer machines into the “cloud” or using build platforms like Travis CI or CircleCI seems plausible. However, due to higher costs, developers are coerced to take an alternative route.

Here’s our story of why we built BuildBot, the open source build pipeline tool for Unity builds.

The Analysis of Time and Cost of Unity Builds

We, at TotalCloud.io, have been leveraging the Unity3D platform to build our immersive visual cloud management platform since inception. Without a doubt, Unity3D is a wonderful multi-platform game engine, be it for game development or non-game interactive simulations and visualizations.

However, it has been quite a challenge for us to tackle the high time-to-build on Unity 3D. Sometimes, the time taken to generate one build was close to an hour. At times, we push close to 10 builds per day! Now, imagine the insane amount of time we spent just on generating the builds. We wanted our developers to see changes in the builds as soon as possible, without waiting for hours.

To top it, as the time-to-build increased, so did the cost. We were in dire need of a solution that could automate builds in a very short span of time without using costly build platforms.

Just like us, one of the significant factors that keep indie game developers and small studios away from build platforms or CI solutions is the cost incurred to generate builds of a game. Unlike big game studios who might leverage on-prem build servers or CI servers to continuously generate their builds, these indie developers or small teams do not have that kind of money to splurge on hardware and other build platforms.

So, if a game developer generates 10 builds per day, the total cost incurred per month will run into hundreds of dollars, which is heavy on the pocket.

Apart from the cost and time factor, there are other drawbacks of manually generating the Unity builds, such as:

  • Inability to handle complex build pipeline
  • Provides less control over the environment
  • Makes code signing difficult
  • Decreases collaboration in a team

All these factors lead us to build TotalCloud BuildBot, the open source build pipeline tool for Unity builds.

Now let’s dive deeper into cost per build.

The Cost Per Build Comparison: CircleCI Vs. Unity Cloud Vs. AWS

Let’s assume you generate ten builds per day, with the ability to do three builds in parallel. This accounts for approximately 300 builds per month. If each build took close to 30 minutes, then you will consume ~9000 minutes of build time per month. Now let’s make a quick cost comparison between different build platforms:

  • With CircleCI, it would cost anywhere between ~$249 USD to ~$449 USD per month
  • With Unity Cloud Build, it would cost ~$125 USD per month for the Pro Licence + few dollars for concurrent builds
  • With AWS, it would cost anywhere between ~$6 USD to $7 USD per month if you use EC2 instance with Windows Base AMI and i3.large machine

This clearly shows that using AWS is one of the most cost effective solutions.

Hence, we leveraged AWS and built the BuildBot, an open source on-demand build pipeline tool that allows an indie developer or small teams to generate hundreds of builds per month at a fraction of the cost compared to any other solution available in the market.

More on Why We Chose AWS Spot Instance with Windows AMI

The reason to go with EC2 spot instance with Windows Base AMI and i3.large machine instead of Mac OS is that generating Unity builds in Linux is very unreliable and doesn’t work most of the times, because of headless mode issues. On the other hand, AWS does not have Mac OS AMIs. This leaves us with Windows machines.

And, i3.large is a big machine with 15.25 GB memory, 475 SSD storage, high read write capacity and good CPU, which is enough to generate bigger builds. Plus, we are going to leverage NNVM SSD volumes to generate the builds faster instead of using the inbuilt EBS volumes.

Since a build machine needs to come up only when required, we are going to leverage AWS Spot instances to achieve cost savings. Because, i3.large spot instances cost ~$0.0468 USD per hour at 70% discounted rates. We can easily stop the machine when not in use and spin it up quickly when a new commit is available. We will talk more about it in our upcoming build pipeline post. For now, let’s walk you through the steps on generating Unity builds in AWS.

How to Generate Unity Builds in AWS

1. Launch and connect an EC2 Spot instances from the AWS console with Windows 2016 Base AMI and i3.large instance type. For developers who are new to AWS or want a quick walk through on how to launch an i3.large instance type from AWS console, click here.

2. Inside the Windows machine, launch the Powershell ISE from the Start menu. Create two files with the below Powershell scripts. The first script is to create an additional SSD volume that is required to generate builds; and the second script is to install Unity3D on to the Windows machine quickly.

Here’s the script to create the additional NNMV SSD volume. In the script we will name it ‘Jenkins Volume’ because it will be a part of our Jenkins Build Pipeline.

If (!(Test-Path D:)) {

Get-Disk | Where-Object IsOffline –Eq $True | Set-Disk –IsOffline $False

$newdisk = @(get-disk | Where-Object partitionstyle -eq ‘raw’)

$Labels = @(‘Jenkins’,’Other1',’Other2')

for($i = 0; $i -lt $newdisk.Count ; $i++)

{

$disknum = $newdisk[$i].Number

$dl = get-Disk $disknum |

Initialize-Disk -PartitionStyle GPT -PassThru |

New-Partition -AssignDriveLetter -UseMaximumSize

Format-Volume -driveletter $dl.Driveletter -FileSystem NTFS -NewFileSystemLabel $Labels[$i] -Confirm:$false

}

}

Here’s the script to install Unity3D engine.

P.S: Ensure you save this Powershell script in C drive.

$uri_editor = “https://download.unity3d.com/download_unity/a9f86dcd79df/Windows64EditorInstaller/UnitySetup64-2017.3.0f3.exe" ;

$uri_linux_support = “https://download.unity3d.com/download_unity/a9f86dcd79df/TargetSupportInstaller/UnitySetup-Linux-Support-for-Editor-2017.3.0f3.exe" ;

$uri_mac_support = “https://download.unity3d.com/download_unity/a9f86dcd79df/TargetSupportInstaller/UnitySetup-Mac-Support-for-Editor-2017.3.0f3.exe" ;

$out_editor = “C:\Users\Administrator\Documents\UnitySetup64.exe” ;

$out_linux_support = “C:\Users\Administrator\Documents\UnitySetup-Linux-Support.exe” ;

$out_mac_support = “C:\Users\Administrator\Documents\UnitySetup-Mac-Support.exe” ;

$start_time = Get-Date ;

$wc = New-Object System.Net.WebClient ;

$wc.DownloadFile($uri_editor, $out_editor) ;

Write-Output “Download complete, $out_editor > Time taken: $((Get-Date).Subtract($start_time).Seconds)s” ;

$wc.DownloadFile($uri_linux_support, $out_linux_support) ;

Write-Output “Download complete, $out_linux_support > Time taken: $((Get-Date).Subtract($start_time).Seconds)s” ;

$wc.DownloadFile($uri_mac_support, $out_mac_support) ;

Write-Output “Download complete, $out_mac_support > Time taken: $((Get-Date). Subtract($start_time).Seconds)s”;

3. Look for Unity setup in the Unity folder from C drive and install packages for Windows, Linux as well as MacOS.

4. Wait for Unity to setup.

5. Download your code from the Repo and look for the path of the project you want to compile the builds.

6. Create a BAT file to automatically store the builds as they are generated. Here’s an example of a BAT file. Make sure you add the right paths to the respective commands. Example: Use the project path URL you used to save the project in line 2 of the code (inside quotes).

C:\Development\Unity\Editor\Unity.exe -quit -batchmode -projectPath "D:\jenkins\workspace\unity-dev-build-4x"

-buildWindows64Player "D:\jenkins\workspace\unity-dev-build-4x\builds\win\64\TotalCloud.exe" -buildOSXUniversalPlayer "D:\jenkins\workspace\unity-dev-build-4x\builds\osx\64\TotalCloud.app" -buildLinux64Player "D:\jenkins\workspace\unity-dev-build-4x\builds\linux\64\TotalCloud.x86_64" -logFile "D:\jenkins\workspace\unity-dev-build-4x\logs\35.txt" || EXIT /B 1

7. Try generating a new build and check if the new build is available in the Output path and the log file in their designated paths.

Do try it out and share your experience.

This is Part 1 of the three-part series blog providing the stepping stone to using TotalCloud BuildBot. Stay tuned with us for our second blog, where we provide detailed information on how to go about the CI/CD pipeline using BuildBot.

Originally published at blog.totalcloud.io on March 14, 2018.


Published by HackerNoon on 2018/03/15