From ba8fcee8ada01e1bce88a1c9bb76c3f2a27faa51 Mon Sep 17 00:00:00 2001 From: Bilal Qamar <59555732+BilalQamar95@users.noreply.github.com> Date: Wed, 16 Oct 2024 17:58:17 +0500 Subject: [PATCH] perf: updated Dockerfile to optimize requirements installation and dependency caching --- .github/workflows/push-edx-analytics-dashboard-image.yaml | 5 +++++ dockerfiles/edx-analytics-dashboard.Dockerfile | 8 ++++++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/.github/workflows/push-edx-analytics-dashboard-image.yaml b/.github/workflows/push-edx-analytics-dashboard-image.yaml index 6bf61fa..7d256ab 100644 --- a/.github/workflows/push-edx-analytics-dashboard-image.yaml +++ b/.github/workflows/push-edx-analytics-dashboard-image.yaml @@ -9,6 +9,11 @@ on: schedule: - cron: "0 4 * * 1-5" # UTC Time +# Added for testing purposes. Will remove once the PR is finalised + pull_request: + branches: + - '**' + jobs: build-and-push-image: runs-on: ubuntu-latest diff --git a/dockerfiles/edx-analytics-dashboard.Dockerfile b/dockerfiles/edx-analytics-dashboard.Dockerfile index 2ed0d9d..357f8d9 100644 --- a/dockerfiles/edx-analytics-dashboard.Dockerfile +++ b/dockerfiles/edx-analytics-dashboard.Dockerfile @@ -51,8 +51,8 @@ ENV PYTHON_VERSION "${PYTHON_VERSION}" RUN curl -sS https://bootstrap.pypa.io/get-pip.py | python${PYTHON_VERSION} RUN pip install virtualenv -# cloning git repo -RUN curl -L https://github.com/edx/edx-analytics-dashboard//archive/refs/heads/master.tar.gz | tar -xz --strip-components=1 +# Create required directories for requirements +RUN mkdir -p requirements # No need to activate insights virtualenv as it is already activated by putting in the path RUN virtualenv -p python${PYTHON_VERSION} --always-copy ${INSIGHTS_VENV_DIR} @@ -60,8 +60,11 @@ RUN virtualenv -p python${PYTHON_VERSION} --always-copy ${INSIGHTS_VENV_DIR} ENV PATH="${INSIGHTS_CODE_DIR}/node_modules/.bin:$PATH" # insights service config commands below +RUN curl -L -o requirements/production.txt https://raw.githubusercontent.com/edx/edx-analytics-dashboard/master/requirements/production.txt RUN pip install --no-cache-dir -r requirements/production.txt +RUN curl -L https://github.com/edx/edx-analytics-dashboard/archive/refs/heads/master.tar.gz | tar -xz --strip-components=1 + RUN nodeenv ${INSIGHTS_NODEENV_DIR} --node=18.20.2 --prebuilt \ && npm install -g npm@10.5.x @@ -72,6 +75,7 @@ EXPOSE 18110 FROM app as dev +RUN curl -L -o requirements/local.txt https://raw.githubusercontent.com/edx/edx-analytics-dashboard/master/requirements/local.txt RUN pip install --no-cache-dir -r requirements/local.txt ENV DJANGO_SETTINGS_MODULE "analytics_dashboard.settings.devstack"