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 initial codespaces support for dotnet/runtime #59723

Merged
merged 2 commits into from
Sep 29, 2021
Merged
Show file tree
Hide file tree
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
12 changes: 12 additions & 0 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# See here for image contents: https://github.com/microsoft/vscode-dev-containers/tree/v0.192.0/containers/dotnet/.devcontainer/base.Dockerfile

# [Choice] .NET version: 5.0, 3.1, 2.1
ARG VARIANT="5.0"
FROM mcr.microsoft.com/vscode/devcontainers/dotnet:0-${VARIANT}

# Set up machine requirements to build the repo
RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
&& apt-get -y install --no-install-recommends cmake llvm-9 clang-9 \
build-essential python curl git lldb-6.0 liblldb-6.0-dev \
libunwind8 libunwind8-dev gettext libicu-dev liblttng-ust-dev \
libssl-dev libnuma-dev libkrb5-dev zlib1g-dev ninja-build
35 changes: 35 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// For format details, see https://aka.ms/devcontainer.json. For config options, see the README at:
// https://github.com/microsoft/vscode-dev-containers/tree/v0.192.0/containers/dotnet
{
"name": "C# (.NET)",
"build": {
"dockerfile": "Dockerfile",
"args": {
// Update 'VARIANT' to pick a .NET Core version: 2.1, 3.1, 5.0
"VARIANT": "5.0",
}
},

"settings": {
// Loading projects on demand is better for larger codebases
"omnisharp.enableMsBuildLoadProjectsOnDemand": true
},

// Add the IDs of extensions you want installed when the container is created.
"extensions": [
"ms-dotnettools.csharp"
],

// Use 'onCreateCommand' to run pre-build commands inside the codespace
"onCreateCommand": "${containerWorkspaceFolder}/.devcontainer/scripts/onCreateCommand.sh",

Copy link
Member

Choose a reason for hiding this comment

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

Would a "postStartCommand" allow us to do something useful? If we could write a welcome message to the user's terminal, we could help get them started by displaying some common build commands, a link to a doc, etc.

Copy link
Member

Choose a reason for hiding this comment

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

Maybe we could link to a doc and also run ./build.sh --help?

Copy link
Member Author

Choose a reason for hiding this comment

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

What build commands or docs do you think are useful here?

Looking around, I don't see others doing this. Maybe it is something we can enable after the initial work?

Copy link
Member Author

Choose a reason for hiding this comment

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

also run ./build.sh --help?

That output is way too verbose to be useful for a new contributor.

If anything here, I could imagine pointing to https://github.com/dotnet/runtime/blob/main/docs/workflow/README.md. Beyond that, I'm not sure of the value of dumping more things out.

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, I only found a few examples: https://grep.app/search?current=3&q=postStartCommand&filter[path][0]=.devcontainer/ and didn't spot any that were simply dumping help.

I had in mind just writing a few lines welcoming folks and pointing them to the readme, and saying to type "./build.sh --help"

yes, no need to do it now unless you feel like it. Just trying to think about how to smooth the path after the dev container starts and they're wondering what to do next. that is, if it even is visible in the terminal. I'm guessing it is.

// Add the locally installed dotnet to the path to ensure that it is activated
// This allows developers to just use 'dotnet build' on the command-line, and the local dotnet version will be used.
"remoteEnv": {
"PATH": "${containerWorkspaceFolder}/.dotnet:${containerEnv:PATH}",
eerhardt marked this conversation as resolved.
Show resolved Hide resolved
"DOTNET_MULTILEVEL_LOOKUP": "0"
},

// Comment out connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root.
"remoteUser": "vscode"
}
6 changes: 6 additions & 0 deletions .devcontainer/scripts/onCreateCommand.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/usr/bin/env bash

set -e

# prebuild the repo, so it is ready for development
./build.sh libs+clr -rc Release
Copy link
Member

Choose a reason for hiding this comment

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

@safern if we add +libs.pretest here, will that leave me in a state where I can walk up to any /tests folder and type dotnet build /t:build;test without any other prereqs?

If so it's probably worth adding as I'm assuming libs.pretest is fast.

Copy link
Member

Choose a reason for hiding this comment

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

@danmoseley libs.pretest is already part of the default subsets for libs, so no need to add it.

Copy link
Member

Choose a reason for hiding this comment

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

So I will be able to build and run an individual test library (it doesn't need libs.tests built?)

Copy link
Member

Choose a reason for hiding this comment

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

Correct with the given setup you will be able to run, dotnet build /t:test on a test project and it will work. libs.tests is not needed unless you want to run all tests or send to helix.

Copy link
Member

Choose a reason for hiding this comment

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

nit: you can also do just a dotnet test after a build.cmd/sh clr+libs, doesn't need to be dotnet build /t:test.

Copy link
Member

Choose a reason for hiding this comment

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

This command is very CLR/Libraries team specific. Would it make sense to build the entire repo instead of just those two subsets? (including host and packs)

Copy link
Member

Choose a reason for hiding this comment

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

Eric has a mail out asking whether there's a way to have multiple flavors of dev container.

Copy link
Member Author

Choose a reason for hiding this comment

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

We can always add more to the build in the future, if this turns out to be valuable to more people.

Copy link
Member

Choose a reason for hiding this comment

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

Sounds good. My hope is that in the future we can spend some time on optimizing the repo's root build (including all subsets but with just one selected runtime) which should make it a no-brainer to build the entire repo. More and more parts will be required over time anyway, i.e. we don't use the live built host today in libraries but we want to. Similar for other parts like the targeting pack produced in the "packs" subset.

/braindump end

17 changes: 17 additions & 0 deletions .github/workflows/create-codespaces-prebuild.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: Create Codespaces Prebuild
Copy link
Member

Choose a reason for hiding this comment

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

Whoa - is this what it looks like? Exciting!

We might later add more to the build (eg libs.tests) if we're typically picking up a cached image.

Copy link
Member

Choose a reason for hiding this comment

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

If the prebuild fails, how will we know?

Copy link
Member Author

Choose a reason for hiding this comment

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

is this what it looks like?

yes.

If the prebuild fails, how will we know?

It is a GitHub action. I would hope we can set up rules when it fails to notify someone.

Copy link
Member Author

Choose a reason for hiding this comment

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

on:
schedule:
# Run at 06:00 am UTC every day
- cron: '0 6 * * *'
workflow_dispatch:
jobs:
createPrebuild:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: github/codespaces-precache@v1.0.1
with:
regions: WestUs2
sku_name: standardLinux32gb
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Copy link
Member

Choose a reason for hiding this comment

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

What is this for? No token should be needed?

Copy link
Member Author

@eerhardt eerhardt Sep 29, 2021

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

Following that to https://docs.github.com/en/actions/security-guides/automatic-token-authentication#example-1-passing-the-github_token-as-an-input it suggests the default permissions are very broad and one can restrict eg

permissions:
  contents: read

But I don't grok how this relates to EXPERIMENTAL_CODESPACE_CACHE_TOKEN.

If you believe we're "doing it right" here then that's fine with me.

Copy link
Member Author

Choose a reason for hiding this comment

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

This is literally copied from the above doc (and I see the exact same in other repos).

https://github.com/github/codespaces-precache#standard-template

name: precache codespace
on:
  push:
    branches:
      - main
  workflow_dispatch:
jobs:
  createPrebuild:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - uses: github/codespaces-precache@v1.0.1
        with:
          regions: WestUs2
          sku_name: standardLinux32gb
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

https://github.com/microsoft/vscode/blob/main/.github/workflows/create-codespaces-prebuild.yml

https://github.com/rails/rails/blob/main/.github/workflows/codespaces.yml

1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,6 @@ Session.vim

# Visual Studio Code
.vscode/
.devcontainer/

# Private test configuration and binaries.
config.ps1
Expand Down