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

Support Build Arg to Override Default requirements.txt #188

Closed
derks opened this issue Apr 9, 2017 · 2 comments
Closed

Support Build Arg to Override Default requirements.txt #188

derks opened this issue Apr 9, 2017 · 2 comments

Comments

@derks
Copy link

derks commented Apr 9, 2017

The standard for Python+PIP is a requirements.txt obviously, however in my use case for a project there are officially no required dependencies, but you can optionally install extensions that might have external dependencies. Therefore you end up with an official requirements.txt that is empty, but also a requirements-dev.txt that has all the optional requirements for development only.

It would be a minor change to set this as a build time arg, and not introduce any backward compatibility issues.

ARG REQUIREMENTS_FILE=requirements.txt
ONBUILD COPY $REQUIREMENTS_FILE /usr/src/app/

And then us outliers could utilize it:

$ docker build --build-arg REQUIREMENTS_FILE=requirements_dev.txt ...

Or more realistically, this will be from a development focused docker-compose.yml:

version: "3"
services:
    myapp:
        image: myapp:dev
        build:
            context: .
            args:
                REQUIREMENTS_FILE=requirements-dev.txt
        volumes:
            - .:/usr/src/app
@yosifkit
Copy link
Member

Unfortunately this change would have not have the intended effect for the end user since the ARG would be processed by our builder. When the user does FROM python:onbuild and builds, only the ONBUILD lines get triggered in the dependent image.

We are currently working toward removing onbuild images from the official images: docker-library/official-images#2076, since they are easily replaced with a more transparent Dockerfile and are inadequate beyond basic use cases as is the case you ran into with this issue.

So we recommend not using a Dockerfile of FROM python:onbuild and to instead be explicit:

FROM python:3.6

WORKDIR /usr/src/app

COPY requirements.txt /usr/src/app/
RUN pip install --no-cache-dir -r requirements.txt

COPY . /usr/src/app

This way you can change what needs to be copied in with or instead of requirements.txt and even make it FROM python:3.6-alpine and have more control over the size of the image by adding and removing build dependencies within the layer that they are used.

@derks
Copy link
Author

derks commented Apr 19, 2017

@yosifkit thank you for the feedback, and for clarifying that for me. I will move forward with your suggestions, thanks.

@derks derks closed this as completed Apr 19, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants