Skip to content

Commit 1bdedf1

Browse files
authored
Merge pull request #1688 from hackmdio/chore/dev-container
Add dev container for GitHub Codespaces and VSCode remote container
2 parents e623b72 + 2338113 commit 1bdedf1

File tree

4 files changed

+119
-1
lines changed

4 files changed

+119
-1
lines changed

.devcontainer/Dockerfile

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# [Choice] Node.js version: 16, 14, 12
2+
ARG VARIANT=12-buster
3+
FROM mcr.microsoft.com/vscode/devcontainers/javascript-node:0-${VARIANT}
4+
5+
# [Optional] Uncomment this section to install additional OS packages.
6+
# RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
7+
# && apt-get -y install --no-install-recommends <your-package-list-here>
8+
9+
# [Optional] Uncomment if you want to install an additional version of node using nvm
10+
# ARG EXTRA_NODE_VERSION=10
11+
# RUN su node -c "source /usr/local/share/nvm/nvm.sh && nvm install ${EXTRA_NODE_VERSION}"
12+
13+
# [Optional] Uncomment if you want to install more global node modules
14+
RUN su node -c "npm install -g npm@6"

.devcontainer/devcontainer.json

+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
{
2+
"name": "CodiMD",
3+
"dockerComposeFile": "docker-compose.yml",
4+
"service": "app",
5+
"workspaceFolder": "/workspace",
6+
7+
// Set *default* container specific settings.json values on container create.
8+
"settings": {
9+
"terminal.integrated.shell.linux": "/bin/zsh",
10+
"sqltools.connections": [{
11+
"name": "Container Database",
12+
"driver": "PostgreSQL",
13+
"previewLimit": 50,
14+
"server": "localhost",
15+
"port": 5432,
16+
"database": "codimd",
17+
"username": "codimd",
18+
"password": "codimd"
19+
}],
20+
},
21+
22+
// Add the IDs of extensions you want installed when the container is created.
23+
"extensions": [
24+
"dbaeumer.vscode-eslint",
25+
"visualstudioexptteam.vscodeintellicode",
26+
"christian-kohler.path-intellisense",
27+
"standard.vscode-standard",
28+
"mtxr.sqltools",
29+
"mtxr.sqltools-driver-pg",
30+
"eamodio.gitlens",
31+
"codestream.codestream",
32+
"github.vscode-pull-request-github",
33+
"cschleiden.vscode-github-actions",
34+
"hbenl.vscode-mocha-test-adapter",
35+
"hbenl.vscode-test-explorer"
36+
],
37+
38+
// Use 'forwardPorts' to make a list of ports inside the container available locally.
39+
// "forwardPorts": [],
40+
41+
"portsAttributes": {
42+
"3000": {
43+
"label": "CodiMD server",
44+
"onAutoForward": "notify"
45+
},
46+
"5432": {
47+
"label": "PostgreSQL",
48+
"onAutoForward": "notify"
49+
}
50+
},
51+
52+
// Use 'postCreateCommand' to run commands after the container is created.
53+
// "postCreateCommand": "yarn install",
54+
"postCreateCommand": "sudo chown -R node:node node_modules && /workspace/bin/setup",
55+
56+
// Comment out connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root.
57+
"remoteUser": "node"
58+
}

.devcontainer/docker-compose.yml

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
version: '3'
2+
3+
services:
4+
app:
5+
build:
6+
context: ..
7+
dockerfile: .devcontainer/Dockerfile
8+
args:
9+
VARIANT: 12-buster
10+
environment:
11+
- CMD_DB_URL=postgres://codimd:codimd@localhost/codimd
12+
- CMD_USECDN=false
13+
volumes:
14+
- ..:/workspace:cached
15+
- node_modules:/workspace/node_modules:cached
16+
17+
# Overrides default command so things don't shut down after the process ends.
18+
command: sleep infinity
19+
20+
# Runs app on the same network as the database container, allows "forwardPorts" in devcontainer.json function.
21+
network_mode: service:db
22+
23+
# Runs app on the same network as the database container, allows "forwardPorts" in devcontainer.json function.
24+
25+
# Uncomment the next line to use a non-root user for all processes.
26+
# user: vscode
27+
28+
# Use "forwardPorts" in **devcontainer.json** to forward an app port locally.
29+
# (Adding the "ports" property to this file will not forward from a Codespace.)
30+
31+
db:
32+
image: postgres:12.7-alpine
33+
restart: unless-stopped
34+
volumes:
35+
- postgres-data:/var/lib/postgresql/data
36+
environment:
37+
- POSTGRES_USER=codimd
38+
- POSTGRES_PASSWORD=codimd
39+
- POSTGRES_DB=codimd
40+
41+
# Add "forwardPorts": ["5432"] to **devcontainer.json** to forward PostgreSQL locally.
42+
# (Adding the "ports" property to this file will not forward from a Codespace.)
43+
44+
volumes:
45+
node_modules:
46+
postgres-data:

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
"dev": "webpack --config webpack.dev.js --progress --colors --watch",
2020
"doctoc": "doctoc --title='# Table of Contents' README.md",
2121
"lint": "standard",
22-
"jsonlint": "find . -type f -not -ipath \"./node_modules/*\" -not -ipath \"./.vscode/*\" \\( -name \"*.json\" -o -name \"*.json.*\" \\) | xargs -n 1 -I{} -- bash -c 'echo {}; jq . {} > /dev/null;'",
22+
"jsonlint": "find . -type f -not -ipath \"./.devcontainer/*\" -not -ipath \"./node_modules/*\" -not -ipath \"./.vscode/*\" \\( -name \"*.json\" -o -name \"*.json.*\" \\) | xargs -n 1 -I{} -- bash -c 'echo {}; jq . {} > /dev/null;'",
2323
"start": "sequelize db:migrate && node app.js",
2424
"mocha": "mocha --require intelli-espower-loader --exit ./test --recursive",
2525
"mocha:ci": "mocha --no-color -R dot --require intelli-espower-loader --exit ./test --recursive",

0 commit comments

Comments
 (0)