Disclaimer: I know that it would be better to put Jenkins, and the approach to the realization of some things is far from the best. But the point is to create a CI with an API, with all your decision and as quickly as possible. I will be glad to advice and any criticism.
We only have GNU / Linux server available and access via ssh. The goal is a virtual machine with Windows and the ability to make builds and use all Unity3D functionality from the command line.
We will install and will use:
Let's start with installing Xfce and VNC server. Xfce is a graphical shell that will significantly simplify life and routine with the future virtual machine, because for some reason I could not do an adequate RDP, and the crutches with TeamViewer did not suit me. For example, take Ubuntu and do the following:
sudo apt-get update sudo apt-get -y upgrade apt-get install xfce4 xfce4-goodies gnome-icon-theme tightvncserver
We answer all questions and after installing all this we create a user for our remote desktop on the server:
sudo adducer remoteUser
Enter the password and optionally house information about the user, or simply skip it. Next, if necessary, install sudo:
sudo apt-get install sudo
And we add our user to the root group:
sudo gpasswd -a remoteUser sudo
If you are straining to enter sudo before each command, you can log in as root:
sudo -s
After the works of all the manipulations above, we already have a user on whose behalf we will create our virtual machine, since I wanted to be able to create builds from the browser, I also installed apache2 and php:
sudo apt-get -y apache2 install php5 libapache2-mod-php5 php5-cli
Next, we go in the name of the user we just created:
sudo su - inc
Now we can start our vnc server, for convenience, I will start it with the resolution of my screen:
sudo vncserver -geometry 1280x800
If you are unable to log into your remote desktop, I advise you also to open the port for the outgoing connection, it happens that by default the port is closed:
sudo iptables -A INPUT -p tcp --dport 5901 -j ACCEPT
Well, while we are in the console, it would be cool to install VirtualBox, otherwise there will be nothing to run the virtual machine on:
sudo apt-get install virtualbox
I use Mac and I have a screenshare.app to enter a server, for other systems TightVNC should be suitable.
Now we have everything that we need to work with a virtual machine - a disk image with Windows installed, for informational purposes, I advise you to download it after downloading, import * ova-file, if errors occur during import, just open the ova file as an archive and remove vmdk, ovf - just a config, we will not need it, then create a virtual machine and hook on the existing hard disk.
After performing the above described actions, we will be able to turn on our virtual machine and install everything you need there: Unity, your favorite tool for working with git, etc.
Important note, Unity can work ONLY in headless mode without using a graphics device, I could not solve the problem with the drivers for Intel HD video cards, respectively, I was left without 3D acceleration, good, everything works without it.
Important point, if you want to call Unity functionality via php just like you, you will need to set the ability to execute commands without asking for a password, via visudo, for the user on whose behalf the php script is running, I have www-data - the standard user , I also immediately did all the bash scripts and php on behalf of this user, if you are not strong in configuring via the terminal, everything can be easily configured in the interface, an example visudo:
www-data ALL=NOPASSWD: ALL
How to call visudo:
sudo visudo
I agree that this is not the best approach, because we essentially allow php to do whatever it wants, but in my case it didn’t really bother anyone, the server was isolated.
Well and on snack, how to cause bild for Unity:
sudo vboxmanage guestcontrol "Windows" execute --username IEUser --password Passw0rd! --image "C:\CI\build.bat" --verbose -- "${1}"
verbose - output the response of the guest machine console
"$ {1}" is the parameter that is responsible for the platform (buildWindowsPlayer)
PHP script which causes all this indecency:
$platform = $_GET["platform"]; $shell = "sh build.sh $platform 2>&1"; $out = shell_exec($shell); echo $out;
2> & 1 - this helps a lot when debugging, as it displays errors and allows you to see the output of the script
build.bat also looks very simple:
C:\PROGRA~1\Unity\Editor\Unity.exe -batchmode -projectPath "%PROJECTPATH%" -%1 %buildPath% -quit -nographics C:\7z.exe a %buildPath% %sharedFolderPath%\build.zip
% 1 is a build directive for the platform (buildWindowsPlayer).
All features and manipulations that can be made are here.
The author of this article is not so strong in the Nix, and if I made a mistake I will be glad to correct it. More details about configuring vnc here .
As a conclusion, I will only say that of course this method is suitable for learning how everything interacts and is designed for those who have a server on GNU / Linux and a project on Unity, but there is no time to figure it out. Also answering the question why I use such a number of scripts for such simple operations: in my case, batch files are responsible for post-processing and deploying to shared directories, batch files for calling all the necessary functionality, and php is only a tool to call all of this from a browser, if there are suggestions how to do this more efficiently without loss of clarity, I will be glad to make comments, since I myself think how to minimize all this without turning it into something unsupported.
PS: I am now doing a small tool for myself so that it all works from one script and you can put all the functions on one page and use them, if you want, I can share my work on Github.
PS 2: There is also an option to fill in an already configured vmdk disk with everything you need, but to be honest, it was easier for me, well, and it was quite fun to watch the rest.
PS 3: Don't forget to activate the license for your copy of Windows.
Source: https://habr.com/ru/post/279023/
All Articles