From 98b73976db9c7a9839000d50e7905cdb42d1f2fe Mon Sep 17 00:00:00 2001 From: Muhammad Faraz Maqsood Date: Mon, 18 Mar 2024 16:20:26 +0500 Subject: [PATCH 1/4] feat: upgrade dockerfiles to be compatible with 3.12. 2 --- .../build/ecommerce-worker/Dockerfile | 20 +++++++++++++---- .../ecommerce/build/ecommerce/Dockerfile | 22 ++++++++++++++----- 2 files changed, 33 insertions(+), 9 deletions(-) diff --git a/tutorecommerce/templates/ecommerce/build/ecommerce-worker/Dockerfile b/tutorecommerce/templates/ecommerce/build/ecommerce-worker/Dockerfile index 7cc825e7..48245929 100644 --- a/tutorecommerce/templates/ecommerce/build/ecommerce-worker/Dockerfile +++ b/tutorecommerce/templates/ecommerce/build/ecommerce-worker/Dockerfile @@ -5,7 +5,8 @@ FROM docker.io/ubuntu:20.04 as minimal RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \ --mount=type=cache,target=/var/lib/apt,sharing=locked \ apt update && \ - apt install -y git-core language-pack-en python3 python3-pip python3-venv + apt install -y curl git-core language-pack-en libmysqlclient-dev \ + libssl-dev libffi-dev build-essential ARG APP_USER_ID=1000 RUN useradd --home-dir /openedx --create-home --shell /bin/bash --uid ${APP_USER_ID} app @@ -15,14 +16,25 @@ RUN mkdir /openedx/ecommerce_worker && \ git clone https://github.com/edx/ecommerce-worker.git --branch {{ OPENEDX_COMMON_VERSION }} --depth 1 /openedx/ecommerce_worker WORKDIR /openedx/ecommerce_worker -# Install python venv -RUN python3 -m venv ../venv/ +# Install pyenv +# https://www.python.org/downloads/ +# https://github.com/pyenv/pyenv/releases +ARG PYTHON_VERSION=3.12.2 +ENV PYENV_ROOT /opt/pyenv +USER root +RUN git clone https://github.com/pyenv/pyenv $PYENV_ROOT --branch v2.3.36 --depth 1 +# Install Python +RUN $PYENV_ROOT/bin/pyenv install $PYTHON_VERSION +USER app + +# Create virtualenv +RUN $PYENV_ROOT/versions/$PYTHON_VERSION/bin/python -m venv ../venv/ ENV PATH "/openedx/venv/bin:$PATH" RUN --mount=type=cache,target=/openedx/.cache/pip,sharing=shared pip install \ # https://pypi.org/project/setuptools/ # https://pypi.org/project/pip/ # https://pypi.org/project/wheel/ - setuptools==67.7.2 pip==23.1.2. wheel==0.40.0 + setuptools==69.1.1 pip==24.0 wheel==0.43.0 RUN --mount=type=cache,target=/openedx/.cache/pip,sharing=shared pip install -r requirements/production.txt ENV WORKER_CONFIGURATION_MODULE ecommerce_worker.settings.production diff --git a/tutorecommerce/templates/ecommerce/build/ecommerce/Dockerfile b/tutorecommerce/templates/ecommerce/build/ecommerce/Dockerfile index 4cc6c4be..2cd35c3b 100644 --- a/tutorecommerce/templates/ecommerce/build/ecommerce/Dockerfile +++ b/tutorecommerce/templates/ecommerce/build/ecommerce/Dockerfile @@ -32,7 +32,8 @@ FROM minimal as python RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \ --mount=type=cache,target=/var/lib/apt,sharing=locked \ apt update && \ - apt install -y libmysqlclient-dev libssl-dev python3 python3-pip python3-venv + apt install -y libmysqlclient-dev libssl-dev build-essential \ + libsqlite3-dev libffi-dev ARG APP_USER_ID=1000 RUN if [ "$APP_USER_ID" = 0 ]; then echo "app user may not be root" && false; fi @@ -42,14 +43,25 @@ USER ${APP_USER_ID} # Create cache dir. Otherwise, for some reason, it becomes owned by root. RUN mkdir /openedx/.cache -# Create python venv -RUN python3 -m venv /openedx/venv/ +# Install pyenv +# https://www.python.org/downloads/ +# https://github.com/pyenv/pyenv/releases +ARG PYTHON_VERSION=3.12.2 +ENV PYENV_ROOT /opt/pyenv +USER root +RUN git clone https://github.com/pyenv/pyenv $PYENV_ROOT --branch v2.3.36 --depth 1 +# Install Python +RUN $PYENV_ROOT/bin/pyenv install $PYTHON_VERSION +USER app + +# Create virtualenv +RUN $PYENV_ROOT/versions/$PYTHON_VERSION/bin/python -m venv /openedx/venv ENV PATH "/openedx/venv/bin:$PATH" RUN --mount=type=cache,target=/openedx/.cache/pip,sharing=shared,uid=${APP_USER_ID} pip install \ # https://pypi.org/project/setuptools/ # https://pypi.org/project/pip/ # https://pypi.org/project/wheel/ - setuptools==68.2.2 pip==23.2.1 wheel==0.41.2 + setuptools==69.1.1 pip==24.0 wheel==0.43.0 # Install a recent version of nodejs # https://pypi.org/project/nodeenv @@ -69,7 +81,7 @@ RUN --mount=type=cache,target=/openedx/.cache/bower,sharing=shared,uid=${APP_USE # python requirements RUN --mount=type=cache,target=/openedx/.cache/pip,sharing=shared,uid=${APP_USER_ID} pip install -r requirements.txt # https://pypi.org/project/uWSGI/ -RUN --mount=type=cache,target=/openedx/.cache/pip,sharing=shared,uid=${APP_USER_ID} pip install uwsgi==2.0.21 +RUN --mount=type=cache,target=/openedx/.cache/pip,sharing=shared,uid=${APP_USER_ID} pip install uwsgi==2.0.24 # Install private requirements: this is useful for installing custom payment processors. COPY --chown=app:app ./requirements/ /openedx/requirements From 310f2124bf0010731ff59b302fa4b9b2d03540ee Mon Sep 17 00:00:00 2001 From: Muhammad Faraz Maqsood Date: Mon, 8 Apr 2024 13:26:30 +0500 Subject: [PATCH 2/4] docs: add a comment explaining the need of root user => [minimal 7/19] RUN echo "{}" > /openedx/config.yml 0.2s => ERROR [minimal 8/19] RUN git clone https://github.com/pyenv/pyenv /opt/pyenv --branch v2.3.36 --depth 1 0.4s ------ > importing cache manifest from docker.io/overhangio/openedx-discovery:17.0.0-nightly-cache: ------ ------ > [minimal 8/19] RUN git clone https://github.com/pyenv/pyenv /opt/pyenv --branch v2.3.36 --depth 1: 0.341 fatal: could not create work tree dir '/opt/pyenv': Permission denied ------ Dockerfile:36 -------------------- 34 | ENV PYENV_ROOT /opt/pyenv 35 | # USER root 36 | >>> RUN git clone https://github.com/pyenv/pyenv $PYENV_ROOT --branch v2.3.36 --depth 1 37 | # Install Python 38 | RUN $PYENV_ROOT/bin/pyenv install $PYTHON_VERSION -------------------- ERROR: failed to solve: process "/bin/sh -c git clone https://github.com/pyenv/pyenv $PYENV_ROOT --branch v2.3.36 --depth 1" did not complete successfully: exit code: 128 --- .../templates/ecommerce/build/ecommerce-worker/Dockerfile | 1 + tutorecommerce/templates/ecommerce/build/ecommerce/Dockerfile | 1 + 2 files changed, 2 insertions(+) diff --git a/tutorecommerce/templates/ecommerce/build/ecommerce-worker/Dockerfile b/tutorecommerce/templates/ecommerce/build/ecommerce-worker/Dockerfile index 48245929..95a7217a 100644 --- a/tutorecommerce/templates/ecommerce/build/ecommerce-worker/Dockerfile +++ b/tutorecommerce/templates/ecommerce/build/ecommerce-worker/Dockerfile @@ -21,6 +21,7 @@ WORKDIR /openedx/ecommerce_worker # https://github.com/pyenv/pyenv/releases ARG PYTHON_VERSION=3.12.2 ENV PYENV_ROOT /opt/pyenv +# root user is required for below 2 steps, as app user gets permission denied. USER root RUN git clone https://github.com/pyenv/pyenv $PYENV_ROOT --branch v2.3.36 --depth 1 # Install Python diff --git a/tutorecommerce/templates/ecommerce/build/ecommerce/Dockerfile b/tutorecommerce/templates/ecommerce/build/ecommerce/Dockerfile index 2cd35c3b..6406d2cd 100644 --- a/tutorecommerce/templates/ecommerce/build/ecommerce/Dockerfile +++ b/tutorecommerce/templates/ecommerce/build/ecommerce/Dockerfile @@ -48,6 +48,7 @@ RUN mkdir /openedx/.cache # https://github.com/pyenv/pyenv/releases ARG PYTHON_VERSION=3.12.2 ENV PYENV_ROOT /opt/pyenv +# root user is required for below 2 steps, as app user gets permission denied. USER root RUN git clone https://github.com/pyenv/pyenv $PYENV_ROOT --branch v2.3.36 --depth 1 # Install Python From 12d478363335fcabc6159ca73787ac75f39e56d9 Mon Sep 17 00:00:00 2001 From: Muhammad Faraz Maqsood Date: Mon, 15 Apr 2024 13:58:17 +0500 Subject: [PATCH 3/4] change ecommerce-worker dockerfile according to celery version 5.3.6 --- .../templates/ecommerce/build/ecommerce-worker/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tutorecommerce/templates/ecommerce/build/ecommerce-worker/Dockerfile b/tutorecommerce/templates/ecommerce/build/ecommerce-worker/Dockerfile index 95a7217a..6584576e 100644 --- a/tutorecommerce/templates/ecommerce/build/ecommerce-worker/Dockerfile +++ b/tutorecommerce/templates/ecommerce/build/ecommerce-worker/Dockerfile @@ -39,4 +39,4 @@ RUN --mount=type=cache,target=/openedx/.cache/pip,sharing=shared pip install \ RUN --mount=type=cache,target=/openedx/.cache/pip,sharing=shared pip install -r requirements/production.txt ENV WORKER_CONFIGURATION_MODULE ecommerce_worker.settings.production -CMD celery worker --app=ecommerce_worker.celery_app:app --loglevel=info --maxtasksperchild 100 --queue=fulfillment,email_marketing +CMD celery --app=ecommerce_worker.celery_app:app worker --loglevel=info --max-tasks-per-child=100 --queues=fulfillment,email_marketing From c233ccd811437e1281f5785561b295807010a2c6 Mon Sep 17 00:00:00 2001 From: Muhammad Faraz Maqsood Date: Tue, 7 May 2024 15:26:35 +0500 Subject: [PATCH 4/4] add changelog entry --- .../20240507_152527_faraz.maqsood_python_upgrade_to_v3_12_2.md | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelog.d/20240507_152527_faraz.maqsood_python_upgrade_to_v3_12_2.md diff --git a/changelog.d/20240507_152527_faraz.maqsood_python_upgrade_to_v3_12_2.md b/changelog.d/20240507_152527_faraz.maqsood_python_upgrade_to_v3_12_2.md new file mode 100644 index 00000000..ff0346e0 --- /dev/null +++ b/changelog.d/20240507_152527_faraz.maqsood_python_upgrade_to_v3_12_2.md @@ -0,0 +1 @@ +- 💥[Feature] Upgrade Python version to 3.12.2. (by @Faraz32123)