Last active
March 22, 2024 13:05
-
-
Save NimJay/53d95c601dc43721362ab983607f3b7d to your computer and use it in GitHub Desktop.
Generate requirements.txt for a given requirements.in file using a Docker container.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Set the version of Python you want to use here. | |
FROM python:3.12.2-slim@sha256:36d57d7f9948fefe7b6092cfe8567da368033e71ba281b11bb9eeffce3d45bc6 as base | |
# Ignore this. This is needed to build Online Boutique's recommendationservice. | |
# RUN apt-get -qq update \ | |
# && apt-get install -y --no-install-recommends \ | |
# wget g++ \ | |
# && rm -rf /var/lib/apt/lists/* | |
# This Dockerfile assumes that the requirements.in file is in the same folder as this Dockerfile. | |
COPY requirements.in . | |
# Install pip-tools which will contain pip-compile. | |
RUN pip install -U pip pip-tools | |
# Generate requirements.txt. | |
RUN pip-compile --output-file=requirements.txt requirements.in | |
# Let's test that the requirements.txt actually installs dependencies properly. | |
RUN pip install -r requirements.txt | |
# Finally, print out the contents of requirements.txt | |
# when you build this Docker container image | |
RUN cat requirements.txt | |
# and when you run this Docker container image | |
ENTRYPOINT ["cat", "requirements.txt"] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Instructions
Dockerfile
file and yourrequirements.in
file in the same folder.requirements.txt
in the previous step, but you can also run the container for cleaner output:Without Docker
If you aren't able to use
docker
, you can usegcloud
to build a Dockerfile and push it to an Artifact Registry.