Skip to content

Commit 6e3dfdd

Browse files
committed
Pythonパッケージのインストールをnonrootで行う
1 parent 3bf2acc commit 6e3dfdd

1 file changed

Lines changed: 22 additions & 10 deletions

File tree

Dockerfile

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@ WORKDIR /usr/src/app
1818

1919
COPY .npmrc .npmrc
2020
COPY requirements.txt requirements.txt
21-
COPY pyproject.toml pyproject.toml
22-
COPY uv.lock uv.lock
2321
COPY package.json package.json
2422
COPY package-lock.json package-lock.json
2523

@@ -37,21 +35,35 @@ RUN apt-get update && \
3735
apt-get update && \
3836
apt-get install -y --no-install-recommends nodejs && \
3937
pip install -r requirements.txt --no-cache-dir && \
40-
if [ "${ENV}" = 'dev' ]; then \
41-
uv sync --frozen --dev; \
42-
else \
43-
uv sync --frozen; \
44-
fi && \
4538
npm install && \
46-
pip uninstall -y uv virtualenv && \
47-
apt-get remove -y git gcc libc6-dev gnupg && \
39+
apt-get remove -y gcc libc6-dev gnupg && \
4840
apt-get autoremove -y && \
4941
apt-get clean && \
50-
rm -rf /var/lib/apt/lists ~/.cache /tmp /root/.npm /usr/src/app/node_modules/re2/.github/actions/*/Dockerfile && \
42+
rm -rf /var/lib/apt/lists ~/.cache /tmp/* /root/.npm /usr/src/app/node_modules/re2/.github/actions/*/Dockerfile && \
5143
find / -type f -perm /u+s -ignore_readdir_race -not -path '/sys/devices/virtual/powercap/*' -exec chmod u-s {} \; && \
5244
find / -type f -perm /g+s -ignore_readdir_race -not -path '/sys/devices/virtual/powercap/*' -exec chmod g-s {} \; && \
5345
useradd -l -m -s /bin/bash -N -u "1000" "nonroot" && \
5446
chown -R nonroot /usr/src/app
47+
48+
USER nonroot
49+
50+
COPY pyproject.toml pyproject.toml
51+
COPY uv.lock uv.lock
52+
53+
RUN if [ "${ENV}" = 'dev' ]; then \
54+
uv sync --frozen --dev; \
55+
else \
56+
uv sync --frozen; \
57+
fi
58+
59+
USER root
60+
61+
RUN pip uninstall -y uv virtualenv && \
62+
apt-get remove -y git && \
63+
apt-get autoremove -y && \
64+
apt-get clean && \
65+
rm -rf /var/lib/apt/lists ~/.cache /tmp
66+
5567
USER nonroot
5668

5769
ENV PATH="/usr/src/app/.venv/bin:$PATH"

0 commit comments

Comments
 (0)