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 df5c98f commit d2a4816
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
5 changes: 5 additions & 0 deletions .github/workflows/push-enterprise-access-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
21 changes: 11 additions & 10 deletions dockerfiles/enterprise-access.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ RUN apt-get update && apt-get -qy install --no-install-recommends \
pkg-config \
libmysqlclient-dev \
libssl-dev \
git \
git \
wget \
curl \
libffi-dev \
Expand All @@ -59,16 +59,14 @@ RUN apt-get update && apt-get -qy install --no-install-recommends \
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone

RUN pip install --upgrade pip setuptools
# delete apt package lists because we do not need them inflating our image

# Remove package lists to reduce image size
RUN rm -rf /var/lib/apt/lists/*

# need to use virtualenv pypi package with Python 3.12
# Set up Python environment and install virtualenv
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-access/archive/refs/heads/main.tar.gz | tar -xz --strip-components=1

# Create a virtualenv for sanity
ENV VIRTUAL_ENV=/edx/venvs/enterprise-access
RUN virtualenv -p python${PYTHON_VERSION} $VIRTUAL_ENV
Expand All @@ -94,16 +92,18 @@ RUN useradd -m --shell /bin/false app

WORKDIR /edx/app/enterprise-access

RUN pwd

RUN curl -L -o /requirements/pip.txt https://raw.githubusercontent.com/openedx/enterprise-access/main/requirements/pip.txt
RUN curl -L -o /requirements/production.txt https://raw.githubusercontent.com/openedx/enterprise-access/main/requirements/production.txt
# Dependencies are installed as root so they cannot be modified by the application user.
RUN pip install -r /requirements/pip.txt
RUN pip install -r /requirements/production.txt

RUN mkdir -p /edx/var/log

# Code is owned by root so it cannot be modified by the application user.
# So we copy it before changing users.
# Clone the source code
RUN curl -L https://github.com/openedx/enterprise-access/archive/refs/heads/main.tar.gz | tar -xz --strip-components=1

# Change user to app
USER app

# Gunicorn 19 does not log to stdout or stderr by default. Once we are past gunicorn 19, the logging to STDOUT need not be specified.
Expand All @@ -115,6 +115,7 @@ CMD newrelic-admin run-program gunicorn --workers=2 --name enterprise-access -c

FROM app as devstack
USER root
RUN curl -L -o /requirements/dev.txt https://raw.githubusercontent.com/openedx/enterprise-access/main/requirements/dev.txt
RUN pip install -r /requirements/dev.txt
USER app
CMD gunicorn --workers=2 --name enterprise-access -c /edx/app/enterprise-access/enterprise_access/docker_gunicorn_configuration.py --log-file - --max-requests=1000 enterprise_access.wsgi:application

0 comments on commit d2a4816

Please sign in to comment.