Skip to content

Commit

Permalink
perf: updated Dockerfile to optimize requirements installation and de…
Browse files Browse the repository at this point in the history
…pendency caching
  • Loading branch information
BilalQamar95 committed Oct 16, 2024
1 parent a375c39 commit 04264cb
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .github/workflows/push-enterprise-subsidy-image.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 10 additions & 3 deletions dockerfiles/enterprise-subsidy.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand All @@ -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
Expand All @@ -102,6 +108,7 @@ CMD gunicorn --workers=2 --name enterprise-subsidy -c /edx/app/enterprise-subsid

FROM app as devstack

Check warning on line 109 in dockerfiles/enterprise-subsidy.Dockerfile

View workflow job for this annotation

GitHub Actions / build-and-push-image

The 'as' keyword should match the case of the 'from' keyword

FromAsCasing: 'as' and 'FROM' keywords' casing do not match More info: https://docs.docker.com/go/dockerfile/rule/from-as-casing/
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

Check warning on line 114 in dockerfiles/enterprise-subsidy.Dockerfile

View workflow job for this annotation

GitHub Actions / build-and-push-image

JSON arguments recommended for ENTRYPOINT/CMD to prevent unintended behavior related to OS signals

JSONArgsRecommended: JSON arguments recommended for CMD to prevent unintended behavior related to OS signals More info: https://docs.docker.com/go/dockerfile/rule/json-args-recommended/

0 comments on commit 04264cb

Please sign in to comment.