Skip to content

Commit 35ee537

Browse files
committed
working on integrating the Cosmos docker emulator for simpler local dev
1 parent 822f757 commit 35ee537

14 files changed

Lines changed: 1025 additions & 171 deletions

File tree

.devcontainer/Dockerfile

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,28 @@
11
ARG VARIANT="6.0-bullseye-slim"
22
FROM mcr.microsoft.com/vscode/devcontainers/dotnet:0-${VARIANT}
33

4-
# [Option] Install Node.js
5-
ARG INSTALL_NODE="true"
6-
ARG NODE_VERSION="lts/*"
7-
RUN if [ "${INSTALL_NODE}" = "true" ]; then su vscode -c "umask 0002 && . /usr/local/share/nvm/nvm.sh && nvm install ${NODE_VERSION} 2>&1"; fi
4+
# [Option] Enable non-root Docker access in container
5+
ARG ENABLE_NONROOT_DOCKER="true"
6+
# [Option] Use the OSS Moby CLI instead of the licensed Docker CLI
7+
ARG USE_MOBY="true"
88

9-
# [Option] Install Azure CLI
10-
ARG INSTALL_AZURE_CLI="false"
11-
COPY library-scripts/azcli-debian.sh /tmp/library-scripts/
12-
RUN if [ "$INSTALL_AZURE_CLI" = "true" ]; then bash /tmp/library-scripts/azcli-debian.sh; fi \
13-
&& apt-get clean -y && rm -rf /var/lib/apt/lists/* /tmp/library-scripts
9+
# Enable new "BUILDKIT" mode for Docker CLI
10+
ENV DOCKER_BUILDKIT=1
1411

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>
12+
# Install needed packages and setup non-root user. Use a separate RUN statement to add your
13+
# own dependencies. A user of "automatic" attempts to reuse an user ID if one already exists.
14+
ARG USERNAME=automatic
15+
ARG USER_UID=1000
16+
ARG USER_GID=$USER_UID
17+
COPY library-scripts/*.sh /tmp/library-scripts/
18+
RUN apt-get update \
19+
&& /bin/bash /tmp/library-scripts/common-debian.sh "${INSTALL_ZSH}" "${USERNAME}" "${USER_UID}" "${USER_GID}" "${UPGRADE_PACKAGES}" "true" "true" \
20+
# Use Docker script from script library to set things up
21+
&& /bin/bash /tmp/library-scripts/docker-debian.sh "${ENABLE_NONROOT_DOCKER}" "/var/run/docker-host.sock" "/var/run/docker.sock" "${USERNAME}" \
22+
# Clean up
23+
&& apt-get autoremove -y && apt-get clean -y && rm -rf /var/lib/apt/lists/* /tmp/library-scripts/
1824

19-
# [Optional] Uncomment this line to install global node packages.
20-
# RUN su vscode -c "source /usr/local/share/nvm/nvm.sh && npm install -g <your-package-here>" 2>&1
25+
# Setting the ENTRYPOINT to docker-init.sh will configure non-root access
26+
# to the Docker socket. The script will also execute CMD as needed.
27+
ENTRYPOINT [ "/usr/local/share/docker-init.sh" ]
28+
CMD [ "sleep", "infinity" ]

.devcontainer/devcontainer.json

Lines changed: 29 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,36 @@
11
{
2-
"name": "FSharp.CosmosDB",
3-
"build": {
4-
"dockerfile": "Dockerfile",
5-
"args": {
6-
// Options
7-
"INSTALL_NODE": "false",
8-
"NODE_VERSION": "lts/*",
9-
"INSTALL_AZURE_CLI": "true",
10-
"UPGRADE_PACKAGES": "false",
11-
"VARIANT": "6.0"
12-
}
13-
},
2+
"name": "FSharp.CosmosDB",
3+
"dockerComposeFile": "docker-compose.yml",
4+
"service": "app",
5+
"workspaceFolder": "/workspace",
146

15-
"settings": {
16-
"terminal.integrated.defaultProfile.linux": "zsh"
17-
},
7+
// Use this environment variable if you need to bind mount your local source code into a new container.
8+
"remoteEnv": {
9+
"LOCAL_WORKSPACE_FOLDER": "${localWorkspaceFolder}"
10+
},
1811

19-
// Add the IDs of extensions you want installed when the container is created.
20-
"extensions": [
21-
"Ionide.Ionide-fsharp",
22-
"ms-dotnettools.csharp",
23-
"ms-vscode.azure-account",
24-
"ionide.ionide-fake",
25-
"ionide.ionide-paket",
26-
"github.vscode-pull-request-github",
27-
"paolodellepiane.fantomas-fmt",
28-
"ms-azuretools.vscode-cosmosdb"
29-
],
12+
"settings": {
13+
"terminal.integrated.defaultProfile.linux": "zsh"
14+
},
3015

31-
// Use 'forwardPorts' to make a list of ports inside the container available locally.
32-
// "forwardPorts": [],
16+
// Add the IDs of extensions you want installed when the container is created.
17+
"extensions": [
18+
"Ionide.Ionide-fsharp",
19+
"ms-dotnettools.csharp",
20+
"ms-vscode.azure-account",
21+
"ionide.ionide-fake",
22+
"ionide.ionide-paket",
23+
"github.vscode-pull-request-github",
24+
"paolodellepiane.fantomas-fmt",
25+
"ms-azuretools.vscode-cosmosdb"
26+
],
3327

34-
// Use 'postCreateCommand' to run commands after the container is created.
35-
"postCreateCommand": "dotnet tool restore && dotnet restore",
28+
// Use 'forwardPorts' to make a list of ports inside the container available locally.
29+
// "forwardPorts": [],
3630

37-
// Comment out connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root.
38-
"remoteUser": "vscode"
31+
// Use 'postCreateCommand' to run commands after the container is created.
32+
"postCreateCommand": "dotnet tool restore && dotnet restore && ./.devcontainer/start.sh",
33+
34+
// Comment out connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root.
35+
"remoteUser": "vscode"
3936
}

.devcontainer/docker-compose.yml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
version: '3'
2+
3+
services:
4+
app:
5+
build:
6+
context: .
7+
dockerfile: Dockerfile
8+
args:
9+
USER_UID: 1000
10+
USER_GID: 1000
11+
VARIANT: "6.0"
12+
13+
init: true
14+
volumes:
15+
- /var/run/docker.sock:/var/run/docker-host.sock
16+
- ..:/workspace:cached
17+
18+
entrypoint: /usr/local/share/docker-init.sh
19+
command: sleep infinity
20+
environment:
21+
# These names aren't special - they're just used in the Node app to configure the CosmosClient
22+
COSMOS__ENDPOINT: https://cosmos:8081
23+
# This is the publicly documented emulator key
24+
COSMOS__KEY: 'C2y6yDjf5/R+ob0N8A7Cgv30VRDJIWEHLM+4QDU5DE2nQ9nDuVTqobD4b8mGGyPMbIZnqyMsEcaGQy67XIw/Jw=='
25+
26+
network_mode: service:cosmos
27+
cosmos:
28+
image: mcr.microsoft.com/cosmosdb/linux/azure-cosmos-emulator:latest
29+
mem_limit: 3g
30+
cpu_count: 2
31+
environment:
32+
AZURE_COSMOS_EMULATOR_PARTITION_COUNT: 10
33+
AZURE_COSMOS_EMULATOR_ENABLE_DATA_PERSISTENCE: "true"
34+
volumes:
35+
# Forwards the local Docker socket to the container.
36+
- /var/run/docker.sock:/var/run/docker-host.sock

0 commit comments

Comments
 (0)