Skip to content

Recompile requirements file used by Python in a container environment

hwassman edited this page Jul 31, 2023 · 2 revisions

Using Python requirements files is among Python development best practices. It dramatically reduces the need for managing and supervising different libraries. Managing your library dependencies from one place makes it easier, more convenient, and faster. It helps keep everything organized and easy for everyone involved.

It is a great way to ensure you have all the necessary dependencies installed for your project.

Also, GitHub provides automated vulnerability alerts for dependencies in your repository. By uploading a requirements.txt with your code, GitHub checks for any conflict and sends an alert to the administrator if it detects any. It can even resolve the vulnerabilities automatically!

If the conflicts in the requirements file could not be resolved automatically, or the base image version needs to be upgraded to a later version, or set to a different version, then the Python package requirements list can be recompiled by following the steps below.

Recompile requirements file used by Python in a container environment

Clone repository to your favourite directory on your test system.

# git clone https://github.com/IBM/ibm-spectrum-scale-bridge-for-grafana.git bridge_7.0.9-dev

Modify the base image version in the Dockerfile if required.

ARG BASE=registry.access.redhat.com/ubi9/ubi:9.2

Comment in the following rows

COPY ./requirements/requirements_ubi9.txt  /root/requirements_ubi9.txt
# COPY ./requirements/requirements_ubi.in  /root/requirements_ubi.in

RUN yum install -y python39 python3-pip

# RUN /usr/bin/python3 -m pip install pip-tools && \
#     /usr/bin/python3 -m piptools compile /root/requirements_ubi.in  --output-file /root/requirements_ubi9.txt && \
#     echo "Compiled python packages: $(cat /root/requirements_ubi9.txt)"

RUN /usr/bin/python3 -m pip install -r /root/requirements_ubi9.txt && \
    echo "Installed python version: $(/usr/bin/python3 -V)" && \
    echo "Installed python packages: $(/usr/bin/python3 -m pip list)"

The dependencies in python packages will be recompiled, printed out and tested during the image build execution

# podman build  -t scale_bridge:test_7.0.9_dev .

Verify the build process finished successfully. Copy "Compiled python packages:" section from the CLI output to a new requirements_ubiXXX.txt file. Store the file under /requirements. Comment out the previously embedded lines in the Dockerfile. Make sure the python packages install step in the Dockefile points to the new requirements file.

RUN /usr/bin/python3 -m pip install --user -r /root/requirements_ubiXXX.txt 

Test image build again.

User Guide

Installation

Configuration

Maintenance

Troubleshooting

Use cases

Designing dashboards

Developer Guide

Clone this wiki locally