Skip to content

Commit

Permalink
Add multi instance dev container
Browse files Browse the repository at this point in the history
  • Loading branch information
kbeaugrand committed May 24, 2023
1 parent 1ff62f6 commit e2ca121
Showing 6 changed files with 58 additions and 16 deletions.
4 changes: 2 additions & 2 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -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"
24 changes: 12 additions & 12 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -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"
}
40 changes: 40 additions & 0 deletions .devcontainer/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -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:
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -9,6 +9,7 @@ local.settings.json
*.user
*.userosscache
*.sln.docstates
user-secrets.json

# User-specific files (MonoDevelop/Xamarin Studio)
*.userprefs
4 changes: 2 additions & 2 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -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": {
1 change: 1 addition & 0 deletions src/Directory.Build.props
Original file line number Diff line number Diff line change
@@ -9,6 +9,7 @@
<TreatWarningsAsErrors>false</TreatWarningsAsErrors>
<TargetFramework>net6.0</TargetFramework>
<NoWarn>1591</NoWarn>
<RestoreFallbackFolders>clear</RestoreFallbackFolders>
</PropertyGroup>

<ItemGroup>

0 comments on commit e2ca121

Please sign in to comment.