Skip to content

Commit b565060

Browse files
authored
Fix devcontainer to non root user (#86)
Signed-off-by: Shunsuke Kimura <[email protected]>
1 parent 41be5a3 commit b565060

File tree

3 files changed

+19
-16
lines changed

3 files changed

+19
-16
lines changed

.devcontainer/Dockerfile

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,22 @@
1-
# Rust v1.77 as a base image
21
FROM rust:1.77-slim
32

4-
RUN apt-get update && \
5-
apt-get install -y --no-install-recommends \
6-
git openssh-client \
7-
curl \
8-
# install python3, jinja2 pyyaml
9-
python3 \
10-
python3-pip \
3+
ARG USERNAME=typst-jp
4+
ARG USER_UID=1000
5+
ARG USER_GID=$USER_UID
6+
7+
RUN groupadd --gid $USER_GID $USERNAME \
8+
&& useradd --uid $USER_UID --gid $USER_GID -m $USERNAME \
9+
&& chsh -s /bin/bash $USERNAME \
10+
&& apt-get update \
11+
&& apt-get install -y --no-install-recommends \
12+
git \
13+
openssh-client \
14+
python3 \
15+
python3-pip \
1116
&& python3 -m pip install --break-system-packages jinja2 PyYAML \
12-
# install nodejs and serve
13-
&& curl -fsSL https://deb.nodesource.com/setup_20.x | bash - \
14-
&& apt-get install -y nodejs \
15-
&& npm install -g [email protected] \
1617
&& apt-get clean \
17-
&& rm -rf /var/lib/apt/lists/* \
18+
&& rm -rf /var/lib/apt/lists/*
1819

1920
WORKDIR /workspace
2021
ENV PATH="/root/.cargo/bin:${PATH}"
22+
USER $USERNAME

.devcontainer/devcontainer.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@
44
"dockerfile": "Dockerfile",
55
"context": ".."
66
},
7-
"forwardPorts": [3000],
7+
"remoteUser": "typst-jp",
88
"workspaceMount": "source=${localWorkspaceFolder},target=/workspace,type=bind,consistency=cached",
99
"workspaceFolder": "/workspace",
10-
"postStartCommand": "cargo test --package typst-docs --lib -- tests::test_docs --exact --nocapture && python3 ./gen.py && npx serve -n ./dist"
10+
"postStartCommand": "cargo test --package typst-docs --lib -- tests::test_docs --exact --nocapture && python3 ./gen.py && python3 -m http.server -d dist",
11+
"postCreateCommand": "git config --global --add safe.directory ${containerWorkspaceFolder}"
1112
}

.vscode/tasks.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
{
55
"label": "gen: typst-jp documentation",
66
"type": "shell",
7-
"command": "cargo test --package typst-docs --lib -- tests::test_docs --exact --nocapture && python3 ./gen.py && echo reload or open http://localhost:3000",
7+
"command": "cargo test --package typst-docs --lib -- tests::test_docs --exact --nocapture && python3 ./gen.py && echo reload or open http://localhost:8000",
88
"problemMatcher": []
99
}
1010
]

0 commit comments

Comments
 (0)