Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade python to 3.12 and upgrade related packages; Bug fix failing mime type tests #323

Merged
merged 40 commits into from
Nov 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
1868fc1
TMMA-508: Refactor detecting mime types of file uploads
asset-web Oct 25, 2024
f8f483b
Bug fix refactoring detecting mime types
asset-web Oct 25, 2024
55efed6
Bug fix refactoring detecting mime types
asset-web Oct 25, 2024
5a49a83
Bug fix refactoring tests to use mimetypes package
asset-web Oct 25, 2024
f63c6ce
Add more debug output to mime type validator
asset-web Oct 25, 2024
23a2ee4
Update pip version
asset-web Oct 31, 2024
98bd395
TMMA-511: Upgrade Python from 3.8.x to 3.9+; TMMA-347: Set up RHEL8 d…
asset-web Oct 31, 2024
60384e8
Update Python version in probe test
asset-web Nov 3, 2024
c2a2514
Merge branch 'TMMA-511' into TMMA-508
asset-web Nov 4, 2024
6a568f6
Bug fix typo in debug messages
asset-web Nov 4, 2024
99bb858
Bug fix location protocol required by change in redis connector
asset-web Nov 4, 2024
c3f82df
Bug fix settings required with change in redis connector package
asset-web Nov 4, 2024
ddc4bd5
Fix deprecation warning
asset-web Nov 4, 2024
4a75d2a
Attempt to resolve issue with detecting mimetypes of compressed files
asset-web Nov 4, 2024
ee307d1
Refactor determining mime types
asset-web Nov 5, 2024
32abee5
Add fallback for detecting mime types
asset-web Nov 5, 2024
e147b71
Attempt to upgrade to Python 3.12 - WIP known issue re mimetype detec…
asset-web Nov 5, 2024
0a83e40
Attempt to upgrade to Python 3.12 - WIP known issue re mimetype detec…
asset-web Nov 5, 2024
1549cfb
Remove unused / unnecessary functions or commands that trigger warnin…
asset-web Nov 5, 2024
801f6d6
Remove unused / unnecessary functions or commands that trigger warnin…
asset-web Nov 5, 2024
dd33ff5
Use explict regular expresson r prefixed strings
asset-web Nov 5, 2024
55d9f42
Bug fix using explict regular expresson rb prefixed byte strings
asset-web Nov 5, 2024
3a1334b
Update Probe page test
asset-web Nov 5, 2024
20bb56a
Update to use Python 3.12 pip and related system packages instead
asset-web Nov 5, 2024
63673cf
Re-instate using python-magic egg to detect mimetype, add support to …
asset-web Nov 5, 2024
02c860b
Bug fix typo in updated test
asset-web Nov 5, 2024
61af05a
Update to use python 3.12 test assertion
asset-web Nov 5, 2024
5c92473
Revert change to mime type detection which appears to work well with …
asset-web Nov 5, 2024
a03789f
Bug fix reverting test to using python-magic package; Lower debugging…
asset-web Nov 5, 2024
7106079
Adjust failing tests; Temp only run failing tests
asset-web Nov 5, 2024
90c8208
Add further debug output and fallback mimetpye check
asset-web Nov 6, 2024
7c9ac08
Add further debug output and fallback mimetpye check
asset-web Nov 6, 2024
046b078
Add further debug output and fallback mimetpye check
asset-web Nov 6, 2024
e134796
Add further debug output and fallback mimetpye check
asset-web Nov 6, 2024
cb7cd5f
Bug fix mime type check
asset-web Nov 6, 2024
ec33542
Update clamd tests; Re-enable Django tests
asset-web Nov 6, 2024
23d1be4
Merge branch 'master' into upgrade-to-312
asset-web Nov 6, 2024
8c93484
Revert and modify when Debian docker image related Github actions are…
asset-web Nov 6, 2024
1a6b65f
Ensure using virtualenv by default for future runs of make_virtualenv…
asset-web Nov 6, 2024
1dbbfde
[skip ci] Remove temp file
asset-web Nov 6, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
deploy/Dockerfile
deploy/Dockerfile-rhel
2 changes: 1 addition & 1 deletion .github/workflows/check-python-dependcies.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: '3.8'
python-version: '3.12'
architecture: 'x64'
- name: Run checks for package updates
run: bash tests/run-update-checks.sh
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ on:
# TODO: Review scope of GitHub action grows
- '.github/workflows/docker.yml'
- 'deploy/Dockerfile'
- 'entrypoints/**'
# - 'entrypoints/**'
- 'requirements/**'
# schedule:
# - cron: 30 9 * * WED
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/run-django-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: '3.8'
python-version: '3.12'
architecture: 'x64'
- name: Run Python 3/Django tests
run: bash tests/run-django-tests.sh
2 changes: 1 addition & 1 deletion .github/workflows/run-fabric-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: '3.8'
python-version: '3.12'
architecture: 'x64'
- name: Syntax check Python 3 Fabric deployment script
run: bash tests/run-fabric-tests.sh
8 changes: 7 additions & 1 deletion CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
# Changelog

9.8.2 TMMA-508: Resolve issue in tests after RHEL migration
9.9.0 TMMA-511: Upgrade Python from 3.8.x to 3.12.x
TMMA-508: Resolve issue in tests after RHEL migration
Apply MySQL Connector/Python connector security update
TMMA-347: Set up RHEL8 development docker environment
Update packages used to connect to redis
Update Python dependencies
Update version of MySQL used in GitHub actions

9.8.1 TMMA-509: Improve security of Python packaging tool
Update Python packaging tool
Expand Down
16 changes: 9 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@

### Prerequisites

* Vagrant https://www.vagrantup.com/
* VirtualBox https://www.virtualbox.org/ or another provider, see https://www.vagrantup.com/docs/providers/
* Vagrant [https://www.vagrantup.com/]
* VirtualBox [https://www.virtualbox.org/] or another provider, see [https://www.vagrantup.com/docs/providers/]
NB: The vagrant installation also requires an additional plugin to mount the development source code cloned on your local machine.

Tested with these versions:
Expand Down Expand Up @@ -131,23 +131,25 @@ NB: If you want to manually run migrations you need to use the --database flag
python manage.py migrate --database=admin --settings=temmpo.settings.dev

#### Updating the requirements file using pip-tools (via Vagrant VM)

NB: This can take a while as we also generate hashes for additional security.

fab pip_sync_requirements_file:env=dev,use_local_mode=True -f /usr/local/projects/temmpo/lib/dev/src/temmpo/deploy/fabfile.py

#### Upgrading the requirements file using pip-tools (via Vagrant VM)
NB: This can take a while as we also generate hashes for additional security.

Optionally pass in a package or update them all within any requirements.in file constraints

fab pip_tools_update_requirements:env=dev,use_local_mode=True,package="" -f /usr/local/projects/temmpo/lib/dev/src/temmpo/deploy/fabfile.py


Alternatively
Alternatively a Python (Debian) base docker image to update requirements

docker build -f deploy/Dockerfile -t temmpo-web .
docker run --rm -it -v $PWD:/srv -w /srv temmpo-web bash /srv/entrypoints/update-requirements.sh

Alternatively build a RHEL base docker image to update requirements

docker compose build web
docker compose run --rm --no-deps web bash ./entrypoints/update-requirements.sh

#### Create Docker images for different environments

docker build -f deploy/Dockerfile -t temmpo-web-dev . --build-arg REQUIREMENTS_FILE=dev.txt
Expand Down
4 changes: 4 additions & 0 deletions browser/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ def _create_upload_file_from_path(self, file_path):
def to_python(self, value):
value = super(ExtractorFileField, self).to_python(value)
mime_type = magic.from_buffer(value.read(1024), mime=True)

logger.debug("DEBUG: temp file path %s" % value.temporary_file_path())
logger.debug("DEBUG: mime %s" % mime_type)

if mime_type in ('application/gzip', 'application/x-gzip', 'application/bzip', 'application/bzip2', 'application/x-bzip', 'application/x-bzip2'):
try:
extracted_file_path = xtract(value.temporary_file_path())
Expand Down
5 changes: 2 additions & 3 deletions browser/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,8 @@

def get_user_upload_location(instance, filename):
"""Based on slugify code - from django.utils.text import slugify."""
# TODO Test changes explictly
filename = re.sub('[^\.\w\s-]', '', filename).strip().lower()
filename = re.sub('[-\s]+', '-', filename)
filename = re.sub(r'[^\.\w\s-]', '', filename).strip().lower()
filename = re.sub(r'[-\s]+', '-', filename)

return timezone.now().strftime('/'.join(['abstracts', str(instance.user.id), '%Y-%m-%d', '%H-%M-%S-' + filename]))

Expand Down
4 changes: 2 additions & 2 deletions browser/probe.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def check(self, components, label='', function=None, max_duration=5, allow_fail=
success = function()
end = time.time()
if end - start > max_duration:
logger.warn(
logger.warning(
"Check timestamp exceeded for '%s' (%s took longer than %s)" % (label, end - start, max_duration))
except Exception as e:
end = time.time()
Expand Down Expand Up @@ -99,7 +99,7 @@ def probe_email(self):
return True

def python_version(self):
if sys.version_info.major == 3 and sys.version_info.minor == 8:
if sys.version_info.major == 3 and sys.version_info.minor == 12:
return True
else:
return False
Expand Down
15 changes: 9 additions & 6 deletions browser/validators.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
# -*- coding: utf-8 -*-
import logging
import magic
import re

import magic

from django.core.exceptions import ValidationError

logger = logging.getLogger(__name__)

OVID_MEDLINE_IDENTIFIER_PATTERN = re.compile(b"^<\d+>")
OVID_MEDLINE_IDENTIFIER_LABEL_PATTERN = re.compile(b"^Unique Identifier")
OVID_MEDLINE_IDENTIFIER_MESH_PATTERN = re.compile(b"^MeSH Subject Headings")
OVID_MEDLINE_IDENTIFIER_PATTERN = re.compile(rb"^<\d+>")
OVID_MEDLINE_IDENTIFIER_LABEL_PATTERN = re.compile(rb"^Unique Identifier")
OVID_MEDLINE_IDENTIFIER_MESH_PATTERN = re.compile(rb"^MeSH Subject Headings")

PUBMED_IDENTIFIER_PATTERN = re.compile(b"^PMID- \d+")
PUBMED_IDENTIFIER_MH_PATTERN = re.compile(b"^MH -")
PUBMED_IDENTIFIER_PATTERN = re.compile(rb"^PMID- \d+")
PUBMED_IDENTIFIER_MH_PATTERN = re.compile(rb"^MH -")


class MimetypeValidator(object):
Expand All @@ -25,6 +26,8 @@ def __init__(self, mimetypes):
def __call__(self, value):
try:
mime = magic.from_buffer(value.read(1024), mime=True)
logger.debug("DEBUG: temp file path %s" % value.temporary_file_path())
logger.debug("DEBUG: mime %s" % mime)
if mime not in self.mimetypes:
raise ValidationError('%s is not an acceptable file type. Please use a %s formatted file instead.' % (value, ' or '.join(self.mimetypes)))
except AttributeError as e:
Expand Down
6 changes: 3 additions & 3 deletions deploy/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
FROM python:3.8.20-slim
FROM python:3.12.7-slim

ENV PYTHONDONTWRITEBYTECODE=1
ENV PYTHONUNBUFFERED=1
ENV PIP_VERSION='24.2'
ENV SETUPTOOLS_VERSION='74.1.2'
ENV PIP_VERSION='24.3.1'
ENV SETUPTOOLS_VERSION='75.2.0'
ENV PIP_TOOLS_VERSION='7.4.1'
# NB: Version 15.1.0 is installed on RHEL
ENV VE_VERSION='20.26.4'
Expand Down
95 changes: 95 additions & 0 deletions deploy/Dockerfile-rhel
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
FROM redhat/ubi8:8.10

ENV PYTHONDONTWRITEBYTECODE=1
ENV PYTHONUNBUFFERED=1

RUN yum -C repolist

ARG RHEL_ORG_ID
ARG RHEL_ACTIVATION_KEY
RUN subscription-manager register --org ${RHEL_ORG_ID} --activationkey ${RHEL_ACTIVATION_KEY}

RUN subscription-manager repos --enable codeready-builder-for-rhel-8-x86_64-debug-rpms
RUN subscription-manager repos --enable rhel-8-for-x86_64-supplementary-source-rpms
RUN subscription-manager repos --enable rhel-8-for-x86_64-baseos-e4s-source-rpms

RUN yum -C repolist
RUN subscription-manager repos --list

# Install EPEL
RUN yum -y install https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm

# Update system packages and install dependencies
RUN yum update -y && \
yum -y install \
bzip2 \
clamav \
clamav-data \
clamav-devel \
clamav-filesystem \
clamav-freshclam \
clamav-lib \
clamd \
curl \
# firefox-esr \
gcc \
libffi \
libxml2 \
pkg-config \
mariadb-connector-c-devel \
perl-DBD-MySQL \
python312 \
python3.12-pip \
python3.12-devel \
python3.12-lxml \
python3.12-setuptools \
python3.12-wheel \
zip

ENV PIP_VERSION='24.3.1'
ENV SETUPTOOLS_VERSION='75.2.0'
ENV PIP_TOOLS_VERSION='7.4.1'
ENV VE_VERSION='20.26.3'
ENV FABRIC_VERSION='1.15.0'

RUN pip3 -V
RUN pip3.12 -V

RUN pip3.12 install -U pip==${PIP_VERSION}
RUN pip3.12 install -U setuptools==${SETUPTOOLS_VERSION}
RUN pip3.12 install pip-tools==${PIP_TOOLS_VERSION}
RUN pip3.12 install virtualenv==${VE_VERSION}
RUN pip3.12 install fabric==${FABRIC_VERSION}

RUN pip3.12 freeze
RUN virtualenv --version

ENV ENVIRON="test"
ENV REQUIREMENTS="test"

ENV PROJECT_PATH=/usr/local/projects/temmpo
ENV CODE_PATH=${PROJECT_PATH}/lib/${ENVIRON}/src/temmpo

WORKDIR ${CODE_PATH}

COPY deploy/setup-rhel-env.sh deploy/
RUN bash deploy/setup-rhel-env.sh

COPY deploy/fabfile.py deploy/
COPY requirements/test.txt requirements/test.txt
COPY temmpo/settings/github_actions_ci_private_settings.py temmpo/settings/

RUN ln -s temmpo/settings/github_actions_ci_private_settings.py ${PROJECT_PATH}/.settings/private_settings.py

RUN fab -l -f deploy/fabfile.py
RUN fab make_virtualenv:env=${ENVIRON},configure_apache=False,clone_repo=False,branch=None,migrate_db=False,use_local_mode=True,requirements=${REQUIREMENTS},restart_rqworker=False,virtualenv=virtualenv,project_dir=${PROJECT_PATH}/ -f deploy/fabfile.py

COPY . ${CODE_PATH}

VOLUME [ ${CODE_PATH} ]

RUN ls -l /usr/local/projects/temmpo/.settings/private_settings.py

CMD [ "pip3.12", "check" ] # TODO replace with command to run tests

# CMD ../../bin/python3 manage.py test --settings=temmpo.settings.test_mysql --exclude-tag=selenium-test --exclude-tag=skip-on-ubuntu
Loading