Skip to content

Commit 9c804e4

Browse files
authored
Better devcontainers (#280)
* Better fantomas on build * Better devcontainers
1 parent a717b3c commit 9c804e4

File tree

15 files changed

+258
-243
lines changed

15 files changed

+258
-243
lines changed

.devcontainer/Dockerfile

Lines changed: 10 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,17 @@
1-
FROM debian:buster-slim
2-
3-
4-
RUN apt-get update \
5-
&& apt-get install -y --no-install-recommends \
6-
ca-certificates \
7-
\
8-
# .NET Core dependencies
9-
libc6 \
10-
libgcc1 \
11-
libgssapi-krb5-2 \
12-
libicu63 \
13-
libssl1.1 \
14-
libstdc++6 \
15-
zlib1g \
16-
curl \
17-
git \
18-
procps \
19-
wget \
20-
&& rm -rf /var/lib/apt/lists/*
1+
# [Choice] Debian version (use bullseye on local arm64/Apple Silicon): bookworm, bullseye, buster
2+
ARG VARIANT="bookworm"
3+
FROM buildpack-deps:${VARIANT}-curl
214

225

236
ENV \
247
# Enable detection of running in a container
258
DOTNET_RUNNING_IN_CONTAINER=true \
26-
DOTNET_INSTALL_DIR=/usr/share/dotnet/ \
27-
DOTNET_ROOT=/usr/share/dotnet/
28-
29-
COPY ./.devcontainer/install-dotnets.sh global.json* .
30-
31-
RUN /bin/bash install-dotnets.sh
32-
33-
ENV PATH="$DOTNET_ROOT:${PATH}"
34-
RUN ln -s /usr/share/dotnet/dotnet /usr/bin/dotnet
9+
DOTNET_ROOT=/usr/share/dotnet/ \
10+
DOTNET_NOLOGO=true \
11+
DOTNET_CLI_TELEMETRY_OPTOUT=false\
12+
DOTNET_USE_POLLING_FILE_WATCHER=true
3513

36-
RUN dotnet --info
3714

38-
# Copy endpoint specific user settings into container to specify
39-
# .NET Core should be used as the runtime.
40-
COPY ./.devcontainer/settings.vscode.json /root/.vscode-remote/data/Machine/settings.json
15+
# [Optional] Uncomment this section to install additional OS packages.
16+
# RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
17+
# && apt-get -y install --no-install-recommends <your-package-list-here>

.devcontainer/devcontainer.json

Lines changed: 71 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,73 @@
11
{
2-
"name": "dotnet",
3-
// Set the build context one level higher so we can grab metadata like global.json
4-
"context": "..",
5-
"dockerFile": "Dockerfile",
6-
"forwardPorts": [
7-
0
8-
],
9-
"extensions": [
10-
"ionide.ionide-fsharp",
11-
"ms-dotnettools.csharp",
12-
"editorconfig.editorconfig",
13-
"ionide.ionide-paket",
14-
"ionide.ionide-fake"
15-
]
2+
"name": "dotnet",
3+
// Set the build context one level higher so we can grab metadata like global.json
4+
"context": "..",
5+
"dockerFile": "Dockerfile",
6+
"forwardPorts": [
7+
0
8+
],
9+
"features": {
10+
// https://github.com/devcontainers/features/blob/main/src/common-utils/README.md
11+
"ghcr.io/devcontainers/features/common-utils:2": {
12+
"installZsh": true,
13+
"installOhMyZshConfig": true,
14+
"configureZshAsDefaultShell": true,
15+
"username": "vscode",
16+
"userUid": "1000",
17+
"userGid": "1000",
18+
"upgradePackages": true
19+
},
20+
// https://github.com/devcontainers/features/blob/main/src/github-cli/README.md
21+
"ghcr.io/devcontainers/features/github-cli:1": {},
22+
// https://github.com/devcontainers-contrib/features/blob/main/src/starship/README.md
23+
"ghcr.io/devcontainers-contrib/features/starship:1": {},
24+
// https://github.com/devcontainers/features/blob/main/src/dotnet/README.md
25+
"ghcr.io/devcontainers/features/dotnet:2": {
26+
"version": "7.0",
27+
"additionalVersions": "6.0"
28+
}
29+
},
30+
"overrideFeatureInstallOrder": [
31+
"ghcr.io/devcontainers/features/common-utils",
32+
"ghcr.io/devcontainers/features/github-cli",
33+
"ghcr.io/devcontainers-contrib/features/starship",
34+
"ghcr.io/devcontainers/features/dotnet"
35+
],
36+
"customizations": {
37+
"vscode": {
38+
// Add the IDs of extensions you want installed when the container is created.
39+
"extensions": [
40+
"ms-dotnettools.csharp",
41+
"Ionide.Ionide-fsharp",
42+
"tintoy.msbuild-project-tools",
43+
"ionide.ionide-paket",
44+
"usernamehw.errorlens",
45+
"alefragnani.Bookmarks",
46+
"oderwat.indent-rainbow",
47+
"vscode-icons-team.vscode-icons",
48+
"EditorConfig.EditorConfig",
49+
"ms-azuretools.vscode-docker",
50+
"GitHub.vscode-pull-request-github",
51+
"github.vscode-github-actions"
52+
],
53+
"settings": {
54+
"terminal.integrated.defaultProfile.linux": "zsh",
55+
"csharp.suppressDotnetInstallWarning": true
56+
}
57+
}
58+
},
59+
"remoteUser": "vscode",
60+
"containerUser": "vscode",
61+
"containerEnv": {
62+
// Expose the local environment variable to the container
63+
// They are used for releasing and publishing from the container
64+
"GITHUB_TOKEN": "${localEnv:GITHUB_TOKEN}"
65+
},
66+
"onCreateCommand": {
67+
"enable-starship": "echo 'eval \"$(starship init zsh)\"' >> ~/.zshrc"
68+
},
69+
"postAttachCommand": {
70+
"restore": "dotnet tool restore && dotnet restore"
71+
},
72+
"waitFor": "updateContentCommand"
1673
}

.devcontainer/install-dotnets.sh

Lines changed: 0 additions & 23 deletions
This file was deleted.

.devcontainer/settings.vscode.json

Lines changed: 0 additions & 7 deletions
This file was deleted.
Lines changed: 10 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,17 @@
1-
FROM debian:buster-slim
2-
3-
4-
RUN apt-get update \
5-
&& apt-get install -y --no-install-recommends \
6-
ca-certificates \
7-
\
8-
# .NET Core dependencies
9-
libc6 \
10-
libgcc1 \
11-
libgssapi-krb5-2 \
12-
libicu63 \
13-
libssl1.1 \
14-
libstdc++6 \
15-
zlib1g \
16-
curl \
17-
git \
18-
procps \
19-
wget \
20-
&& rm -rf /var/lib/apt/lists/*
1+
# [Choice] Debian version (use bullseye on local arm64/Apple Silicon): bookworm, bullseye, buster
2+
ARG VARIANT="bookworm"
3+
FROM buildpack-deps:${VARIANT}-curl
214

225

236
ENV \
247
# Enable detection of running in a container
258
DOTNET_RUNNING_IN_CONTAINER=true \
26-
DOTNET_INSTALL_DIR=/usr/share/dotnet/ \
27-
DOTNET_ROOT=/usr/share/dotnet/
28-
29-
COPY ./.devcontainer/install-dotnets.sh global.json* ./
30-
31-
RUN /bin/bash install-dotnets.sh
32-
33-
ENV PATH="$DOTNET_ROOT:${PATH}"
34-
RUN ln -s /usr/share/dotnet/dotnet /usr/bin/dotnet
9+
DOTNET_ROOT=/usr/share/dotnet/ \
10+
DOTNET_NOLOGO=true \
11+
DOTNET_CLI_TELEMETRY_OPTOUT=false\
12+
DOTNET_USE_POLLING_FILE_WATCHER=true
3513

36-
RUN dotnet --info
3714

38-
# Copy endpoint specific user settings into container to specify
39-
# .NET Core should be used as the runtime.
40-
COPY ./.devcontainer/settings.vscode.json /root/.vscode-remote/data/Machine/settings.json
15+
# [Optional] Uncomment this section to install additional OS packages.
16+
# RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
17+
# && apt-get -y install --no-install-recommends <your-package-list-here>
Lines changed: 71 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,73 @@
11
{
2-
"name": "dotnet",
3-
// Set the build context one level higher so we can grab metadata like global.json
4-
"context": "..",
5-
"dockerFile": "Dockerfile",
6-
"forwardPorts": [
7-
0
8-
],
9-
"extensions": [
10-
"ionide.ionide-fsharp",
11-
"ms-dotnettools.csharp",
12-
"editorconfig.editorconfig",
13-
"ionide.ionide-paket",
14-
"ionide.ionide-fake"
15-
]
2+
"name": "dotnet",
3+
// Set the build context one level higher so we can grab metadata like global.json
4+
"context": "..",
5+
"dockerFile": "Dockerfile",
6+
"forwardPorts": [
7+
0
8+
],
9+
"features": {
10+
// https://github.com/devcontainers/features/blob/main/src/common-utils/README.md
11+
"ghcr.io/devcontainers/features/common-utils:2": {
12+
"installZsh": true,
13+
"installOhMyZshConfig": true,
14+
"configureZshAsDefaultShell": true,
15+
"username": "vscode",
16+
"userUid": "1000",
17+
"userGid": "1000",
18+
"upgradePackages": true
19+
},
20+
// https://github.com/devcontainers/features/blob/main/src/github-cli/README.md
21+
"ghcr.io/devcontainers/features/github-cli:1": {},
22+
// https://github.com/devcontainers-contrib/features/blob/main/src/starship/README.md
23+
"ghcr.io/devcontainers-contrib/features/starship:1": {},
24+
// https://github.com/devcontainers/features/blob/main/src/dotnet/README.md
25+
"ghcr.io/devcontainers/features/dotnet:2": {
26+
"version": "7.0",
27+
"additionalVersions": "6.0"
28+
}
29+
},
30+
"overrideFeatureInstallOrder": [
31+
"ghcr.io/devcontainers/features/common-utils",
32+
"ghcr.io/devcontainers/features/github-cli",
33+
"ghcr.io/devcontainers-contrib/features/starship",
34+
"ghcr.io/devcontainers/features/dotnet"
35+
],
36+
"customizations": {
37+
"vscode": {
38+
// Add the IDs of extensions you want installed when the container is created.
39+
"extensions": [
40+
"ms-dotnettools.csharp",
41+
"Ionide.Ionide-fsharp",
42+
"tintoy.msbuild-project-tools",
43+
"ionide.ionide-paket",
44+
"usernamehw.errorlens",
45+
"alefragnani.Bookmarks",
46+
"oderwat.indent-rainbow",
47+
"vscode-icons-team.vscode-icons",
48+
"EditorConfig.EditorConfig",
49+
"ms-azuretools.vscode-docker",
50+
"GitHub.vscode-pull-request-github",
51+
"github.vscode-github-actions"
52+
],
53+
"settings": {
54+
"terminal.integrated.defaultProfile.linux": "zsh",
55+
"csharp.suppressDotnetInstallWarning": true
56+
}
57+
}
58+
},
59+
"remoteUser": "vscode",
60+
"containerUser": "vscode",
61+
"containerEnv": {
62+
// Expose the local environment variable to the container
63+
// They are used for releasing and publishing from the container
64+
"GITHUB_TOKEN": "${localEnv:GITHUB_TOKEN}"
65+
},
66+
"onCreateCommand": {
67+
"enable-starship": "echo 'eval \"$(starship init zsh)\"' >> ~/.zshrc"
68+
},
69+
"postAttachCommand": {
70+
"restore": "dotnet tool restore && dotnet restore"
71+
},
72+
"waitFor": "updateContentCommand"
1673
}

Content/Console/.devcontainer/install-dotnets.sh

Lines changed: 0 additions & 23 deletions
This file was deleted.

Content/Console/.devcontainer/settings.vscode.json

Lines changed: 0 additions & 7 deletions
This file was deleted.

Content/Console/Directory.Build.targets

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ See https://learn.microsoft.com/en-us/visualstudio/msbuild/customize-by-director
77
<PropertyGroup>
88
<_BuildProjBaseIntermediateOutputPath>$(MSBuildThisFileDirectory)build/obj/</_BuildProjBaseIntermediateOutputPath>
99
<_DotnetToolManifestFile>$(MSBuildThisFileDirectory).config/dotnet-tools.json</_DotnetToolManifestFile>
10-
<_DotnetToolRestoreOutputFile>$(_BuildProjBaseIntermediateOutputPath)/dotnet-tool-restore-$(NETCoreSdkVersion)</_DotnetToolRestoreOutputFile>
11-
<_DotnetFantomasOutputFile>$(BaseIntermediateOutputPath)dotnet-fantomas-msbuild</_DotnetFantomasOutputFile>
10+
<_DotnetToolRestoreOutputFile>$(_BuildProjBaseIntermediateOutputPath)/dotnet-tool-restore-$(NETCoreSdkVersion)-$(OS)</_DotnetToolRestoreOutputFile>
11+
<_DotnetFantomasOutputFile>$(BaseIntermediateOutputPath)dotnet-fantomas-msbuild-$(NETCoreSdkVersion)-$(OS)</_DotnetFantomasOutputFile>
1212
</PropertyGroup>
1313

1414
<!-- Make sure that dotnet tools (including paket) are restored before restoring any project -->
@@ -19,8 +19,9 @@ See https://learn.microsoft.com/en-us/visualstudio/msbuild/customize-by-director
1919
</Target>
2020

2121
<!-- Make sure that files are formatted before building -->
22-
<Target Name="Format" BeforeTargets="BeforeBuild" Inputs="@(Compile)" Outputs="$(_DotnetFantomasOutputFile)" >
23-
<Exec Command="dotnet fantomas $(MSBuildProjectDirectory)" StandardOutputImportance="High" StandardErrorImportance="High" WorkingDirectory="$(MSBuildThisFileDirectory)" />
22+
<Target Name="Format" Condition=" '$(MSBuildProjectExtension)' == '.fsproj' AND '$(DesignTimeBuild)' != 'true' " BeforeTargets="BeforeBuild" Inputs="@(Compile)" Outputs="$(_DotnetFantomasOutputFile)" >
23+
<Exec Command="dotnet fantomas $(MSBuildProjectDirectory)" StandardOutputImportance="High" StandardErrorImportance="High" WorkingDirectory="$(MSBuildThisFileDirectory)" ContinueOnError="WarnAndContinue" />
2424
<Touch Files="$(_DotnetFantomasOutputFile)" AlwaysCreate="True" ForceTouch="True" />
2525
</Target>
26+
2627
</Project>

0 commit comments

Comments
 (0)