Skip to content

Commit bcd7692

Browse files
ljm42“ljm42”
andauthored
Add optional VS Code devcontainer (#477)
Before Submitting This PR, Please Ensure You Have Completed The Following: 1. [ ] Are internal links to wiki documents using [relative file links](https://docusaurus.io/docs/markdown-features/links)? 2. [ ] Are all new documentation files lowercase, with dash separated names (ex. unraid-os.mdx)? 3. [ ] Are all assets (images, etc), located in an assets/ subfolder next to the .md/mdx files? 4. [ ] Have you checked to ensure there aren't other open [Pull Requests](../../../pulls) for the same update/change? 5. [ ] Is the build succeeding? <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit ## Release Notes * **New Features** * Added VS Code Dev Container support for streamlined local development with pre-configured Node.js environment, package manager, and documentation server. * **Documentation** * Added getting started guide for Dev Container setup including Git credentials sharing. * **Chores** * Updated build scripts and development configuration. <!-- review_stack_entry_start --> [![Review Change Stack](https://storage.googleapis.com/coderabbit_public_assets/review-stack-in-coderabbit-ui.svg)](https://app.coderabbit.ai/change-stack/unraid/docs/pull/477) <!-- review_stack_entry_end --> <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Co-authored-by: “ljm42” <“larry_meaney@iname.com”>
1 parent 000c2b9 commit bcd7692

6 files changed

Lines changed: 187 additions & 2 deletions

File tree

.devcontainer/Dockerfile

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
FROM node:24.15.0-bookworm
2+
3+
ENV COREPACK_ENABLE_DOWNLOAD_PROMPT=0
4+
ENV DEBIAN_FRONTEND=noninteractive
5+
ARG ACTIONLINT_VERSION=1.7.12
6+
7+
RUN apt-get update \
8+
&& apt-get install -y --no-install-recommends \
9+
bash-completion \
10+
build-essential \
11+
ca-certificates \
12+
curl \
13+
dnsutils \
14+
findutils \
15+
gawk \
16+
gh \
17+
git \
18+
git-lfs \
19+
iputils-ping \
20+
jq \
21+
less \
22+
lsof \
23+
netcat-openbsd \
24+
nvi \
25+
openssh-client \
26+
pkg-config \
27+
procps \
28+
python3 \
29+
ripgrep \
30+
rsync \
31+
shellcheck \
32+
sudo \
33+
tree \
34+
unzip \
35+
xz-utils \
36+
zip \
37+
&& rm -rf /var/lib/apt/lists/*
38+
39+
RUN set -eux; \
40+
case "$(uname -m)" in \
41+
x86_64) actionlint_arch="amd64"; actionlint_sha256="8aca8db96f1b94770f1b0d72b6dddcb1ebb8123cb3712530b08cc387b349a3d8" ;; \
42+
aarch64|arm64) actionlint_arch="arm64"; actionlint_sha256="325e971b6ba9bfa504672e29be93c24981eeb1c07576d730e9f7c8805afff0c6" ;; \
43+
*) echo "Unsupported actionlint architecture: $(uname -m)" >&2; exit 1 ;; \
44+
esac; \
45+
curl -fsSL "https://github.com/rhysd/actionlint/releases/download/v${ACTIONLINT_VERSION}/actionlint_${ACTIONLINT_VERSION}_linux_${actionlint_arch}.tar.gz" -o /tmp/actionlint.tar.gz; \
46+
echo "${actionlint_sha256} /tmp/actionlint.tar.gz" | sha256sum -c -; \
47+
tar -xzf /tmp/actionlint.tar.gz -C /usr/local/bin actionlint; \
48+
chmod +x /usr/local/bin/actionlint; \
49+
rm /tmp/actionlint.tar.gz
50+
51+
RUN corepack enable \
52+
&& corepack prepare pnpm@10.33.2 --activate \
53+
&& usermod -l vscode node \
54+
&& groupmod -n vscode node \
55+
&& usermod -d /home/vscode -m vscode \
56+
&& usermod -aG sudo vscode \
57+
&& echo 'vscode ALL=(ALL) NOPASSWD:ALL' > /etc/sudoers.d/90-vscode \
58+
&& chmod 0440 /etc/sudoers.d/90-vscode \
59+
&& mkdir -p /workspaces/docs \
60+
&& chown -R vscode:vscode /workspaces /home/vscode
61+
62+
WORKDIR /workspaces/docs

.devcontainer/devcontainer.json

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
{
2+
"name": "docs",
3+
"build": {
4+
"dockerfile": "Dockerfile"
5+
},
6+
"remoteUser": "vscode",
7+
"workspaceFolder": "/workspaces/${localWorkspaceFolderBasename}",
8+
"containerEnv": {
9+
"COREPACK_ENABLE_DOWNLOAD_PROMPT": "0",
10+
"DOCUSAURUS_BIND_HOST": "0.0.0.0"
11+
},
12+
"remoteEnv": {
13+
"DOCUSAURUS_BIND_HOST": "0.0.0.0"
14+
},
15+
"mounts": [
16+
"source=gh-config,target=/home/vscode/.config/gh,type=volume"
17+
],
18+
"postCreateCommand": "sudo chown -R vscode:vscode /home/vscode/.config && corepack enable && pnpm install --store-dir /home/vscode/.local/share/pnpm/store --frozen-lockfile --prefer-offline",
19+
"postStartCommand": "sudo chown -R vscode:vscode /home/vscode/.config",
20+
"forwardPorts": [
21+
3000,
22+
3001
23+
],
24+
"portsAttributes": {
25+
"3000": {
26+
"label": "Docusaurus static preview",
27+
"onAutoForward": "notify"
28+
},
29+
"3001": {
30+
"label": "Docusaurus",
31+
"onAutoForward": "notify"
32+
}
33+
},
34+
"customizations": {
35+
"vscode": {
36+
"extensions": [
37+
"davidanson.vscode-markdownlint",
38+
"esbenp.prettier-vscode",
39+
"github.vscode-github-actions",
40+
"redhat.vscode-yaml",
41+
"unifiedjs.vscode-mdx"
42+
],
43+
"settings": {
44+
"typescript.tsdk": "node_modules/typescript/lib"
45+
}
46+
}
47+
}
48+
}

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# Dependencies
22
/node_modules
3+
.pnpm-store/
34

45
# Production
56
/build

README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,22 @@ nvm use
127127
pnpm install
128128
```
129129

130+
### Optional: VS Code Dev Container
131+
132+
This repo includes a VS Code dev container for contributors who want a local environment that closely matches the GitHub Actions Ubuntu/Node/pnpm setup.
133+
134+
To use it:
135+
136+
1. Install [Docker Desktop](https://www.docker.com/products/docker-desktop/) or another compatible container runtime.
137+
2. Install the [Dev Containers extension](https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-containers) for VS Code.
138+
3. Open this repo in VS Code and choose **Dev Containers: Reopen in Container**.
139+
140+
The container uses the Node.js version from `.nvmrc`, enables Corepack/pnpm, installs repo dependencies, forwards the Docusaurus dev server on port `3001`, and includes useful CLI tools such as `git`, `gh`, `jq`, `ripgrep`, `nvi`, `shellcheck`, and `actionlint`.
141+
142+
Once the container is ready, see [Usage](#usage) for local development commands.
143+
144+
VS Code Dev Containers can share host Git credentials with the container. See [Sharing Git credentials with your container](https://code.visualstudio.com/remote/advancedcontainers/sharing-git-credentials) for SSH agent and credential-helper setup. GitHub CLI authentication is separate; run `gh auth login` inside the container if you need authenticated `gh` commands. The container stores GitHub CLI config in a Docker named volume (`gh-config`) so `gh` authentication can persist across dev container rebuilds and can be shared with other dev containers on the same Docker engine.
145+
130146
<p align="right">(<a href="#readme-top">back to top</a>)</p>
131147

132148
<!-- USAGE EXAMPLES -->

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@
44
"private": true,
55
"scripts": {
66
"docusaurus": "docusaurus",
7-
"start": "docusaurus start --port 3001",
7+
"start": "node scripts/run-docusaurus.mjs start",
88
"build": "docusaurus build",
99
"swizzle": "docusaurus swizzle",
1010
"deploy": "docusaurus deploy",
1111
"clear": "docusaurus clear",
12-
"serve": "docusaurus serve",
12+
"serve": "node scripts/run-docusaurus.mjs serve",
1313
"write-heading-ids": "docusaurus write-heading-ids",
1414
"typecheck": "tsc",
1515
"lint:mdx": "remark . --ext .md,.mdx --quiet --frail",

scripts/run-docusaurus.mjs

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
#!/usr/bin/env node
2+
3+
import { spawn } from "node:child_process";
4+
5+
const commandName = process.argv[2];
6+
const defaultPorts = {
7+
serve: "3000",
8+
start: "3001",
9+
};
10+
11+
if (!Object.hasOwn(defaultPorts, commandName)) {
12+
console.error("Usage: node scripts/run-docusaurus.mjs <start|serve>");
13+
process.exit(1);
14+
}
15+
16+
// Docusaurus defaults to localhost, which is right for direct local runs.
17+
// Dev containers set DOCUSAURUS_BIND_HOST=0.0.0.0 so VS Code/Docker can
18+
// forward container ports for both the dev server and static preview server.
19+
const host = process.env.DOCUSAURUS_BIND_HOST || "localhost";
20+
const port = process.env.DOCUSAURUS_PORT || defaultPorts[commandName];
21+
const command = process.platform === "win32" ? "pnpm.cmd" : "pnpm";
22+
const passthroughArgs = process.argv.slice(3);
23+
24+
console.log(`Starting Docusaurus ${commandName} on ${host}:${port}`);
25+
26+
const child = spawn(
27+
command,
28+
[
29+
"exec",
30+
"docusaurus",
31+
commandName,
32+
"--host",
33+
host,
34+
"--port",
35+
port,
36+
...passthroughArgs,
37+
],
38+
{
39+
stdio: "inherit",
40+
},
41+
);
42+
43+
for (const signal of ["SIGINT", "SIGTERM"]) {
44+
process.on(signal, () => {
45+
if (!child.killed) {
46+
child.kill(signal);
47+
}
48+
});
49+
}
50+
51+
child.on("exit", (code, signal) => {
52+
if (signal) {
53+
process.kill(process.pid, signal);
54+
return;
55+
}
56+
57+
process.exit(code ?? 1);
58+
});

0 commit comments

Comments
 (0)