From 7fc4df66df48da4e213141f87c515c02c2d16e62 Mon Sep 17 00:00:00 2001 From: Opliko Date: Sat, 8 Jan 2022 21:37:45 +0000 Subject: [PATCH 01/10] feat: initial devcontainer setup --- .devcontainer/Dockerfile | 33 +++++++++++++++++++++++++ .devcontainer/config.json | 13 ++++++++++ .devcontainer/devcontainer.json | 27 ++++++++++++++++++++ .devcontainer/docker-compose.yml | 42 ++++++++++++++++++++++++++++++++ .devcontainer/nodebb-db-init.js | 1 + 5 files changed, 116 insertions(+) create mode 100644 .devcontainer/Dockerfile create mode 100644 .devcontainer/config.json create mode 100644 .devcontainer/devcontainer.json create mode 100644 .devcontainer/docker-compose.yml create mode 100644 .devcontainer/nodebb-db-init.js diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile new file mode 100644 index 0000000..49caeba --- /dev/null +++ b/.devcontainer/Dockerfile @@ -0,0 +1,33 @@ +FROM + + +# [Choice] Node.js version (use -bullseye variants on local arm64/Apple Silicon): 16, 14, 12, 16-bullseye, 14-bullseye, 12-bullseye, 16-buster, 14-buster, 12-buster +ARG VARIANT=16-bullseye +FROM mcr.microsoft.com/vscode/devcontainers/javascript-node:0-${VARIANT} + +# Install MongoDB command line tools if on buster and x86_64 (arm64 not supported) +ARG MONGO_TOOLS_VERSION=5.0 +RUN . /etc/os-release \ + && if [ "${VERSION_CODENAME}" = "buster" ] && [ "$(dpkg --print-architecture)" = "amd64" ]; then \ + curl -sSL "https://www.mongodb.org/static/pgp/server-${MONGO_TOOLS_VERSION}.asc" | gpg --dearmor > /usr/share/keyrings/mongodb-archive-keyring.gpg \ + && echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/mongodb-archive-keyring.gpg] http://repo.mongodb.org/apt/debian $(lsb_release -cs)/mongodb-org/${MONGO_TOOLS_VERSION} main" | tee /etc/apt/sources.list.d/mongodb-org-${MONGO_TOOLS_VERSION}.list \ + && apt-get update && export DEBIAN_FRONTEND=noninteractive \ + && apt-get install -y mongodb-database-tools mongodb-mongosh \ + && apt-get clean -y && rm -rf /var/lib/apt/lists/*; \ + fi + +# [Optional] Uncomment this section to install additional OS packages. +# RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \ +# && apt-get -y install --no-install-recommends + +# [Optional] Uncomment if you want to install an additional version of node using nvm +# ARG EXTRA_NODE_VERSION=10 +# RUN su node -c "source /usr/local/share/nvm/nvm.sh && nvm install ${EXTRA_NODE_VERSION}" + +# [Optional] Uncomment if you want to install more global node modules +RUN su node -c "npm install -g grunt-cli" +WORKDIR /opt/nodebb +RUN git clone https://github.com/NodeBB/NodeBB /opt/nodebb +COPY ["./config.json", "/opt/nodebb/"] + +CMD node ./nodebb setup --skip-build && grunt -b /opt/nodebb --gruntfile /opt/nodebb/Gruntfile.js \ No newline at end of file diff --git a/.devcontainer/config.json b/.devcontainer/config.json new file mode 100644 index 0000000..a32e920 --- /dev/null +++ b/.devcontainer/config.json @@ -0,0 +1,13 @@ +{ + "url": "http://127.0.0.1", + "secret": "development-value-do-not-use-in-production", + "database": "mongo", + "mongo": { + "host": "127.0.0.1", + "port": 27017, + "database": "nodebb", + "username": "nodebb", + "password": "nodebb" + }, + "port": 4567 +} diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 0000000..8b0aea0 --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,27 @@ +// For format details, see https://aka.ms/devcontainer.json. For config options, see the README at: +// https://github.com/microsoft/vscode-dev-containers/tree/v0.208.0/containers/javascript-node-mongo +// Update the VARIANT arg in docker-compose.yml to pick a Node.js version +{ + "name": "Node.js & Mongo DB", + "dockerComposeFile": "docker-compose.yml", + "service": "app", + "workspaceFolder": "/workspace", + + // Set *default* container specific settings.json values on container create. + "settings": {}, + + // Add the IDs of extensions you want installed when the container is created. + "extensions": [ + "dbaeumer.vscode-eslint", + "mongodb.mongodb-vscode" + ], + + // Use 'forwardPorts' to make a list of ports inside the container available locally. + "forwardPorts": [4567, 27017], + + // Use 'postCreateCommand' to run commands after the container is created. + "postCreateCommand": "yarn install && yarn link && npm_name=$(node -p \"require('./package.json').name\") && current_dir=$(pwd) && cd /var/NodeBB && yarn link $npm_name && cd $current_dir", + + // Comment out connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root. + "remoteUser": "node" +} \ No newline at end of file diff --git a/.devcontainer/docker-compose.yml b/.devcontainer/docker-compose.yml new file mode 100644 index 0000000..794c165 --- /dev/null +++ b/.devcontainer/docker-compose.yml @@ -0,0 +1,42 @@ +version: '3.8' + +services: + app: + build: + context: . + dockerfile: Dockerfile + args: + # Update 'VARIANT' to pick an LTS version of Node.js: 16, 14, 12. + # Append -bullseye or -buster to pin to an OS version. + # Use -bullseye variants on local arm64/Apple Silicon. + VARIANT: 16-bullseye + depends_on: + - db + volumes: + - ..:/workspace:cached + + # Runs app on the same network as the database container, allows "forwardPorts" in devcontainer.json function. + network_mode: service:db + + # Uncomment the next line to use a non-root user for all processes. + user: node + + # Use "forwardPorts" in **devcontainer.json** to forward an app port locally. + # (Adding the "ports" property to this file will not forward from a Codespace.) + + db: + image: mongo:latest + restart: unless-stopped + volumes: + - mongodb-data:/data/db + - ./nodebb-db-init.js:/docker-entrypoint-initdb.d/nodebb-db-init.js + # Uncomment to change startup options + environment: + MONGO_INITDB_ROOT_USERNAME: root + MONGO_INITDB_ROOT_PASSWORD: root + MONGO_INITDB_DATABASE: nodebb + # Add "forwardPorts": ["27017"] to **devcontainer.json** to forward MongoDB locally. + # (Adding the "ports" property to this file will not forward from a Codespace.) + +volumes: + mongodb-data: \ No newline at end of file diff --git a/.devcontainer/nodebb-db-init.js b/.devcontainer/nodebb-db-init.js new file mode 100644 index 0000000..050ed1a --- /dev/null +++ b/.devcontainer/nodebb-db-init.js @@ -0,0 +1 @@ +db.createUser({user: "nodebb", pwd: "nodebb", roles: [{role: "readWrite", db: "nodebb", {role: "clusterMonitor", db: "admin"}]}); \ No newline at end of file From 9d5454cfa1b72ba0a688ccfc11fe5ec1e777188a Mon Sep 17 00:00:00 2001 From: opliko Date: Sun, 9 Jan 2022 01:55:58 +0100 Subject: [PATCH 02/10] fix: move setup to postCreateCommand --- .devcontainer/Dockerfile | 25 +++++++++++-------------- .devcontainer/config.json | 5 ++++- .devcontainer/devcontainer.json | 16 ++++++++-------- .devcontainer/docker-compose.yml | 5 +---- 4 files changed, 24 insertions(+), 27 deletions(-) diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile index 49caeba..c09875d 100644 --- a/.devcontainer/Dockerfile +++ b/.devcontainer/Dockerfile @@ -1,20 +1,17 @@ -FROM - - # [Choice] Node.js version (use -bullseye variants on local arm64/Apple Silicon): 16, 14, 12, 16-bullseye, 14-bullseye, 12-bullseye, 16-buster, 14-buster, 12-buster -ARG VARIANT=16-bullseye +ARG VARIANT=16-buster FROM mcr.microsoft.com/vscode/devcontainers/javascript-node:0-${VARIANT} +USER node + # Install MongoDB command line tools if on buster and x86_64 (arm64 not supported) ARG MONGO_TOOLS_VERSION=5.0 -RUN . /etc/os-release \ - && if [ "${VERSION_CODENAME}" = "buster" ] && [ "$(dpkg --print-architecture)" = "amd64" ]; then \ - curl -sSL "https://www.mongodb.org/static/pgp/server-${MONGO_TOOLS_VERSION}.asc" | gpg --dearmor > /usr/share/keyrings/mongodb-archive-keyring.gpg \ - && echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/mongodb-archive-keyring.gpg] http://repo.mongodb.org/apt/debian $(lsb_release -cs)/mongodb-org/${MONGO_TOOLS_VERSION} main" | tee /etc/apt/sources.list.d/mongodb-org-${MONGO_TOOLS_VERSION}.list \ - && apt-get update && export DEBIAN_FRONTEND=noninteractive \ - && apt-get install -y mongodb-database-tools mongodb-mongosh \ - && apt-get clean -y && rm -rf /var/lib/apt/lists/*; \ - fi +RUN sudo apt-get update && export DEBIAN_FRONTEND=noninteractive && sudo apt-get install gnupg &&\ + wget -qO - https://www.mongodb.org/static/pgp/server-${MONGO_TOOLS_VERSION}.asc | sudo apt-key add - &&\ + echo "deb [arch=$(dpkg --print-architecture)] http://repo.mongodb.org/apt/debian $(lsb_release -cs)/mongodb-org/${MONGO_TOOLS_VERSION} main" | sudo tee /etc/apt/sources.list.d/mongodb-org-${MONGO_TOOLS_VERSION}.list &&\ + sudo apt-get update && export DEBIAN_FRONTEND=noninteractive &&\ + sudo apt-get install -y mongodb-database-tools mongodb-mongosh &&\ + sudo apt-get clean -y && sudo rm -rf /var/lib/apt/lists/*; # [Optional] Uncomment this section to install additional OS packages. # RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \ @@ -25,9 +22,9 @@ RUN . /etc/os-release \ # RUN su node -c "source /usr/local/share/nvm/nvm.sh && nvm install ${EXTRA_NODE_VERSION}" # [Optional] Uncomment if you want to install more global node modules -RUN su node -c "npm install -g grunt-cli" +RUN yarn global add grunt-cli WORKDIR /opt/nodebb RUN git clone https://github.com/NodeBB/NodeBB /opt/nodebb COPY ["./config.json", "/opt/nodebb/"] -CMD node ./nodebb setup --skip-build && grunt -b /opt/nodebb --gruntfile /opt/nodebb/Gruntfile.js \ No newline at end of file +ENTRYPOINT grunt -b /opt/nodebb --gruntfile /opt/nodebb/Gruntfile.js \ No newline at end of file diff --git a/.devcontainer/config.json b/.devcontainer/config.json index a32e920..19578e9 100644 --- a/.devcontainer/config.json +++ b/.devcontainer/config.json @@ -9,5 +9,8 @@ "username": "nodebb", "password": "nodebb" }, - "port": 4567 + "port": 4567, + "package_manager": "yarn", + "admin__username": "admin" + } diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 8b0aea0..b52721f 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -6,22 +6,22 @@ "dockerComposeFile": "docker-compose.yml", "service": "app", "workspaceFolder": "/workspace", - // Set *default* container specific settings.json values on container create. "settings": {}, - // Add the IDs of extensions you want installed when the container is created. "extensions": [ "dbaeumer.vscode-eslint", "mongodb.mongodb-vscode" ], - // Use 'forwardPorts' to make a list of ports inside the container available locally. - "forwardPorts": [4567, 27017], - + "forwardPorts": [ + 4567, + 27017 + ], // Use 'postCreateCommand' to run commands after the container is created. - "postCreateCommand": "yarn install && yarn link && npm_name=$(node -p \"require('./package.json').name\") && current_dir=$(pwd) && cd /var/NodeBB && yarn link $npm_name && cd $current_dir", - + "postCreateCommand": "node /opt/nodebb/nodebb setup --skip-build", + "postStartCommand": "yarn install && yarn link && npm_name=$(node -p \"require('./package.json').name\") && cd /opt/nodebb && yarn link $npm_name && grunt -b /opt/nodebb --gruntfile /opt/nodebb/Gruntfile.js", // Comment out connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root. - "remoteUser": "node" + "remoteUser": "node", + "overrideCommand": true } \ No newline at end of file diff --git a/.devcontainer/docker-compose.yml b/.devcontainer/docker-compose.yml index 794c165..2d33376 100644 --- a/.devcontainer/docker-compose.yml +++ b/.devcontainer/docker-compose.yml @@ -9,12 +9,9 @@ services: # Update 'VARIANT' to pick an LTS version of Node.js: 16, 14, 12. # Append -bullseye or -buster to pin to an OS version. # Use -bullseye variants on local arm64/Apple Silicon. - VARIANT: 16-bullseye - depends_on: - - db + VARIANT: 16-buster volumes: - ..:/workspace:cached - # Runs app on the same network as the database container, allows "forwardPorts" in devcontainer.json function. network_mode: service:db From 9d42b15629e748a38355183e9206a039d998bc36 Mon Sep 17 00:00:00 2001 From: Opliko Date: Sun, 9 Jan 2022 21:41:11 +0000 Subject: [PATCH 03/10] fix: typo in mongodb init causing network to fail --- .devcontainer/Dockerfile | 1 + .devcontainer/config.json | 9 ++++++--- .devcontainer/devcontainer.json | 4 ++-- .devcontainer/docker-compose.yml | 12 ++++++------ .devcontainer/nodebb-db-init.js | 2 +- 5 files changed, 16 insertions(+), 12 deletions(-) diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile index c09875d..d2a8ce8 100644 --- a/.devcontainer/Dockerfile +++ b/.devcontainer/Dockerfile @@ -27,4 +27,5 @@ WORKDIR /opt/nodebb RUN git clone https://github.com/NodeBB/NodeBB /opt/nodebb COPY ["./config.json", "/opt/nodebb/"] +CMD grunt -b /opt/nodebb --gruntfile /opt/nodebb/Gruntfile.js ENTRYPOINT grunt -b /opt/nodebb --gruntfile /opt/nodebb/Gruntfile.js \ No newline at end of file diff --git a/.devcontainer/config.json b/.devcontainer/config.json index 19578e9..c5bbf6d 100644 --- a/.devcontainer/config.json +++ b/.devcontainer/config.json @@ -10,7 +10,10 @@ "password": "nodebb" }, "port": 4567, - "package_manager": "yarn", - "admin__username": "admin" - + "bind_address": "127.0.0.1", + "admin": { + "email": "nodebb@example.com", + "username": "nodebb", + "password": "nodebb" + } } diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index b52721f..9f57321 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -4,7 +4,7 @@ { "name": "Node.js & Mongo DB", "dockerComposeFile": "docker-compose.yml", - "service": "app", + "service": "nodebb", "workspaceFolder": "/workspace", // Set *default* container specific settings.json values on container create. "settings": {}, @@ -20,7 +20,7 @@ ], // Use 'postCreateCommand' to run commands after the container is created. "postCreateCommand": "node /opt/nodebb/nodebb setup --skip-build", - "postStartCommand": "yarn install && yarn link && npm_name=$(node -p \"require('./package.json').name\") && cd /opt/nodebb && yarn link $npm_name && grunt -b /opt/nodebb --gruntfile /opt/nodebb/Gruntfile.js", + "postStartCommand": "yarn install && npm link && npm_name=$(node -p \"require('./package.json').name\") && cd /opt/nodebb && npm link $npm_name && /opt/nodebb/nodebb activate $npm_name && grunt -b /opt/nodebb --gruntfile /opt/nodebb/Gruntfile.js", // Comment out connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root. "remoteUser": "node", "overrideCommand": true diff --git a/.devcontainer/docker-compose.yml b/.devcontainer/docker-compose.yml index 2d33376..d37015d 100644 --- a/.devcontainer/docker-compose.yml +++ b/.devcontainer/docker-compose.yml @@ -1,7 +1,7 @@ -version: '3.8' +version: '3.9' services: - app: + nodebb: build: context: . dockerfile: Dockerfile @@ -13,15 +13,14 @@ services: volumes: - ..:/workspace:cached # Runs app on the same network as the database container, allows "forwardPorts" in devcontainer.json function. - network_mode: service:db - + network_mode: service:mongodb # Uncomment the next line to use a non-root user for all processes. - user: node + # user: node # Use "forwardPorts" in **devcontainer.json** to forward an app port locally. # (Adding the "ports" property to this file will not forward from a Codespace.) - db: + mongodb: image: mongo:latest restart: unless-stopped volumes: @@ -32,6 +31,7 @@ services: MONGO_INITDB_ROOT_USERNAME: root MONGO_INITDB_ROOT_PASSWORD: root MONGO_INITDB_DATABASE: nodebb + # Add "forwardPorts": ["27017"] to **devcontainer.json** to forward MongoDB locally. # (Adding the "ports" property to this file will not forward from a Codespace.) diff --git a/.devcontainer/nodebb-db-init.js b/.devcontainer/nodebb-db-init.js index 050ed1a..4eb5c52 100644 --- a/.devcontainer/nodebb-db-init.js +++ b/.devcontainer/nodebb-db-init.js @@ -1 +1 @@ -db.createUser({user: "nodebb", pwd: "nodebb", roles: [{role: "readWrite", db: "nodebb", {role: "clusterMonitor", db: "admin"}]}); \ No newline at end of file +db.createUser({user: "nodebb", pwd: "nodebb", roles: [{role: "readWrite", db: "nodebb"}, {role: "clusterMonitor", db: "admin"}]}); \ No newline at end of file From 3ad4958b559e06764f7d2a19a3a583421ecf3e65 Mon Sep 17 00:00:00 2001 From: Opliko Date: Sun, 16 Jan 2022 18:35:50 +0100 Subject: [PATCH 04/10] feat: redirect log output to make nodebb logs work --- .devcontainer/devcontainer.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 9f57321..276a464 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -20,8 +20,8 @@ ], // Use 'postCreateCommand' to run commands after the container is created. "postCreateCommand": "node /opt/nodebb/nodebb setup --skip-build", - "postStartCommand": "yarn install && npm link && npm_name=$(node -p \"require('./package.json').name\") && cd /opt/nodebb && npm link $npm_name && /opt/nodebb/nodebb activate $npm_name && grunt -b /opt/nodebb --gruntfile /opt/nodebb/Gruntfile.js", + "postStartCommand": "yarn install && npm link && npm_name=$(node -p \"require('./package.json').name\") && cd /opt/nodebb && npm link $npm_name && /opt/nodebb/nodebb activate $npm_name && grunt -b /opt/nodebb --gruntfile /opt/nodebb/Gruntfile.js > /opt/nodebb/logs/output.log", // Comment out connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root. "remoteUser": "node", "overrideCommand": true -} \ No newline at end of file +} From f0f4d130986a3d352aa10ca47744667b652d60f7 Mon Sep 17 00:00:00 2001 From: Opliko Date: Sun, 16 Jan 2022 18:43:43 +0100 Subject: [PATCH 05/10] fix: chown config correctly --- .devcontainer/Dockerfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile index d2a8ce8..72a5f08 100644 --- a/.devcontainer/Dockerfile +++ b/.devcontainer/Dockerfile @@ -25,7 +25,7 @@ RUN sudo apt-get update && export DEBIAN_FRONTEND=noninteractive && sudo apt-get RUN yarn global add grunt-cli WORKDIR /opt/nodebb RUN git clone https://github.com/NodeBB/NodeBB /opt/nodebb -COPY ["./config.json", "/opt/nodebb/"] +COPY --chown=node:node ["./config.json", "/opt/nodebb/"] CMD grunt -b /opt/nodebb --gruntfile /opt/nodebb/Gruntfile.js -ENTRYPOINT grunt -b /opt/nodebb --gruntfile /opt/nodebb/Gruntfile.js \ No newline at end of file +ENTRYPOINT grunt -b /opt/nodebb --gruntfile /opt/nodebb/Gruntfile.js From cb80d62fd65697c482d5e260e158b524728aaedb Mon Sep 17 00:00:00 2001 From: Opliko Date: Sat, 18 Jun 2022 21:47:47 +0000 Subject: [PATCH 06/10] feat: move NodeBB installation to yarn --- .devcontainer/Dockerfile | 8 ++++++-- .devcontainer/config.json | 5 +++-- .devcontainer/devcontainer.json | 26 ++++++++++++++++++++------ .devcontainer/docker-compose.yml | 1 + 4 files changed, 30 insertions(+), 10 deletions(-) diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile index 72a5f08..060777c 100644 --- a/.devcontainer/Dockerfile +++ b/.devcontainer/Dockerfile @@ -4,7 +4,7 @@ FROM mcr.microsoft.com/vscode/devcontainers/javascript-node:0-${VARIANT} USER node -# Install MongoDB command line tools if on buster and x86_64 (arm64 not supported) +# Install MongoDB command line tools ARG MONGO_TOOLS_VERSION=5.0 RUN sudo apt-get update && export DEBIAN_FRONTEND=noninteractive && sudo apt-get install gnupg &&\ wget -qO - https://www.mongodb.org/static/pgp/server-${MONGO_TOOLS_VERSION}.asc | sudo apt-key add - &&\ @@ -21,11 +21,15 @@ RUN sudo apt-get update && export DEBIAN_FRONTEND=noninteractive && sudo apt-get # ARG EXTRA_NODE_VERSION=10 # RUN su node -c "source /usr/local/share/nvm/nvm.sh && nvm install ${EXTRA_NODE_VERSION}" -# [Optional] Uncomment if you want to install more global node modules +# install grunt globally RUN yarn global add grunt-cli + WORKDIR /opt/nodebb RUN git clone https://github.com/NodeBB/NodeBB /opt/nodebb COPY --chown=node:node ["./config.json", "/opt/nodebb/"] +# preemptively copy package.json, since to use yarn nconf will need to be installed before setup +RUN cp /opt/nodebb/install/package.json /opt/nodebb/package.json + CMD grunt -b /opt/nodebb --gruntfile /opt/nodebb/Gruntfile.js ENTRYPOINT grunt -b /opt/nodebb --gruntfile /opt/nodebb/Gruntfile.js diff --git a/.devcontainer/config.json b/.devcontainer/config.json index c5bbf6d..83132d6 100644 --- a/.devcontainer/config.json +++ b/.devcontainer/config.json @@ -1,5 +1,5 @@ { - "url": "http://127.0.0.1", + "url": "http://127.0.0.1:4567", "secret": "development-value-do-not-use-in-production", "database": "mongo", "mongo": { @@ -15,5 +15,6 @@ "email": "nodebb@example.com", "username": "nodebb", "password": "nodebb" - } + }, + "package_manager": "yarn" } diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 276a464..7cebf5b 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -2,25 +2,39 @@ // https://github.com/microsoft/vscode-dev-containers/tree/v0.208.0/containers/javascript-node-mongo // Update the VARIANT arg in docker-compose.yml to pick a Node.js version { - "name": "Node.js & Mongo DB", + "name": "NodeBB plugin", "dockerComposeFile": "docker-compose.yml", "service": "nodebb", "workspaceFolder": "/workspace", // Set *default* container specific settings.json values on container create. "settings": {}, - // Add the IDs of extensions you want installed when the container is created. + // Eslint extension is here since it integrates with the quickstart config + // MongoDB extension can be a useful alternative to `mongosh` for debugging "extensions": [ "dbaeumer.vscode-eslint", "mongodb.mongodb-vscode" ], - // Use 'forwardPorts' to make a list of ports inside the container available locally. + // Exposes NodeBB and MongoDB ports locally with labels "forwardPorts": [ 4567, 27017 ], - // Use 'postCreateCommand' to run commands after the container is created. - "postCreateCommand": "node /opt/nodebb/nodebb setup --skip-build", - "postStartCommand": "yarn install && npm link && npm_name=$(node -p \"require('./package.json').name\") && cd /opt/nodebb && npm link $npm_name && /opt/nodebb/nodebb activate $npm_name && grunt -b /opt/nodebb --gruntfile /opt/nodebb/Gruntfile.js > /opt/nodebb/logs/output.log", + "portsAttributes": { + "4567": { + "label": "NodeBB", + // show a notification when NodeBB is ready, useful since it can take a bit to set up + "onAutoForward": "notify" + }, + "27017": { + "label": "MongoDB", + "onAutoForward": "silent" + } + }, + // Install and setup NodeBB on workspace creation to speed up the setup. + // The build happens on startup anyway, so it can be skipped here + "onCreateCommand": "cd /opt/nodebb && yarn install && node /opt/nodebb/nodebb setup --skip-build", + // prepare the plugin and link it to NodeBB, then start NodeBB using grunt so it rebuilds on changes + "postStartCommand": "yarn install && yarn link && npm_name=$(node -p \"require('./package.json').name\") && cd /opt/nodebb && yarn link $npm_name && /opt/nodebb/nodebb activate $npm_name && grunt -b /opt/nodebb --gruntfile /opt/nodebb/Gruntfile.js > /opt/nodebb/logs/output.log", // Comment out connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root. "remoteUser": "node", "overrideCommand": true diff --git a/.devcontainer/docker-compose.yml b/.devcontainer/docker-compose.yml index d37015d..c831bd2 100644 --- a/.devcontainer/docker-compose.yml +++ b/.devcontainer/docker-compose.yml @@ -25,6 +25,7 @@ services: restart: unless-stopped volumes: - mongodb-data:/data/db + # script that creates the nodebb user in nodebb database - ./nodebb-db-init.js:/docker-entrypoint-initdb.d/nodebb-db-init.js # Uncomment to change startup options environment: From b618dd01d6aedc4d8cce15b26924924361aaf47c Mon Sep 17 00:00:00 2001 From: Opliko Date: Sat, 18 Jun 2022 22:26:29 +0000 Subject: [PATCH 07/10] feat: add updateContentCommand speed up prebuilds --- .devcontainer/devcontainer.json | 1 + 1 file changed, 1 insertion(+) diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 7cebf5b..5188a0d 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -33,6 +33,7 @@ // Install and setup NodeBB on workspace creation to speed up the setup. // The build happens on startup anyway, so it can be skipped here "onCreateCommand": "cd /opt/nodebb && yarn install && node /opt/nodebb/nodebb setup --skip-build", + "updateContentCommand": "yarn install", // prepare the plugin and link it to NodeBB, then start NodeBB using grunt so it rebuilds on changes "postStartCommand": "yarn install && yarn link && npm_name=$(node -p \"require('./package.json').name\") && cd /opt/nodebb && yarn link $npm_name && /opt/nodebb/nodebb activate $npm_name && grunt -b /opt/nodebb --gruntfile /opt/nodebb/Gruntfile.js > /opt/nodebb/logs/output.log", // Comment out connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root. From 9c1560652594e0631056203a562bf7677e3e2ffc Mon Sep 17 00:00:00 2001 From: Opliko Date: Sat, 18 Jun 2022 22:28:04 +0000 Subject: [PATCH 08/10] fix: also ensure activation on content update --- .devcontainer/devcontainer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 5188a0d..20e5260 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -33,7 +33,7 @@ // Install and setup NodeBB on workspace creation to speed up the setup. // The build happens on startup anyway, so it can be skipped here "onCreateCommand": "cd /opt/nodebb && yarn install && node /opt/nodebb/nodebb setup --skip-build", - "updateContentCommand": "yarn install", + "updateContentCommand": "yarn install && yarn link && npm_name=$(node -p \"require('./package.json').name\") && cd /opt/nodebb && yarn link $npm_name && /opt/nodebb/nodebb activate $npm_name", // prepare the plugin and link it to NodeBB, then start NodeBB using grunt so it rebuilds on changes "postStartCommand": "yarn install && yarn link && npm_name=$(node -p \"require('./package.json').name\") && cd /opt/nodebb && yarn link $npm_name && /opt/nodebb/nodebb activate $npm_name && grunt -b /opt/nodebb --gruntfile /opt/nodebb/Gruntfile.js > /opt/nodebb/logs/output.log", // Comment out connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root. From 43d806f1fda9938044debf31de8d6a4ef479003a Mon Sep 17 00:00:00 2001 From: Opliko Date: Tue, 21 Jun 2022 17:40:07 +0000 Subject: [PATCH 09/10] docs: add devcontainer documentation --- .devcontainer/README.md | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 .devcontainer/README.md diff --git a/.devcontainer/README.md b/.devcontainer/README.md new file mode 100644 index 0000000..6dbc409 --- /dev/null +++ b/.devcontainer/README.md @@ -0,0 +1,30 @@ +# Plugin devcontainer configuration +This Visual Studio Code devcontianer configuration will set up NodeBB, then link and activate the developed plugin to it. The server will rebuild and restart on any changes to the plugin. + +Additionally it includes MongoDB tools ([MongoDB Shell (`mongosh`)](https://www.mongodb.com/docs/mongodb-shell/) and [MongoDB Database Tools](https://www.mongodb.com/docs/database-tools/)) in case viewing or modifying the database manually is needed. + +## Credentials +Default credentials for NodeBB and MongoDB (for `nodebb` database) are simply `nodebb:nodebb` (username:password). MongoDB root user is `root:root`. + +## Paths and ports +NodeBB is installed under `/opt/nodebb`. By defualt it should be exposed under port `4567` on your host, however VSCode will choose another port if that one is taken. +MongoDB is using a separate container in the same network. By defualt it should be exposed under port `27017` on your host, however VSCode will choose another port if that one is taken. + +The plugin will be mounted under `/workspaces`. + +## How to run + +### Locally +You can use the [Remote - Containers](vscode:extension/ms-vscode-remote.remote-containers) Visual Studio Code extension and run the `Remote-Containers: Open Folder in Container...` command to select your plugin folder, or use `Remote-Containers: Reopen in Container` if you already have the folder open in VS Code. + +### SSH host +You can also self-host a remote container using the [Remote - SSH](vscode:extension/ms-vscode-remote.remote-ssh) extension. See Visual Studio Code documentation [here](https://code.visualstudio.com/docs/remote/containers#_open-a-folder-on-a-remote-ssh-host-in-a-container). + +### In Codespaces +Simply select `Codespaces` under the `Code` button in GitHub UI and create a new codespace. Alternatively, run `Codespaces: Create New Codespace` command in Visual Studio Code. + +## Quirks + +- Currently the only way to restart NodeBB is to activate the grunt file watcher by changing a plugin or NodeBB file +- NodeBB is configured with `http://127.0.0.1:4567` as its URL. Even if it doesn't match the actual URL you use it usually doesn't matter, however it can cause issues with certain types of plugins. This value can be changed in `/opt/nodebb/config.json`. Since `config.json` isn't watched by grunt it will require forcing a restart using the aformentioned method (changing another, actually watched file) +- Building the codespace will take a few minutes for NodeBB installation. On GitHub Codespaces this time can be greatly reduced by using [Codespaces Prebuilds](https://docs.github.com/en/codespaces/prebuilding-your-codespaces/about-codespaces-prebuilds). \ No newline at end of file From 040d499c7d4f3503e42622774cc1e3c661e79f28 Mon Sep 17 00:00:00 2001 From: Opliko Date: Thu, 11 Aug 2022 21:49:53 +0200 Subject: [PATCH 10/10] fix: add -y to apt-get for gnupg --- .devcontainer/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile index 060777c..71b2104 100644 --- a/.devcontainer/Dockerfile +++ b/.devcontainer/Dockerfile @@ -6,7 +6,7 @@ USER node # Install MongoDB command line tools ARG MONGO_TOOLS_VERSION=5.0 -RUN sudo apt-get update && export DEBIAN_FRONTEND=noninteractive && sudo apt-get install gnupg &&\ +RUN sudo apt-get update && export DEBIAN_FRONTEND=noninteractive && sudo apt-get install -y gnupg &&\ wget -qO - https://www.mongodb.org/static/pgp/server-${MONGO_TOOLS_VERSION}.asc | sudo apt-key add - &&\ echo "deb [arch=$(dpkg --print-architecture)] http://repo.mongodb.org/apt/debian $(lsb_release -cs)/mongodb-org/${MONGO_TOOLS_VERSION} main" | sudo tee /etc/apt/sources.list.d/mongodb-org-${MONGO_TOOLS_VERSION}.list &&\ sudo apt-get update && export DEBIAN_FRONTEND=noninteractive &&\