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

Bug: Docker image build kwargs is not working #706

Open
Tranquility2 opened this issue Oct 1, 2024 · 3 comments · May be fixed by #708
Open

Bug: Docker image build kwargs is not working #706

Tranquility2 opened this issue Oct 1, 2024 · 3 comments · May be fixed by #708
Labels

Comments

@Tranquility2
Copy link
Contributor

Describe the bug

When using kwargs in the Image API, the params are not passed into the build

To Reproduce

For example:

with DockerImage(path="./", tag="new:test", buildargs={"PIP_EXTRA_INDEX_URL": PIP_EXTRA_INDEX_URL}) as image:

The PIP_EXTRA_INDEX_URL fails to register in the docker image build process:

E               docker.errors.BuildError: The command '/bin/sh -c pip3 install --no-cache-dir -r requirements.txt --extra-index-url ${PIP_EXTRA_INDEX_URL}' returned a non-zero code: 2
@Tranquility2
Copy link
Contributor Author

class DockerImage:
...
    def __init__(
        self,
        path: Union[str, PathLike],
        docker_client_kw: Optional[dict] = None,
        tag: Optional[str] = None,
        clean_up: bool = True,
        dockerfile_path: Union[str, PathLike] = "Dockerfile",
        no_cache: bool = False,
        **kwargs,
    ) -> None:
...
    def build(self, **kwargs) -> Self:
        logger.info(f"Building image from {self.path}")
        docker_client = self.get_docker_client()
        self._image, self._logs = docker_client.build(
            path=str(self.path), tag=self.tag, dockerfile=self._dockerfile_path, nocache=self._no_cache, **kwargs
        )
        logger.info(f"Built image {self.short_id} with tag {self.tag}")
        return self
...
    def __enter__(self) -> Self:
        return self.build()

As can be seen kwargs is not passed/used correctly...
This is ofc my bad, sorry.
Will create a fix asap.

maybe also take the time to add something like #614

@Tranquility2
Copy link
Contributor Author

Workaround

Just use the lower level methods

def test_something():
    image = DockerImage(path="./", tag="new:test")
    image.build(buildargs={"PIP_EXTRA_INDEX_URL": PIP_EXTRA_INDEX_URL})
    with AWSLambdaContainer(image=image, port=8080) as func:
       # Do Something with the container
    image.remove()

@black-snow
Copy link
Contributor

I feel like this was my original issue with build args exactly :D

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants