Skip to content

Commit 55060eb

Browse files
authored
Split Codespaces configuration based on development scenarios (dotnet#74683)
* Split libraries and wasm devcontainers Codespaces allows for monorepo support now. So we can have different pre-builds for different dev environments. Creating a "libraries" pre-build and a "wasm" pre-build devcontainer. * Move devcontainer files into separate folders * Path up a directory to the Dockerfile * Split the Dockerfile so it can be customized per devcontainer * Update Codespaces docs * Respond to PR feedback * Use the new open devcontainers path. * Use the GH CLI feature instead of installing it ourselves * Set hostRequirements for Codespaces Developing in dotnet/runtime with a 2-core / 4GB ram machine doesn't work very well. Add a minimum of 4-core machine to the devcontainer spec. Fix dotnet#75680
1 parent bff967b commit 55060eb

File tree

7 files changed

+174
-54
lines changed

7 files changed

+174
-54
lines changed

.devcontainer/libraries/Dockerfile

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# See here for image contents: https://github.com/microsoft/vscode-dev-containers/tree/v0.192.0/containers/dotnet/.devcontainer/base.Dockerfile
2+
# For details on dotnet specific container, see: https://github.com/microsoft/vscode-dev-containers/tree/main/containers/dotnet
3+
4+
# [Choice] .NET version: 6.0, 3.1
5+
ARG VARIANT="6.0-focal"
6+
FROM mcr.microsoft.com/devcontainers/dotnet:0-${VARIANT}
7+
8+
# Set up machine requirements to build the repo and the gh CLI
9+
RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
10+
&& apt-get -y install --no-install-recommends \
11+
cmake \
12+
llvm-10 \
13+
clang-10 \
14+
build-essential \
15+
python \
16+
curl \
17+
git \
18+
lldb-6.0 \
19+
liblldb-6.0-dev \
20+
libunwind8 \
21+
libunwind8-dev \
22+
gettext \
23+
libicu-dev \
24+
liblttng-ust-dev \
25+
libssl-dev \
26+
libnuma-dev \
27+
libkrb5-dev \
28+
zlib1g-dev \
29+
ninja-build
+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
// For format details, see https://aka.ms/devcontainer.json.
2+
{
3+
"name": "C# (.NET)",
4+
"build": {
5+
"dockerfile": "Dockerfile",
6+
"args": {
7+
// Update 'VARIANT' to pick a .NET Core version: 3.1, 6.0
8+
// Append -bullseye or -focal to pin to an OS version.
9+
"VARIANT": "6.0-focal"
10+
}
11+
},
12+
"hostRequirements": {
13+
"cpus": 4,
14+
"memory": "8gb"
15+
},
16+
17+
"features": {
18+
"ghcr.io/devcontainers/features/github-cli:1": {}
19+
},
20+
21+
// Configure tool-specific properties.
22+
"customizations": {
23+
// Configure properties specific to VS Code.
24+
"vscode": {
25+
// Add the IDs of extensions you want installed when the container is created.
26+
"extensions": [
27+
"ms-dotnettools.csharp"
28+
],
29+
"settings": {
30+
// Loading projects on demand is better for larger codebases
31+
"omnisharp.enableMsBuildLoadProjectsOnDemand": true,
32+
"omnisharp.enableRoslynAnalyzers": true,
33+
"omnisharp.enableEditorConfigSupport": true,
34+
"omnisharp.enableAsyncCompletion": true,
35+
"omnisharp.testRunSettings": "${containerWorkspaceFolder}/artifacts/obj/vscode/.runsettings"
36+
}
37+
}
38+
},
39+
40+
// Use 'onCreateCommand' to run pre-build commands inside the codespace
41+
"onCreateCommand": "${containerWorkspaceFolder}/.devcontainer/scripts/onCreateCommand.sh libraries",
42+
43+
// Use 'postCreateCommand' to run commands after the container is created.
44+
"postCreateCommand": "${containerWorkspaceFolder}/.devcontainer/scripts/postCreateCommand.sh",
45+
46+
// Add the locally installed dotnet to the path to ensure that it is activated
47+
// This allows developers to just use 'dotnet build' on the command-line, and the local dotnet version will be used.
48+
"remoteEnv": {
49+
"PATH": "${containerWorkspaceFolder}/.dotnet:${containerEnv:PATH}",
50+
"DOTNET_MULTILEVEL_LOOKUP": "0"
51+
},
52+
53+
// Comment out connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root.
54+
"remoteUser": "vscode"
55+
}

.devcontainer/scripts/onCreateCommand.sh

+18-10
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,26 @@
22

33
set -e
44

5-
# prebuild the repo, so it is ready for development
6-
./build.sh libs+clr -rc Release
7-
# restore libs tests so that the project is ready to be loaded by OmniSharp
8-
./build.sh libs.tests -restore
5+
opt=$1
6+
case "$opt" in
97

10-
# prebuild for WASM, so it is ready for wasm development
11-
make -C src/mono/wasm provision-wasm
12-
export EMSDK_PATH=$PWD/src/mono/wasm/emsdk
13-
./build.sh mono+libs -os Browser -c release
8+
libraries)
9+
# prebuild the repo, so it is ready for development
10+
./build.sh libs+clr -rc Release
11+
# restore libs tests so that the project is ready to be loaded by OmniSharp
12+
./build.sh libs.tests -restore
13+
;;
1414

15-
# install dotnet-serve for running wasm samples
16-
./dotnet.sh tool install dotnet-serve --tool-path ./.dotnet-tools-global
15+
wasm)
16+
# prebuild for WASM, so it is ready for wasm development
17+
make -C src/mono/wasm provision-wasm
18+
export EMSDK_PATH=$PWD/src/mono/wasm/emsdk
19+
./build.sh mono+libs -os Browser -c Release
20+
21+
# install dotnet-serve for running wasm samples
22+
./dotnet.sh tool install dotnet-serve --tool-path ./.dotnet-tools-global
23+
;;
24+
esac
1725

1826
# save the commit hash of the currently built assemblies, so developers know which version was built
1927
git rev-parse HEAD > ./artifacts/prebuild.sha

.devcontainer/Dockerfile renamed to .devcontainer/wasm/Dockerfile

+22-12
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,32 @@
11
# See here for image contents: https://github.com/microsoft/vscode-dev-containers/tree/v0.192.0/containers/dotnet/.devcontainer/base.Dockerfile
22
# For details on dotnet specific container, see: https://github.com/microsoft/vscode-dev-containers/tree/main/containers/dotnet
33

4-
# [Choice] .NET version: 6.0, 5.0, 3.1, 2.1
4+
# [Choice] .NET version: 6.0, 3.1
55
ARG VARIANT="6.0-focal"
6-
FROM mcr.microsoft.com/vscode/devcontainers/dotnet:0-${VARIANT}
7-
8-
# Setup the gh (GitHub) CLI signing key.
9-
RUN curl -fsSL https://cli.github.com/packages/githubcli-archive-keyring.gpg | dd of=/usr/share/keyrings/githubcli-archive-keyring.gpg && \
10-
chmod go+r /usr/share/keyrings/githubcli-archive-keyring.gpg && \
11-
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" | tee /etc/apt/sources.list.d/github-cli.list > /dev/null
6+
FROM mcr.microsoft.com/devcontainers/dotnet:0-${VARIANT}
127

138
# Set up machine requirements to build the repo and the gh CLI
149
RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
15-
&& apt-get -y install --no-install-recommends cmake llvm-10 clang-10 \
16-
build-essential python curl git lldb-6.0 liblldb-6.0-dev \
17-
libunwind8 libunwind8-dev gettext libicu-dev liblttng-ust-dev \
18-
libssl-dev libnuma-dev libkrb5-dev zlib1g-dev ninja-build \
19-
gh
10+
&& apt-get -y install --no-install-recommends \
11+
cmake \
12+
llvm-10 \
13+
clang-10 \
14+
build-essential \
15+
python \
16+
curl \
17+
git \
18+
lldb-6.0 \
19+
liblldb-6.0-dev \
20+
libunwind8 \
21+
libunwind8-dev \
22+
gettext \
23+
libicu-dev \
24+
liblttng-ust-dev \
25+
libssl-dev \
26+
libnuma-dev \
27+
libkrb5-dev \
28+
zlib1g-dev \
29+
ninja-build
2030

2131
# Install V8 Engine
2232
SHELL ["/bin/bash", "-c"]

.devcontainer/devcontainer.json renamed to .devcontainer/wasm/devcontainer.json

+29-16
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,44 @@
1-
// For format details, see https://aka.ms/devcontainer.json. For config options, see the README at:
2-
// https://github.com/microsoft/vscode-dev-containers/tree/v0.192.0/containers/dotnet
1+
// For format details, see https://aka.ms/devcontainer.json.
32
{
43
"name": "C# (.NET)",
54
"build": {
65
"dockerfile": "Dockerfile",
76
"args": {
8-
// Update 'VARIANT' to pick a .NET Core version: 2.1, 3.1, 5.0
9-
"VARIANT": "5.0",
7+
// Update 'VARIANT' to pick a .NET Core version: 3.1, 6.0
8+
// Append -bullseye or -focal to pin to an OS version.
9+
"VARIANT": "6.0-focal"
1010
}
1111
},
12+
"hostRequirements": {
13+
"cpus": 4,
14+
"memory": "8gb"
15+
},
1216

13-
"settings": {
14-
// Loading projects on demand is better for larger codebases
15-
"omnisharp.enableMsBuildLoadProjectsOnDemand": true,
16-
"omnisharp.enableRoslynAnalyzers": true,
17-
"omnisharp.enableEditorConfigSupport": true,
18-
"omnisharp.enableAsyncCompletion": true,
19-
"omnisharp.testRunSettings": "${containerWorkspaceFolder}/artifacts/obj/vscode/.runsettings"
17+
"features": {
18+
"ghcr.io/devcontainers/features/github-cli:1": {}
2019
},
2120

22-
// Add the IDs of extensions you want installed when the container is created.
23-
"extensions": [
24-
"ms-dotnettools.csharp"
25-
],
21+
// Configure tool-specific properties.
22+
"customizations": {
23+
// Configure properties specific to VS Code.
24+
"vscode": {
25+
// Add the IDs of extensions you want installed when the container is created.
26+
"extensions": [
27+
"ms-dotnettools.csharp"
28+
],
29+
"settings": {
30+
// Loading projects on demand is better for larger codebases
31+
"omnisharp.enableMsBuildLoadProjectsOnDemand": true,
32+
"omnisharp.enableRoslynAnalyzers": true,
33+
"omnisharp.enableEditorConfigSupport": true,
34+
"omnisharp.enableAsyncCompletion": true,
35+
"omnisharp.testRunSettings": "${containerWorkspaceFolder}/artifacts/obj/vscode/.runsettings"
36+
}
37+
}
38+
},
2639

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

3043
// Use 'postCreateCommand' to run commands after the container is created.
3144
"postCreateCommand": "${containerWorkspaceFolder}/.devcontainer/scripts/postCreateCommand.sh",

docs/workflow/Codespaces.md

+21-16
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,20 @@ dotnet/runtime runs a nightly GitHub Action to build the latest code in the repo
77

88
1. From https://github.com/dotnet/runtime, drop-down the `Code` button and select the `Codespaces` tab.
99

10-
![New codespace button](https://docs.github.com/assets/images/help/codespaces/new-codespace-button.png)
10+
![New codespace button](https://docs.github.com/assets/cb-138303/images/help/codespaces/new-codespace-button.png)
1111

12-
2. Select the Machine type. For dotnet/runtime, it is recommended to select at least a `4-core` machine. You can also verify that a "Prebuild" is ready.
12+
2. Click the drop-down at the side of the `Create codespace on main` button and select `Configure and create codespace`
13+
14+
![Configure and create codespace](https://docs.github.com/assets/cb-49317/images/help/codespaces/default-machine-type.png)
15+
16+
3. Select which Dev container configuration you want to use.
17+
18+
![Dev container configuration](./codespace-dev-container-configuration.png)
19+
20+
- For `libraries` work, pick `.devcontainer/libraries/devcontainer.json`.
21+
- For `WASM` work, pick `.devcontainer/wasm/devcontainer.json`.
22+
23+
4. Select the Machine type. For `dotnet/runtime`, it is recommended to select at least a `4-core` machine. You can also verify that a `Prebuild` is ready.
1324

1425
![Codespace machine size](./codespace-machine-size.png)
1526

@@ -20,21 +31,15 @@ dotnet/runtime runs a nightly GitHub Action to build the latest code in the repo
2031

2132
The Codespaces configuration is spread across the following places:
2233

23-
1. The [.devcontainer](../../.devcontainer) folder contains:
24-
- `devcontainer.json` file configures the codespace and mostly has VS Code settings
25-
- The Dockerfile used to create the image
34+
1. The [.devcontainer](../../.devcontainer) folder contains folders for each "development scenario":
35+
- `libraries` - Used by developers working in `src/libraries`
36+
- `wasm` - Used by developers working on the browser-wasm workload
2637
- The `scripts` folder contains any scripts that are executed during the creation of the codespace. This has the build command that builds the entire repo for prebuilds.
27-
2. The GitHub Action can be configured by following the instructions at https://docs.github.com/codespaces/prebuilding-your-codespaces/configuring-prebuilds.
38+
2. Each development scenario folder contains:
39+
- `devcontainer.json` file configures the codespace and has VS Code / Environment settings
40+
- The Dockerfile used to create the Docker image
41+
3. The GitHub Action can be configured by following the instructions at https://docs.github.com/codespaces/prebuilding-your-codespaces/configuring-prebuilds.
2842

2943
To test out changes to the `.devcontainer` files, you can follow the process in [Applying changes to your configuration](https://docs.github.com/codespaces/customizing-your-codespace/configuring-codespaces-for-your-project#applying-changes-to-your-configuration) docs. This allows you to rebuild the Codespace privately before creating a PR.
3044

31-
To test out your `.yml` changes, here is the process:
32-
33-
**Note**: *Executing these steps will overwrite the current prebuilt container for the entire repo. Afterwards, anyone creating a new codespace will get a prebuilt machine with your test changes until the Action in `main` is executed again.*
34-
35-
1. Edit and commit the files to a branch.
36-
2. Push that to a branch on dotnet/runtime. Be careful that you aren't pushing to `main` or some other important branch. Prefix your branch name with your GitHub account name, so others know it is a dev branch. ex. `username/FixCodespaces`.
37-
3. In the "Actions" tab at the top of dotnet/runtime:
38-
- Select "Create Codespaces Prebuild" action on the left
39-
- On the right click "Run workflow" and pick your branch
40-
- After it runs, try to create a codespace
45+
To test out your changes you can run the [Codespaces Prebuilds Action](https://github.com/dotnet/runtime/actions/workflows/codespaces/create_codespaces_prebuilds) in your fork against a branch with your changes.
Loading

0 commit comments

Comments
 (0)