Skip to content

Commit 5a97b52

Browse files
alexr00alexdima
authored andcommitted
Add devContainer schema+validation
1 parent 36e7f18 commit 5a97b52

2 files changed

Lines changed: 145 additions & 0 deletions

File tree

extensions/configuration-editing/package.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,14 @@
9696
{
9797
"fileMatch": "/.vscode/extensions.json",
9898
"url": "vscode://schemas/extensions"
99+
},
100+
{
101+
"fileMatch": "/.devcontainer/devcontainer.json",
102+
"url": "./schemas/devContainer.schema.json"
103+
},
104+
{
105+
"fileMatch": "/.devcontainer.json",
106+
"url": "./schemas/devContainer.schema.json"
99107
}
100108
]
101109
},
Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
{
2+
"$schema": "http://json-schema.org/schema#",
3+
"description": "Defines a dev container",
4+
"allowComments": true,
5+
"type": "object",
6+
"definitions": {
7+
"devContainerCommon": {
8+
"properties": {
9+
"name": {
10+
"type": "string",
11+
"description": "A name to show for the workspace folder."
12+
},
13+
"extensions": {
14+
"type": "array",
15+
"description": "An array of extensions that should be installed into the container.",
16+
"items": {
17+
"type": "string"
18+
}
19+
},
20+
"postCreateCommand": {
21+
"type": ["string", "array"],
22+
"description": "A command to run after creating the container. If this is a single string, it will be run in a shell. If this is an array of strings, it will be run as a single command without shell.",
23+
"items": {
24+
"type": "string"
25+
}
26+
},
27+
"devPort": {
28+
"type": "integer",
29+
"description": "The port VS Code can use to connect to its backend."
30+
}
31+
}
32+
},
33+
"nonComposeBase": {
34+
"properties": {
35+
"appPort": {
36+
"type": ["integer", "string", "array"],
37+
"description": "Application ports that are exposed by the container. This can be a single port or an array of ports. Each port can be a number or a string. A number is mapped to the same port on the host. A string is passed to Docker unchanged and can be used to map ports differently, e.g. \"8000:8010\".",
38+
"items": {
39+
"type": ["integer", "string"]
40+
}
41+
},
42+
"runArgs": {
43+
"type": "array",
44+
"description": "The arguments required when starting in the container.",
45+
"items": {
46+
"type": "string"
47+
}
48+
},
49+
"shutdownAction": {
50+
"type": "string",
51+
"enum": ["none", "stopContainer"],
52+
"description": "Action to take when VS Code is shutting down. The default is to stop the container."
53+
},
54+
"overrideCommand": {
55+
"type": "boolean",
56+
"description": "Whether to overwrite the command specified in the image. The default is true."
57+
}
58+
}
59+
},
60+
"dockerFileContainer": {
61+
"properties": {
62+
"dockerFile": {
63+
"type": "string",
64+
"description": "The location of the Dockerfile that defines the contents of the container. The path is relative to the folder containing the `devcontainer.json` file."
65+
},
66+
"context": {
67+
"type": "string",
68+
"description": "The location of the context folder for building the Docker image. The path is relative to the folder containing the `devcontainer.json` file."
69+
}
70+
},
71+
"required": ["dockerFile"]
72+
},
73+
"imageContainer": {
74+
"properties": {
75+
"image": {
76+
"type": "string",
77+
"description": "The docker image that will be used to create the container."
78+
}
79+
},
80+
"required": ["image"]
81+
},
82+
"composeContainer": {
83+
"properties": {
84+
"dockerComposeFile": {
85+
"type": ["string", "array"],
86+
"description": "The name of the docker-compose file(s) used to start the services.",
87+
"items": {
88+
"type": "string"
89+
}
90+
},
91+
"service": {
92+
"type": "string",
93+
"description": "The service you want to work on."
94+
},
95+
"workspaceFolder": {
96+
"type": "string",
97+
"description": "The path of the workspace folder inside the container."
98+
},
99+
"shutdownAction": {
100+
"type": "string",
101+
"enum": ["none", "stopCompose"],
102+
"description": "Action to take when VS Code is shutting down. The default is to stop the containers."
103+
}
104+
},
105+
"required": ["dockerComposeFile", "service", "workspaceFolder"]
106+
}
107+
},
108+
"allOf": [
109+
{
110+
"oneOf": [
111+
{
112+
"allOf": [
113+
{
114+
"oneOf": [
115+
{
116+
"$ref": "#/definitions/dockerFileContainer"
117+
},
118+
{
119+
"$ref": "#/definitions/imageContainer"
120+
}
121+
]
122+
},
123+
{
124+
"$ref": "#/definitions/nonComposeBase"
125+
}
126+
]
127+
},
128+
{
129+
"$ref": "#/definitions/composeContainer"
130+
}
131+
]
132+
},
133+
{
134+
"$ref": "#/definitions/devContainerCommon"
135+
}
136+
]
137+
}

0 commit comments

Comments
 (0)