From ed9ff70fe2844059009e2be26706abf466d805a9 Mon Sep 17 00:00:00 2001 From: David Mang Date: Sun, 1 Sep 2024 15:48:09 +0200 Subject: [PATCH] Change server dockerfile to adjust to folder structure --- .github/workflows/build_docker.yml | 3 +++ docker/client/Dockerfile | 2 ++ docker/server/Dockerfile | 19 +++++++++++++++---- server/insights/views.py | 1 + 4 files changed, 21 insertions(+), 4 deletions(-) diff --git a/.github/workflows/build_docker.yml b/.github/workflows/build_docker.yml index 2b4ad43..cfcf943 100644 --- a/.github/workflows/build_docker.yml +++ b/.github/workflows/build_docker.yml @@ -84,6 +84,9 @@ jobs: platforms: linux/amd64,linux/arm64 push: true tags: ${{ steps.meta.outputs.tags }} + build-args: | + "VITE_API_URL=${{ var.VITE_API_URL }}" + "VITE_ENABLE_TRACKING"=${{ var.VITE_ENABLE_TRACKING }}" - id: output-tag-client run: | diff --git a/docker/client/Dockerfile b/docker/client/Dockerfile index 24d8c22..e4e1452 100644 --- a/docker/client/Dockerfile +++ b/docker/client/Dockerfile @@ -1,8 +1,10 @@ FROM node:alpine ARG VITE_API_URL +ARG VITE_ENABLE_TRACKING ENV VITE_API_URL=$VITE_API_URL +ENV VITE_ENABLE_TRACKING=$VITE_ENABLE_TRACKING WORKDIR /client diff --git a/docker/server/Dockerfile b/docker/server/Dockerfile index 7485c71..5d3ebfe 100644 --- a/docker/server/Dockerfile +++ b/docker/server/Dockerfile @@ -1,14 +1,25 @@ +# Use Python slim image FROM python:3.12.4-slim-bookworm +# Set the working directory inside the Docker image WORKDIR /server -COPY ../../server . +# Copy only the requirements first to leverage caching +COPY ../../server/requirements.txt . +# Create and activate the virtual environment, then install dependencies RUN python3 -m venv /opt/venv && \ /opt/venv/bin/pip install --upgrade pip && \ - /opt/venv/bin/pip install -r requirements.txt --no-cache-dir && \ - chmod +x /server/entrypoint.sh + /opt/venv/bin/pip install -r requirements.txt --no-cache-dir + +# Copy the rest of the server code into the Docker image +COPY ../../server . + +# Ensure entrypoint script has execute permissions +RUN chmod +x /server/entrypoint.sh +# Expose the application port EXPOSE 8000 -CMD [ "/server/entrypoint.sh" ] \ No newline at end of file +# Run the entrypoint script +CMD [ "/server/entrypoint.sh" ] diff --git a/server/insights/views.py b/server/insights/views.py index d6fcfe6..82db368 100644 --- a/server/insights/views.py +++ b/server/insights/views.py @@ -19,6 +19,7 @@ import datetime from django.contrib.postgres.aggregates import StringAgg +# Get current date and time now_ = now() class TotalChatsView(APIView):