From 04d89b53cc305eda70c43cf00802fedf377daa5b Mon Sep 17 00:00:00 2001 From: Junwei Zhao Date: Mon, 4 Nov 2024 20:21:39 +1100 Subject: [PATCH] Update --- Dockerfile | 16 +++++++++++++--- k8s/manifest.yaml | 16 ++++++++++++++++ 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/Dockerfile b/Dockerfile index ba74916..ac89cd6 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,11 +1,12 @@ FROM ghcr.io/astral-sh/uv:bookworm-slim AS uv -FROM python:3.12-slim +FROM python:3.12 as dev # Set environment variables ENV PYTHONDONTWRITEBYTECODE 1 ENV PYTHONUNBUFFERED 1 ENV PYTHONPATH /app +ENV UV_CACHE_DIR /app/.cache/uv # Set work directory WORKDIR /app @@ -25,10 +26,12 @@ RUN apt-get update && apt-get install -y \ COPY --from=uv /usr/local/bin/uv /usr/local/bin/uv +# Create cache directory with proper permissions +RUN mkdir -p /app/.cache/uv && chmod -R 777 /app/.cache + RUN which uv \ && uv sync --no-dev - # Copy project COPY . . @@ -42,7 +45,14 @@ RUN uv run manage.py collectstatic --noinput RUN uv run manage.py compilemessages --locale=zh_Hans # Create data directory for SQLite database RUN mkdir -p /app/data && chmod 777 /app/data + +FROM python:3.12-slim + +COPY --from=uv /usr/local/bin/uv /usr/local/bin/uv +COPY --from=dev /app /app + +WORKDIR /app # Expose port 8000 EXPOSE 8000 # Run the application -CMD ["uv", "run", "gunicorn", "--chdir", "/app", "url_manager.wsgi:application", "--bind", "0.0.0.0:8000"] +CMD ["uv", "run", "gunicorn", "--chdir", "/app", "core.wsgi:application", "--bind", "0.0.0.0:8000"] diff --git a/k8s/manifest.yaml b/k8s/manifest.yaml index 9d1429d..c8108ba 100644 --- a/k8s/manifest.yaml +++ b/k8s/manifest.yaml @@ -33,6 +33,8 @@ spec: - name: data persistentVolumeClaim: claimName: links-pvc + - name: cache + emptyDir: {} initContainers: - name: links-init image: "ghcr.io/wahyd4/links:main" @@ -49,6 +51,8 @@ spec: volumeMounts: - name: data mountPath: /app/data + - name: cache + mountPath: /app/.cache env: - name: DB_HOST value: new-postgres-postgresql.db.svc.cluster.local @@ -65,6 +69,8 @@ spec: value: "redis://redis-master.db.svc.cluster.local:6379" - name: CELERY_RESULT_BACKEND value: "redis://redis-master.db.svc.cluster.local:6379" + - name: UV_CACHE_DIR + value: "/app/.cache/uv" ports: - containerPort: 8000 name: links-port @@ -180,6 +186,8 @@ spec: - name: data persistentVolumeClaim: claimName: links-pvc + - name: cache + emptyDir: {} containers: - name: celery-worker image: "ghcr.io/wahyd4/links:main" @@ -190,6 +198,8 @@ spec: volumeMounts: - name: data mountPath: /app/data + - name: cache + mountPath: /app/.cache env: - name: DB_HOST value: new-postgres-postgresql.db.svc.cluster.local @@ -201,6 +211,8 @@ spec: value: "redis://redis-master.db.svc.cluster.local:6379" - name: CELERY_RESULT_BACKEND value: "redis://redis-master.db.svc.cluster.local:6379" + - name: UV_CACHE_DIR + value: "/app/.cache/uv" resources: requests: cpu: 100m @@ -218,6 +230,8 @@ spec: volumeMounts: - name: data mountPath: /app/data + - name: cache + mountPath: /app/.cache env: - name: DB_HOST value: new-postgres-postgresql.db.svc.cluster.local @@ -229,6 +243,8 @@ spec: value: "redis://redis-master.db.svc.cluster.local:6379" - name: CELERY_RESULT_BACKEND value: "redis://redis-master.db.svc.cluster.local:6379" + - name: UV_CACHE_DIR + value: "/app/.cache/uv" resources: requests: cpu: 100m