소스 검색

dockerfile enhancement

tanlie 4 일 전
부모
커밋
d5ca27b948
2개의 변경된 파일12개의 추가작업 그리고 5개의 파일을 삭제
  1. 11 4
      Dockerfile
  2. 1 1
      docker-compose.yaml

+ 11 - 4
Dockerfile

@@ -1,17 +1,24 @@
+# syntax=docker/dockerfile:1.4
 FROM python:3.12-slim
 
+# Allow configuring a faster pip index at build time (default: TUNA mirror)
+ARG PIP_INDEX_URL=https://pypi.tuna.tsinghua.edu.cn/simple
 ENV PYTHONDONTWRITEBYTECODE=1 \
     PYTHONUNBUFFERED=1 \
-    PIP_NO_CACHE_DIR=1
+    PIP_INDEX_URL=$PIP_INDEX_URL
 
 WORKDIR /app
 
+# Copy only requirements first to maximise layer cache
 COPY requirements.txt ./
-RUN python -m pip install --upgrade pip \
-    && python -m pip install --no-cache-dir -r requirements.txt
+
+# Use BuildKit cache mount for pip to avoid re-downloading wheels between builds.
+# Build with: DOCKER_BUILDKIT=1 docker build --build-arg PIP_INDEX_URL=... -t ginger .
+RUN --mount=type=cache,target=/root/.cache/pip \
+    python -m pip install --upgrade pip setuptools wheel && \
+    python -m pip install --prefer-binary -r requirements.txt
 
 COPY . .
 
 EXPOSE 5000
-
 CMD ["uwsgi", "--ini", "/app/uwsgi.ini"]

+ 1 - 1
docker-compose.yaml

@@ -11,7 +11,7 @@ services:
       MYSQL_HOST: ${MYSQL_HOST:-host.docker.internal}
       MYSQL_PORT: ${MYSQL_PORT:-3306}
       MYSQL_USER: ${MYSQL_USER:-root}
-      MYSQL_PASSWORD: ${MYSQL_PASSWORD:-}
+      MYSQL_PASSWORD: ${MYSQL_PASSWORD:-@@qinys12346..}
       MYSQL_DB: ${MYSQL_DB:-flask}
       MYSQL_CHARSET: utf8mb4
     extra_hosts: