Skip to content
This repository was archived by the owner on Nov 30, 2023. It is now read-only.

Commit 3cd6c6e

Browse files
authored
Merge pull request #188 from philliphoff/philliphoff-dapr-node
Add a Dev Container for developing Dapr with Node.js 12 & TypeScript
2 parents da38314 + fa45261 commit 3cd6c6e

20 files changed

+2168
-2
lines changed

containers/dapr-dotnetcore-3.0/README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,11 @@ If you've already opened your folder in a container, rebuild the container using
6767
2. To use VS Code's copy of this definition:
6868
1. Start VS Code and open your project folder.
6969
2. Press <kbd>F1</kbd> select and **Remote-Containers: Add Development Container Configuration Files...** from the command palette.
70-
3. Select the Dapr with C# (.NET Core Latest) definition.
70+
3. Select the Dapr with C# (.NET Core 3.0) definition.
7171

7272
3. To use latest-and-greatest copy of this definition from the repository:
7373
1. Clone this repository.
74-
2. Copy the contents of `containers/dotnetcore-latest/.devcontainer` to the root of your project folder.
74+
2. Copy the contents of `containers/dapr-dotnetcore-3.0/.devcontainer` to the root of your project folder.
7575
3. Start VS Code and open your project folder.
7676

7777
4. After following step 2 or 3, the contents of the `.devcontainer` folder in your project can be adapted to meet your needs.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
#-------------------------------------------------------------------------------------------------------------
2+
# Copyright (c) Microsoft Corporation. All rights reserved.
3+
# Licensed under the MIT License. See https://go.microsoft.com/fwlink/?linkid=2090316 for license information.
4+
#-------------------------------------------------------------------------------------------------------------
5+
6+
FROM node:12
7+
8+
# Avoid warnings by switching to noninteractive
9+
ENV DEBIAN_FRONTEND=noninteractive
10+
11+
# The node image includes a non-root user with sudo access. Use the "remoteUser"
12+
# property in devcontainer.json to use it. On Linux, the container user's GID/UIDs
13+
# will be updated to match your local UID/GID (when using the dockerFile property).
14+
# See https://aka.ms/vscode-remote/containers/non-root-user for details.
15+
ARG USERNAME=node
16+
ARG USER_UID=1000
17+
ARG USER_GID=$USER_UID
18+
19+
# Docker Compose version
20+
ARG COMPOSE_VERSION=1.24.0
21+
22+
# Configure apt and install packages
23+
RUN apt-get update \
24+
&& apt-get -y install --no-install-recommends apt-utils dialog 2>&1 \
25+
#
26+
# Verify git and needed tools are installed
27+
&& apt-get -y install git iproute2 procps \
28+
#
29+
# Install Docker CE CLI
30+
&& apt-get install -y apt-transport-https ca-certificates curl gnupg-agent software-properties-common lsb-release \
31+
&& curl -fsSL https://download.docker.com/linux/$(lsb_release -is | tr '[:upper:]' '[:lower:]')/gpg | (OUT=$(apt-key add - 2>&1) || echo $OUT) \
32+
&& add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/$(lsb_release -is | tr '[:upper:]' '[:lower:]') $(lsb_release -cs) stable" \
33+
&& apt-get update \
34+
&& apt-get install -y docker-ce-cli \
35+
#
36+
# Install Docker Compose
37+
&& curl -sSL "https://github.com/docker/compose/releases/download/${COMPOSE_VERSION}/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose \
38+
&& chmod +x /usr/local/bin/docker-compose \
39+
#
40+
# Install Dapr
41+
&& wget -q https://raw.githubusercontent.com/dapr/cli/master/install/install.sh -O - | /bin/bash \
42+
#
43+
# Remove outdated yarn from /opt and install via package
44+
# so it can be easily updated via apt-get upgrade yarn
45+
&& rm -rf /opt/yarn-* \
46+
&& rm -f /usr/local/bin/yarn \
47+
&& rm -f /usr/local/bin/yarnpkg \
48+
&& apt-get install -y curl apt-transport-https lsb-release \
49+
&& curl -sS https://dl.yarnpkg.com/$(lsb_release -is | tr '[:upper:]' '[:lower:]')/pubkey.gpg | apt-key add - 2>/dev/null \
50+
&& echo "deb https://dl.yarnpkg.com/$(lsb_release -is | tr '[:upper:]' '[:lower:]')/ stable main" | tee /etc/apt/sources.list.d/yarn.list \
51+
&& apt-get update \
52+
&& apt-get -y install --no-install-recommends yarn \
53+
#
54+
# Install tslint and typescript globally
55+
&& npm install -g tslint eslint typescript \
56+
#
57+
# [Optional] Update a non-root user to UID/GID if needed.
58+
&& if [ "$USER_GID" != "1000" ] || [ "$USER_UID" != "1000" ]; then \
59+
groupmod --gid $USER_GID $USERNAME \
60+
&& usermod --uid $USER_UID --gid $USER_GID $USERNAME \
61+
&& chown -R $USER_UID:$USER_GID /home/$USERNAME; \
62+
fi \
63+
# [Optional] Add add sudo support for non-root user
64+
&& apt-get install -y sudo \
65+
&& echo node ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/$USERNAME \
66+
&& chmod 0440 /etc/sudoers.d/$USERNAME \
67+
#
68+
# Clean up
69+
&& apt-get autoremove -y \
70+
&& apt-get clean -y \
71+
&& rm -rf /var/lib/apt/lists/*
72+
73+
# Switch back to dialog for any ad-hoc use of apt-get
74+
ENV DEBIAN_FRONTEND=dialog
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
{
2+
"name": "Dapr with Node.js 12 & TypeScript",
3+
"dockerComposeFile": "docker-compose.yml",
4+
"service": "docker-in-docker",
5+
"workspaceFolder": "/workspace",
6+
7+
// Use 'settings' to set *default* container specific settings.json values on container create.
8+
// You can edit these settings after create using File > Preferences > Settings > Remote.
9+
"settings": {
10+
"terminal.integrated.shell.linux": "/bin/bash"
11+
},
12+
13+
// Uncomment the next line if you want start specific services in your Docker Compose config.
14+
// "runServices": [],
15+
16+
// Uncomment the next line if you want to keep your containers running after VS Code shuts down.
17+
// "shutdownAction": "none",
18+
19+
// Ensure Dapr is running on opening the container
20+
"postCreateCommand": "dapr init",
21+
22+
// Uncomment the next line to have VS Code connect as an existing non-root user in the container.
23+
// On Linux, by default, the container user's UID/GID will be updated to match your local user. See
24+
// https://aka.ms/vscode-remote/containers/non-root for details on adding a non-root user if none exist.
25+
// "remoteUser": "node",
26+
27+
// Add the IDs of extensions you want installed when the container is created in the array below.
28+
"extensions": [
29+
"dbaeumer.vscode-eslint",
30+
"ms-azuretools.vscode-docker",
31+
32+
// TSLint is included for backwards compatibility, but is deprecated.
33+
// See https://github.com/palantir/tslint/issues/4534
34+
"ms-vscode.vscode-typescript-tslint-plugin"
35+
]
36+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#-------------------------------------------------------------------------------------------------------------
2+
# Copyright (c) Microsoft Corporation. All rights reserved.
3+
# Licensed under the MIT License. See https://go.microsoft.com/fwlink/?linkid=2090316 for license information.
4+
#-------------------------------------------------------------------------------------------------------------
5+
6+
version: '3.5'
7+
services:
8+
docker-in-docker:
9+
# Uncomment the next line to use a non-root user for all processes. You can also
10+
# simply use the "remoteUser" property in devcontainer.json if you just want VS Code
11+
# and its sub-processes (terminals, tasks, debugging) to execute as the user. On Linux,
12+
# you may need to update USER_UID and USER_GID in .devcontainer/Dockerfile to match your
13+
# user if not 1000. See https://aka.ms/vscode-remote/containers/non-root for details.
14+
# user: vscode
15+
16+
build:
17+
context: .
18+
dockerfile: Dockerfile
19+
20+
environment:
21+
DAPR_NETWORK: dapr-typescript
22+
DAPR_REDIS_HOST: dapr_redis
23+
DAPR_PLACEMENT_HOST: dapr_placement
24+
25+
# Uncomment the next two lines if you want to publish the application port.
26+
# ports:
27+
# - 3000
28+
29+
volumes:
30+
# Update this to wherever you want VS Code to mount the folder of your project
31+
- ..:/workspace:cached
32+
33+
# Forwards the local Docker socket to the container.
34+
- /var/run/docker.sock:/var/run/docker.sock
35+
36+
# Uncomment the next four lines if you will use a ptrace-based debuggers like C++, Go, and Rust.
37+
# cap_add:
38+
# - SYS_PTRACE
39+
# security_opt:
40+
# - seccomp:unconfined
41+
42+
# Overrides default command so things don't shut down after the process ends.
43+
command: sleep infinity
44+
45+
networks:
46+
default:
47+
name: dapr-typescript
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
README.md
2+
test-project
3+
.vscode
4+
.npmignore
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
// Use IntelliSense to learn about possible attributes.
3+
// Hover to view descriptions of existing attributes.
4+
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5+
"version": "0.2.0",
6+
"configurations": [
7+
{
8+
"type": "node",
9+
"request": "launch",
10+
"name": "Launch Program",
11+
"runtimeExecutable": "npm",
12+
"runtimeArgs": ["run-script", "dapr-debug"],
13+
"port": 9229,
14+
"cwd": "${workspaceFolder}/test-project",
15+
"preLaunchTask": "compile"
16+
}
17+
]
18+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"eslint.validate": [
3+
"javascript",
4+
"typescript"
5+
],
6+
"eslint.workingDirectories": [
7+
{
8+
"directory": "./test-project",
9+
"changeProcessCWD": true
10+
}
11+
]
12+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
// See https://go.microsoft.com/fwlink/?LinkId=733558
3+
// for the documentation about the tasks.json format
4+
"version": "2.0.0",
5+
"tasks": [
6+
{
7+
"label": "compile",
8+
"type": "shell",
9+
"command": "cd test-project && npm run compile",
10+
"problemMatcher": "$tsc",
11+
"dependsOn": "npm: install - test-project"
12+
}
13+
]
14+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
# Dapr with Node.js 12 & TypeScript
2+
3+
## Summary
4+
5+
*Develop Dapr applications using Node.js 12 and TypeScript. Includes Dapr, Node.js, eslint, yarn, and the TypeScript compiler.*
6+
7+
| Metadata | Value |
8+
|----------|-------|
9+
| *Contributors* | The Visual Studio Container Tools team |
10+
| *Definition type* | Docker Compose |
11+
| *Languages, platforms* | Node.js, TypeScript, Dapr |
12+
13+
## Dapr Notes
14+
15+
When the dev container is created, the definition automatically initializes Dapr on a separate Docker network (to isolate it from Dapr instances running locally or in another Dapr dev container). This is done via the `postCreateCommand` in the `.devcontainer/devcontainer.json` and the `DAPR_NETWORK` environment variable in the `.devcontainer/docker-compose.yml`. The `DAPR_REDIS_HOST` and `DAPR_PLACEMENT_HOST` environment variables ensure that Dapr `run` commands implicitly connect to the Dapr instance in that Docker network.
16+
17+
## Using this definition with an existing folder
18+
19+
This definition installs `tslint` globally and includes the VS Code TSLint extension for backwards compatibility, but [TSLint has been deprecated](https://github.com/palantir/tslint/issues/4534) in favor of ESLint, so `eslint` and its corresponding extension has been included as well.
20+
21+
Both `eslint`and `typescript` are installed globally for convenance, but [as of ESLint 6](https://eslint.org/docs/user-guide/migrating-to-6.0.0#-plugins-and-shareable-configs-are-no-longer-affected-by-eslints-location), you will need to install the following packages locally to lint TypeScript code: `@typescript-eslint/eslint-plugin`, `@typescript-eslint/parser`, `eslint`, `typescript`.
22+
23+
To get started, follow these steps:
24+
25+
1. If this is your first time using a development container, please follow the [getting started steps](https://aka.ms/vscode-remote/containers/getting-started) to set up your machine.
26+
27+
2. To use VS Code's copy of this definition:
28+
1. Start VS Code and open your project folder.
29+
2. Press <kbd>F1</kbd> select and **Remote-Containers: Add Development Container Configuration Files...** from the command palette.
30+
3. Select the Dapr with Node.js 12 & TypeScript definition.
31+
32+
3. To use latest-and-greatest copy of this definition from the repository:
33+
1. Clone this repository.
34+
2. Copy the contents of `containers/dapr-typescript-node-12/.devcontainer` to the root of your project folder.
35+
3. Start VS Code and open your project folder.
36+
37+
4. After following step 2 or 3, the contents of the `.devcontainer` folder in your project can be adapted to meet your needs.
38+
39+
5. Finally, press <kbd>F1</kbd> and run **Remote-Containers: Reopen Folder in Container** to start using the definition.
40+
41+
## Testing the definition
42+
43+
This definition includes some test code that will help you verify it is working as expected on your system. Follow these steps:
44+
45+
1. If this is your first time using a development container, please follow the [getting started steps](https://aka.ms/vscode-remote/containers/getting-started) to set up your machine.
46+
2. Clone this repository.
47+
3. Start VS Code, press <kbd>F1</kbd>, and select **Remote-Containers: Open Folder in Container...**
48+
4. Select the `containers/dapr-typescript-node-12` folder.
49+
5. After the folder has opened in the container, press <kbd>F5</kbd> to start the project. This will automatically run `npm install` and compile the source before starting it.
50+
6. Start the application with Dapr:
51+
52+
```bash
53+
$ cd test-project
54+
$ npm run dapr
55+
```
56+
57+
7. In a separate terminal, invoke the application via Dapr:
58+
59+
```bash
60+
# Deposit funds to the account (creating the account if not exists)
61+
$ curl -d 42 -H "Content-Type: application/json" -w "\n" -X POST http://localhost:3500/v1.0/invoke/test/method/accounts/123/deposit
62+
42
63+
# Withdraws funds from the account
64+
$ curl -d 10 -H "Content-Type: application/json" -w "\n" -X POST http://localhost:3500/v1.0/invoke/test/method/accounts/123/withdraw
65+
32
66+
# Get the balance of the account
67+
$ curl -w "\n" http://localhost:3500/v1.0/invoke/test/method/accounts/123
68+
32
69+
$
70+
```
71+
72+
## License
73+
74+
Copyright (c) Microsoft Corporation. All rights reserved.
75+
76+
Licensed under the MIT License. See [LICENSE](https://github.com/Microsoft/vscode-dev-containers/blob/master/LICENSE).
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
"env": {
3+
"es6": true,
4+
"node": true
5+
},
6+
"extends": [
7+
"eslint:recommended",
8+
"plugin:@typescript-eslint/eslint-recommended"
9+
],
10+
"globals": {
11+
"Atomics": "readonly",
12+
"SharedArrayBuffer": "readonly"
13+
},
14+
"parser": "@typescript-eslint/parser",
15+
"parserOptions": {
16+
"ecmaVersion": 2018,
17+
"sourceType": "module"
18+
},
19+
"plugins": [
20+
"@typescript-eslint"
21+
],
22+
"rules": {
23+
}
24+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
apiVersion: dapr.io/v1alpha1
2+
kind: Component
3+
metadata:
4+
name: statestore
5+
spec:
6+
type: state.redis
7+
metadata:
8+
- name: redisHost
9+
value: dapr_redis:6379
10+
- name: redisPassword
11+
value: ""
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
apiVersion: dapr.io/v1alpha1
2+
kind: Component
3+
metadata:
4+
name: messagebus
5+
spec:
6+
type: pubsub.redis
7+
metadata:
8+
- name: redisHost
9+
value: dapr_redis:6379
10+
- name: redisPassword
11+
value: ""

0 commit comments

Comments
 (0)