|
| 1 | +# Setting up a new Crater Windows agent machine |
| 2 | + |
| 3 | +## Operating System |
| 4 | + |
| 5 | +The agent machine should run Windows Server build 1803 (Windows 10 build 1803 |
| 6 | +will **not** work, see below). The machine should have Hyper-V enabled (images |
| 7 | +ending in `v3` on Azure DevOps), although this may not be necessary since we |
| 8 | +only use process isolation. Testing has been done on a server with a GUI, but |
| 9 | +all installation steps can be done at the command line with the exception of |
| 10 | +configuring Docker Desktop. It may be possible to use a headless server if |
| 11 | +Docker is already properly configured. The following paragraphs contain the |
| 12 | +rationale for choosing this particular build of Windows. If this does not |
| 13 | +interest you, skip to the next section. |
| 14 | + |
| 15 | +Docker on Windows supports two different ways to run containers, process |
| 16 | +isolation and Hyper-V isolation. Hyper-V isolation is more secure and more |
| 17 | +flexible, but it is too slow for our purposes; it essentially spins up a VM for |
| 18 | +each container. In order to run process isolation, the build number of the |
| 19 | +agent machine and the docker image [need to match][ver-compat]. You can use |
| 20 | +`winver` to print the version of Windows from the command line. Windows Server |
| 21 | +2016 additionally requires that the **revision number** of the agent machine |
| 22 | +and container image match as well. VMs based on a particular revision of |
| 23 | +Windows can be hard to find, so we want to use a build later than Server 2016. |
| 24 | + |
| 25 | +The `rustops/crates-build-env-windows` image is built on Azure Pipelines CI |
| 26 | +infrastructure, which provides a Windows 1803 host with docker pre-installed |
| 27 | +(the latest Windows version available on AppVeyor is Server 2016). Therefore we |
| 28 | +use this same build of Windows to do `crater` runs. Note that process isolation |
| 29 | +is [disabled on Windows 10 prior to build 1809][win-10], so you **must** use |
| 30 | +Windows Server. Additionally, running containers on Windows 10 requires a |
| 31 | +Professional or Enterprise license. It's possible to run `crater` on other |
| 32 | +builds of Windows as long as you understand these constraints, but you'll need |
| 33 | +to build your own `crates-build-env-windows` image based on a compatible |
| 34 | +version, as the `rustops` one is based on Windows 1803. |
| 35 | + |
| 36 | +[ver-compat]: https://docs.microsoft.com/en-us/virtualization/windowscontainers/deploy-containers/version-compatibility |
| 37 | +[win-10]: https://docs.microsoft.com/en-us/virtualization/windowscontainers/about/faq#can-i-run-windows-containers-in-process-isolated-mode-on-windows-10-enterprise-or-professional |
| 38 | + |
| 39 | +## Install [**Docker Desktop for Windows**][docker-desktop] |
| 40 | + |
| 41 | +[docker-desktop]: https://hub.docker.com/editions/community/docker-ce-desktop-windows |
| 42 | + |
| 43 | +- Download and run the [**Docker Desktop for Windows**][docker-desktop] installer (*not* Docker Toolbox): |
| 44 | + ```powershell |
| 45 | + (New-Object System.Net.WebClient).DownloadFile("https://download.docker.com/win/stable/Docker%20for%20Windows%20Installer.exe", ".\DockerInstaller.exe"); ` |
| 46 | + .\DockerInstaller.exe |
| 47 | + ``` |
| 48 | + |
| 49 | +- Check "Use Windows containers instead of Linux containers" during |
| 50 | + installation. Once installed, double check that Windows containers are indeed |
| 51 | + enabled by right-clicking the Docker icon in the dock. |
| 52 | + |
| 53 | +- Docker will then detect whether the "Containerization" and "Hyper-V" OS |
| 54 | + features are enabled. If they are disabled, Docker will try to enable them |
| 55 | + for you. Alternatively, run the following commands and then reboot. |
| 56 | + |
| 57 | + ```powershell |
| 58 | + Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Hyper-V -All |
| 59 | + Enable-WindowsOptionalFeature -Online -FeatureName Containers -All |
| 60 | + ``` |
| 61 | + |
| 62 | +## Install [`chocolatey`][] and `git` |
| 63 | + |
| 64 | +[`chocolatey`]: https://chocolatey.org/install |
| 65 | + |
| 66 | +Chocolately is a 3rd-party package manager for Windows. We'll use it to install a |
| 67 | +version of `git` which can be used directly from `PowerShell`, as well as some |
| 68 | +other useful things: |
| 69 | + |
| 70 | +```Powershell |
| 71 | +Set-ExecutionPolicy Bypass -Scope Process -Force; iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1')) |
| 72 | +``` |
| 73 | +Then we can install `git`: |
| 74 | + |
| 75 | +```Powershell |
| 76 | +choco install git |
| 77 | +``` |
| 78 | + |
| 79 | +## Install the Visual Studio VC++ tools |
| 80 | + |
| 81 | +We could use the commands from the Dockerfile, but since we already installed `chocolatey`: |
| 82 | + |
| 83 | +```powershell |
| 84 | +choco install -y visualstudio2017-workload-vctools |
| 85 | +``` |
| 86 | + |
| 87 | +## Install rust locally |
| 88 | + |
| 89 | +Follow the normal procedure, but note that `rustup-init.exe` cannot be |
| 90 | +[downloaded from the command line using normal Windows |
| 91 | +utilities][rustup-download]. Instead, use `curl.exe` (the suffix is important), |
| 92 | +which is installed by default on newer versions of Windows or available via |
| 93 | +`chocolately`: |
| 94 | + |
| 95 | +```powershell |
| 96 | +curl.exe -o rustup-init.exe https://win.rustup.rs/x86_64 |
| 97 | +.\rustup-init.exe |
| 98 | +``` |
| 99 | + |
| 100 | +[rustup-download]: https://github.com/rust-lang/rustup.rs/issues/829 |
| 101 | +["Trusted Sites"]: https://www.itg.ias.edu/content/how-add-trusted-sites-internet-explorer |
| 102 | + |
| 103 | +Disabling "Real-time Protection" in "Settings > Update & Security > Windows |
| 104 | +Defender" may speed up [the installation of `rust-docs`][rust-docs]. |
| 105 | + |
| 106 | +[rust-docs]: https://github.com/rust-lang/rustup.rs/issues/1540 |
| 107 | + |
| 108 | +## Build crater |
| 109 | + |
| 110 | +The next step is to download and build `crater` just like on a [Linux |
| 111 | +agent](./agent-machine-setup.md): |
| 112 | + |
| 113 | +```powershell |
| 114 | +git clone https://github.com/rust-lang-nursery/crater |
| 115 | +cd crater |
| 116 | +cargo build --release |
| 117 | +
|
| 118 | +# This is going to take a while to complete |
| 119 | +cargo run --release -- prepare-local |
| 120 | +``` |
| 121 | + |
| 122 | +Running `minicrater` tests require that the `*.expected.json` files match the |
| 123 | +output of crater exactly. However, when installed via `chocolately`, `git` has |
| 124 | +config `core.autocrlf` set to `true` by default. This will override the |
| 125 | +preferences in `crater`'s `.gitattributes` file and cause the JSON files to |
| 126 | +have the wrong line endings (CRLF). Make sure you set `core.autocrlf = false` |
| 127 | +before cloning the repo. |
| 128 | + |
| 129 | +If you've already cloned the repo, simply run the following from inside of it |
| 130 | +to replace the JSON files: |
| 131 | + |
| 132 | +```powershell |
| 133 | +git config core.autocrlf false |
| 134 | +rm -r tests/ |
| 135 | +git checkout -- tests/ |
| 136 | +``` |
| 137 | + |
| 138 | +Remember to run `cargo run -- create-lists` before running the tests. |
0 commit comments