Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add steps for provisioning a Windows box to run crater #423

Merged
merged 1 commit into from
Jul 21, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
138 changes: 138 additions & 0 deletions docs/agent-machine-setup-windows.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
# Setting up a new Crater Windows agent machine

## Operating System

The agent machine should run Windows Server build 1803 (Windows 10 build 1803
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's a good idea to mention up here that Windows 10 Build 1809 and above will work.

Copy link
Contributor Author

@ecstatic-morse ecstatic-morse Jul 22, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's now an officially published 1803 image that's hard-coded as the default, so I think the mention down below is sufficient. I meant for this paragraph to be the bare minimum of information for someone to get up and running with the stock set up, and if you wanna use 1809 you'll need to build your own docker image and pass it to crater.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe I need to add, "later versions of Windows will work, but you'll need to use a custom Docker image, see below".

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea that's enough.

will **not** work, see below). The machine should have Hyper-V enabled (images
ending in `v3` on Azure DevOps), although this may not be necessary since we
only use process isolation. Testing has been done on a server with a GUI, but
all installation steps can be done at the command line with the exception of
configuring Docker Desktop. It may be possible to use a headless server if
Docker is already properly configured. The following paragraphs contain the
rationale for choosing this particular build of Windows. If this does not
interest you, skip to the next section.

Docker on Windows supports two different ways to run containers, process
isolation and Hyper-V isolation. Hyper-V isolation is more secure and more
flexible, but it is too slow for our purposes; it essentially spins up a VM for
each container. In order to run process isolation, the build number of the
agent machine and the docker image [need to match][ver-compat]. You can use
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you want to say "for example, if you're using Build 1803, you can find the image here"

Copy link
Contributor Author

@ecstatic-morse ecstatic-morse Jul 22, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I'll add a link to the official image. As well as instructions for building a custom one.

`winver` to print the version of Windows from the command line. Windows Server
2016 additionally requires that the **revision number** of the agent machine
and container image match as well. VMs based on a particular revision of
Windows can be hard to find, so we want to use a build later than Server 2016.

The `rustops/crates-build-env-windows` image is built on Azure Pipelines CI
infrastructure, which provides a Windows 1803 host with docker pre-installed
(the latest Windows version available on AppVeyor is Server 2016). Therefore we
use this same build of Windows to do `crater` runs. Note that process isolation
is [disabled on Windows 10 prior to build 1809][win-10], so you **must** use
Windows Server. Additionally, running containers on Windows 10 requires a
Professional or Enterprise license. It's possible to run `crater` on other
builds of Windows as long as you understand these constraints, but you'll need
to build your own `crates-build-env-windows` image based on a compatible
version, as the `rustops` one is based on Windows 1803.

[ver-compat]: https://docs.microsoft.com/en-us/virtualization/windowscontainers/deploy-containers/version-compatibility
[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

## Install [**Docker Desktop for Windows**][docker-desktop]

[docker-desktop]: https://hub.docker.com/editions/community/docker-ce-desktop-windows

- Download and run the [**Docker Desktop for Windows**][docker-desktop] installer (*not* Docker Toolbox):
```powershell
(New-Object System.Net.WebClient).DownloadFile("https://download.docker.com/win/stable/Docker%20for%20Windows%20Installer.exe", ".\DockerInstaller.exe"); `
.\DockerInstaller.exe
```

- Check "Use Windows containers instead of Linux containers" during
installation. Once installed, double check that Windows containers are indeed
enabled by right-clicking the Docker icon in the dock.

- Docker will then detect whether the "Containerization" and "Hyper-V" OS
features are enabled. If they are disabled, Docker will try to enable them
for you. Alternatively, run the following commands and then reboot.

```powershell
Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Hyper-V -All
Enable-WindowsOptionalFeature -Online -FeatureName Containers -All
```

## Install [`chocolatey`][] and `git`

[`chocolatey`]: https://chocolatey.org/install

Chocolately is a 3rd-party package manager for Windows. We'll use it to install a
version of `git` which can be used directly from `PowerShell`, as well as some
other useful things:

```Powershell
Set-ExecutionPolicy Bypass -Scope Process -Force; iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))
```
Then we can install `git`:

```Powershell
choco install git
```

## Install the Visual Studio VC++ tools

We could use the commands from the Dockerfile, but since we already installed `chocolatey`:

```powershell
choco install -y visualstudio2017-workload-vctools
```

## Install rust locally

Follow the normal procedure, but note that `rustup-init.exe` cannot be
[downloaded from the command line using normal Windows
utilities][rustup-download]. Instead, use `curl.exe` (the suffix is important),
which is installed by default on newer versions of Windows or available via
`chocolately`:

```powershell
curl.exe -o rustup-init.exe https://win.rustup.rs/x86_64
.\rustup-init.exe
```

[rustup-download]: https://github.com/rust-lang/rustup.rs/issues/829
["Trusted Sites"]: https://www.itg.ias.edu/content/how-add-trusted-sites-internet-explorer

Disabling "Real-time Protection" in "Settings > Update & Security > Windows
Defender" may speed up [the installation of `rust-docs`][rust-docs].

[rust-docs]: https://github.com/rust-lang/rustup.rs/issues/1540

## Build crater

The next step is to download and build `crater` just like on a [Linux
agent](./agent-machine-setup.md):

```powershell
git clone https://github.com/rust-lang-nursery/crater
cd crater
cargo build --release

# This is going to take a while to complete
cargo run --release -- prepare-local
```

Running `minicrater` tests require that the `*.expected.json` files match the
output of crater exactly. However, when installed via `chocolately`, `git` has
config `core.autocrlf` set to `true` by default. This will override the
preferences in `crater`'s `.gitattributes` file and cause the JSON files to
have the wrong line endings (CRLF). Make sure you set `core.autocrlf = false`
before cloning the repo.

If you've already cloned the repo, simply run the following from inside of it
to replace the JSON files:

```powershell
git config core.autocrlf false
rm -r tests/
git checkout -- tests/
```

Remember to run `cargo run -- create-lists` before running the tests.