From 860695e19b8183f78da15f5cedd4ba8a1aa2e026 Mon Sep 17 00:00:00 2001 From: Kevin BEAUGRAND Date: Wed, 24 May 2023 08:45:54 +0000 Subject: [PATCH] Add multi instance dev container --- .devcontainer/Dockerfile | 4 ++-- .devcontainer/devcontainer.json | 24 +++++++++---------- .devcontainer/docker-compose.yml | 40 ++++++++++++++++++++++++++++++++ .gitignore | 1 + .vscode/launch.json | 4 ++-- .vscode/tasks.json | 6 ++--- src/Directory.Build.props | 1 + 7 files changed, 61 insertions(+), 19 deletions(-) create mode 100644 .devcontainer/docker-compose.yml diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile index 7a129d2c1..7a78a91a6 100644 --- a/.devcontainer/Dockerfile +++ b/.devcontainer/Dockerfile @@ -1,8 +1,8 @@ # See here for image contents: https://github.com/microsoft/vscode-dev-containers/tree/v0.238.0/containers/dotnet/.devcontainer/base.Dockerfile # [Choice] .NET version: 6.0, 3.1, 6.0-bullseye, 3.1-bullseye, 6.0-focal, 3.1-focal -ARG VARIANT="6.0-bullseye-slim" -FROM mcr.microsoft.com/vscode/devcontainers/dotnet:0-${VARIANT} +ARG VARIANT="7.0-bullseye-slim" +FROM mcr.microsoft.com/vscode/devcontainers/dotnet:dev-${VARIANT} # [Choice] Node.js version: none, lts/*, 18, 16, 14 ARG NODE_VERSION="none" diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 8be7b11ff..4f05d333c 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -2,16 +2,17 @@ // https://github.com/microsoft/vscode-dev-containers/tree/v0.238.0/containers/dotnet { "name": "C# (.NET)", - "build": { - "dockerfile": "Dockerfile", - "args": { - // Update 'VARIANT' to pick a .NET Core version: 3.1, 6.0 - // Append -bullseye or -focal to pin to an OS version. - "VARIANT": "6.0-bullseye", - // Options - "NODE_VERSION": "lts/*" - } - }, + // Update the 'dockerComposeFile' list if you have more compose files or use different names. + "dockerComposeFile": "docker-compose.yml", + + // The 'service' property is the name of the service for the container that VS Code should + // use. Update this value and .devcontainer/docker-compose.yml to the real service name. + "service": "app", + + // The 'workspaceFolder' property is the path VS Code should open by default when + // connected. Corresponds to a volume mount in .devcontainer/docker-compose.yml + "workspaceFolder": "/workspace", + // Configure tool-specific properties. "customizations": { // Configure properties specific to VS Code. @@ -21,7 +22,6 @@ "ms-dotnettools.csharp", "ms-dotnettools.vscode-dotnet-runtime", "tintoy.msbuild-project-tools", - "jchannon.csharpextensions", "fernandoescolar.vscode-solution-explorer" ] } @@ -51,7 +51,7 @@ // * If only using Remote - Containers with a local container, uncomment this line instead: // "mounts": [ "source=${env:HOME}${env:USERPROFILE}/.aspnet/https,target=/home/vscode/.aspnet/https,type=bind" ], // Use 'postCreateCommand' to run commands after the container is created. - // "postCreateCommand": "dotnet restore", + "postCreateCommand": "dotnet dev-certs https --trust && dotnet restore src/*.sln", // Comment out to connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root. "remoteUser": "vscode" } \ No newline at end of file diff --git a/.devcontainer/docker-compose.yml b/.devcontainer/docker-compose.yml new file mode 100644 index 000000000..1964dda9a --- /dev/null +++ b/.devcontainer/docker-compose.yml @@ -0,0 +1,40 @@ +version: '3.4' + +services: + database: + image: postgres:14-alpine + restart: always + environment: + POSTGRES_PASSWORD: postgrePassword + POSTGRES_DB: cgigeiotdemo + volumes: + - pgdata:/var/lib/postgresql/data + healthcheck: + test: ["CMD-SHELL", "sh -c 'pg_isready -U postgres -d cgigeiotdemo'"] + interval: 10s + timeout: 5s + retries: 5 + + app: + build: + context: . + dockerfile: Dockerfile + # [Optional] You can use build args to set options. e.g. 'VARIANT' below affects the image in the Dockerfile + args: + NODE_VERSION: lts/* + + volumes: + # This is where VS Code should expect to find your project's source code and the value of "workspaceFolder" in .devcontainer/devcontainer.json + - ..:/workspace:cached + + # Uncomment the next line to use Docker from inside the container. See https://aka.ms/vscode-remote/samples/docker-from-docker-compose for details. + - /var/run/docker.sock:/var/run/docker.sock + + # Overrides default command so things don't shut down after the process ends. + command: /bin/sh -c "while sleep 1000; do :; done" + + depends_on: + database: + condition: service_healthy +volumes: + pgdata: \ No newline at end of file diff --git a/.gitignore b/.gitignore index b38b0f982..b7dca1a53 100644 --- a/.gitignore +++ b/.gitignore @@ -9,6 +9,7 @@ local.settings.json *.user *.userosscache *.sln.docstates +user-secrets.json # User-specific files (MonoDevelop/Xamarin Studio) *.userprefs diff --git a/.vscode/launch.json b/.vscode/launch.json index 41d8d4ddb..11aca341f 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -10,9 +10,9 @@ "request": "launch", "preLaunchTask": "build", // If you have changed target frameworks, make sure to update the program path. - "program": "${workspaceFolder}/src/AzureIoTHub.Portal/Server/bin/Debug/net6.0/AzureIoTHub.Portal.Server.dll", + "program": "${workspaceFolder}/src/AzureIoTHub.Portal.Server/bin/Debug/net7.0/AzureIoTHub.Portal.Server.dll", "args": [], - "cwd": "${workspaceFolder}/src/AzureIoTHub.Portal/Server/", + "cwd": "${workspaceFolder}/src/AzureIoTHub.Portal.Server/", "stopAtEntry": false, // Enable launching a web browser when ASP.NET Core starts. For more information: https://aka.ms/VSCode-CS-LaunchJson-WebBrowser "serverReadyAction": { diff --git a/.vscode/tasks.json b/.vscode/tasks.json index 5b9b3495b..97dfed794 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -7,7 +7,7 @@ "type": "process", "args": [ "build", - "${workspaceFolder}/src/AzureIoTHub.Portal/Server/AzureIoTHub.Portal.Server.csproj", + "${workspaceFolder}/src/AzureIoTHub.Portal.Server/AzureIoTHub.Portal.Server.csproj", "/property:GenerateFullPaths=true", "/consoleloggerparameters:NoSummary" ], @@ -19,7 +19,7 @@ "type": "process", "args": [ "publish", - "${workspaceFolder}/src/AzureIoTHub.Portal/Server/AzureIoTHub.Portal.Server.csproj", + "${workspaceFolder}/src/AzureIoTHub.Portal.Server/AzureIoTHub.Portal.Server.csproj", "/property:GenerateFullPaths=true", "/consoleloggerparameters:NoSummary" ], @@ -33,7 +33,7 @@ "watch", "run", "--project", - "${workspaceFolder}/src/AzureIoTHub.Portal/Server/AzureIoTHub.Portal.Server.csproj" + "${workspaceFolder}/src/AzureIoTHub.Portal.Server/AzureIoTHub.Portal.Server.csproj" ], "problemMatcher": "$msCompile" } diff --git a/src/Directory.Build.props b/src/Directory.Build.props index 3dc2f8969..25cc3af99 100644 --- a/src/Directory.Build.props +++ b/src/Directory.Build.props @@ -9,6 +9,7 @@ false net6.0 1591 + clear