Skip to content

Commit

Permalink
Merge pull request #460 from akunzai/dev-containers
Browse files Browse the repository at this point in the history
Simplify the mono msbuild installation in Dev container
  • Loading branch information
akunzai authored Nov 27, 2023
2 parents 59a34b6 + d48ee6a commit b3d74f3
Show file tree
Hide file tree
Showing 6 changed files with 113 additions and 30 deletions.
34 changes: 14 additions & 20 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,26 +1,20 @@
# https://hub.docker.com/_/microsoft-dotnet-sdk/
FROM mcr.microsoft.com/dotnet/sdk:8.0

ARG APT_URL=""

# install ASP.NET Core 6.0 Runtime
COPY --from=mcr.microsoft.com/dotnet/aspnet:6.0-bookworm-slim /usr/share/dotnet /usr/share/dotnet

RUN set -eux; \
# preferred mirror site
[ -n "$APT_URL" ] && [ "$APT_URL" = 'http://free.nchc.org.tw' ] && [ $(uname -m) = 'x86_64' ] && [ -e "/etc/apt/sources.list.d/debian.sources" ] && sed -i -E "/-security/! s,URIs: http?://[^\/]+,URIs: $APT_URL,g" /etc/apt/sources.list.d/debian.sources; \
[ -n "$APT_URL" ] && [ "$APT_URL" != 'http://free.nchc.org.tw' ] && [ -e "/etc/apt/sources.list.d/debian.sources" ] && sed -i -E "s,URIs: http?://[^\/]+,URIs: $APT_URL,g" /etc/apt/sources.list.d/debian.sources; \
# install msbuild for Mono
# https://www.mono-project.com/download/stable/#download-lin-debian
apt-get update; \
apt-get install -y --no-install-recommends dirmngr gnupg ca-certificates; \
# avoid connection timeout
timeout 10 apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF || apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF; \
echo "deb http://download.mono-project.com/repo/debian stable-buster main" > /etc/apt/sources.list.d/mono-official-stable.list; \
apt-get update; \
apt-get install -y mono-devel; \
# clean up
apt-get purge -y --auto-remove gnupg dirmngr; \
rm -rf /var/lib/apt/lists/* /tmp/*; \
# smoke test
dotnet --info && msbuild -version;
# install msbuild for Mono
# https://hub.docker.com/_/mono/
COPY --from=mono /etc/ca-certificates/update.d/mono-keystore /etc/ca-certificates/update.d/
COPY --from=mono /etc/mono /etc/mono
COPY --from=mono /usr/bin/cert-sync /usr/bin/
COPY --from=mono /usr/bin/mono /usr/bin/
COPY --from=mono /usr/bin/msbuild /usr/bin/
COPY --from=mono /usr/lib/mono /usr/lib/mono
COPY --from=mono /usr/lib/libmono-* /usr/lib/
COPY --from=mono /usr/lib/libMono* /usr/lib/

# synchronizes the Mono TLS certificates
# https://www.mono-project.com/docs/about-mono/releases/3.12.0/#cert-sync
RUN cert-sync /etc/ssl/certs/ca-certificates.crt
25 changes: 18 additions & 7 deletions .devcontainer/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,30 @@

## Getting Start

> The following instrstuctions are for macOS environment
```sh
# set up TLS certs and hosts in Host
./init.sh auth.dev.local

# run the Dev Containers
# starting container
docker compose up -d

# run the sample app in Host
cd ../samples/AspNetSample
cd ../samples/AspNetCoreSample
dotnet run

# browse sample app and sign-in as demo user (test:test)
open https://localhost:5001
```

## Admin URLs

- [Keycloak](https://auth.dev.local)

## Credentials

### Keycloak admin

- Username: `admin`
- Password: `admin`

### Keycloak user

- Username: `test`
- Password: `test`
11 changes: 10 additions & 1 deletion .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,17 @@
"service": "dotnet",
"workspaceFolder": "/workspaces",
"postAttachCommand": "corepack enable",
// https://containers.dev/features.
"customizations": {
"vscode": {
"extensions": [
"ms-dotnettools.csharp",
"josefpihrt-vscode.roslynator"
]
}
},
// https://containers.dev/features
"features": {
"ghcr.io/devcontainers/features/git:1": {},
"ghcr.io/devcontainers/features/node:1": {}
}
}
4 changes: 2 additions & 2 deletions .devcontainer/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
version: '2'

name: auth-cas_devcontainer
services:
dotnet:
# https://github.com/devcontainers/images/blob/main/src/dotnet
build: .
image: dotnet:mono
image: dotnet-sdk:mono
environment:
ASPNETCORE_ENVIRONMENT: Development
PATH: $PATH:/home/vscode/.dotnet:/home/vscode/.dotnet/tools
Expand Down
33 changes: 33 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"version": "0.2.0",
"configurations": [
{
// https://github.com/dotnet/vscode-csharp/blob/main/debugger-launchjson.md。
"name": ".NET Core Launch (web)",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
// Needs change path when updating target Framework
"program": "${workspaceFolder}/samples/AspNetCoreSample/bin/Debug/net8.0/AspNetCoreSample.dll",
"args": [],
"cwd": "${workspaceFolder}/samples/AspNetCoreSample",
"stopAtEntry": false,
// https://aka.ms/VSCode-CS-LaunchJson-WebBrowser
"serverReadyAction": {
"action": "openExternally",
"pattern": "\\bNow listening on:\\s+(https?://\\S+)"
},
"env": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
"sourceFileMap": {
"/Views": "${workspaceFolder}/Views"
}
},
{
"name": ".NET Core Attach",
"type": "coreclr",
"request": "attach"
}
]
}
36 changes: 36 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
"version": "2.0.0",
"tasks": [
{
"label": "build",
"command": "dotnet",
"type": "process",
"args": [
"build",
"${workspaceFolder}/CAS.sln",
"/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary;ForceNoAlign"
],
"problemMatcher": "$msCompile"
},
{
"label": "publish",
"command": "dotnet",
"type": "process",
"args": [
"publish",
"${workspaceFolder}/CAS.sln",
"/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary;ForceNoAlign"
],
"problemMatcher": "$msCompile"
},
{
"label": "watch",
"command": "dotnet",
"type": "process",
"args": ["watch", "run", "--project", "${workspaceFolder}/CAS.sln"],
"problemMatcher": "$msCompile"
}
]
}

0 comments on commit b3d74f3

Please sign in to comment.