From 04264cbbd8eebaa5548d50cd62d0e4a6f71d70bd Mon Sep 17 00:00:00 2001 From: Bilal Qamar <59555732+BilalQamar95@users.noreply.github.com> Date: Wed, 16 Oct 2024 16:28:14 +0500 Subject: [PATCH] perf: updated Dockerfile to optimize requirements installation and dependency caching --- .../workflows/push-enterprise-subsidy-image.yaml | 5 +++++ dockerfiles/enterprise-subsidy.Dockerfile | 13 ++++++++++--- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/.github/workflows/push-enterprise-subsidy-image.yaml b/.github/workflows/push-enterprise-subsidy-image.yaml index cb59967..52541d2 100644 --- a/.github/workflows/push-enterprise-subsidy-image.yaml +++ b/.github/workflows/push-enterprise-subsidy-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/enterprise-subsidy.Dockerfile b/dockerfiles/enterprise-subsidy.Dockerfile index 573c3f2..922e1d8 100644 --- a/dockerfiles/enterprise-subsidy.Dockerfile +++ b/dockerfiles/enterprise-subsidy.Dockerfile @@ -54,7 +54,7 @@ RUN apt-get update && apt-get -qy install --no-install-recommends \ python3-pip \ python${PYTHON_VERSION} \ python${PYTHON_VERSION}-dev \ - python${PYTHON_VERSION}-distutils + python${PYTHON_VERSION}-distutils RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone @@ -65,8 +65,7 @@ RUN rm -rf /var/lib/apt/lists/* 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/openedx/enterprise-subsidy/archive/refs/heads/main.tar.gz | tar -xz --strip-components=1 +RUN mkdir -p requirements # Create a virtualenv for sanity ENV VIRTUAL_ENV=/edx/venvs/enterprise-subsidy @@ -83,11 +82,18 @@ EXPOSE 18280 RUN useradd -m --shell /bin/false app # Dependencies are installed as root so they cannot be modified by the application user. + +RUN curl -L -o requirements/pip.txt https://raw.githubusercontent.com/openedx/enterprise-subsidy/main/requirements/pip.txt +RUN curl -L -o requirements/production.txt https://raw.githubusercontent.com/openedx/enterprise-subsidy/main/requirements/production.txt + RUN pip install -r requirements/pip.txt RUN pip install -r requirements/production.txt RUN mkdir -p /edx/var/log +# cloning git repo +RUN curl -L https://github.com/openedx/enterprise-subsidy/archive/refs/heads/main.tar.gz | tar -xz --strip-components=1 + # Code is owned by root so it cannot be modified by the application user. # So we copy it before changing users. USER app @@ -102,6 +108,7 @@ CMD gunicorn --workers=2 --name enterprise-subsidy -c /edx/app/enterprise-subsid FROM app as devstack USER root +RUN curl -L -o requirements/dev.txt https://raw.githubusercontent.com/openedx/enterprise-subsidy/main/requirements/dev.txt RUN pip install -r requirements/dev.txt USER app CMD gunicorn --workers=2 --name enterprise-subsidy -c /edx/app/enterprise-subsidy/enterprise_subsidy/docker_gunicorn_configuration.py --log-file - --max-requests=1000 enterprise_subsidy.wsgi:application