GithubHelp home page GithubHelp logo

Comments (5)

chmeliik avatar chmeliik commented on September 3, 2024

Hi @ElijahAhianyo, thanks for the report!

As an immediate workaround, you may be able to pass the [dD]ockerfile via the fileobj argument instead of by path:

import dockerfile_parse

with open('./dockerfile', 'rb') as f:
    dockerfile = dockerfile_parse.DockerfileParser(fileobj=f)
    # do stuff with dockerfile

# can't use dockerfile anymore, fileobj is closed

Or, if using a real file object is not convenient:

import io
import dockerfile_parse

with open('./dockerfile', 'rb') as f:
    in_memory_file = io.BytesIO(f.read())

dockerfile = dockerfile_parse.DockerfileParser(fileobj=in_memory_file)
# note that writes to the dockerfile (e.g. via the `envs` or `labels` attributes)
#   will only be reflected in the in_memory_file, not on disk

from dockerfile-parse.

chmeliik avatar chmeliik commented on September 3, 2024

As for fixing the problem: maybe it would be good to support any arbitrary filename, rather than just dockerfile and Dockerfile?

For example, podman also supports the Containerfile name: https://docs.podman.io/en/latest/markdown/podman-build.1.html

Not quite sure if there is a nice way to do that while preserving backwards compatibility. Maybe the self.dockerfile_path attribute would have to be smarter:

@property
def dockerfile_path(self):
    if os.path.isfile(self._path):
        return self._path
    else:
        return os.path.join(self._path, DOCKERFILE_FILENAME)

from dockerfile-parse.

ElijahAhianyo avatar ElijahAhianyo commented on September 3, 2024

Hi @ElijahAhianyo, thanks for the report!

As an immediate workaround, you may be able to pass the [dD]ockerfile via the fileobj argument instead of by path:

import dockerfile_parse

with open('./dockerfile', 'rb') as f:
    dockerfile = dockerfile_parse.DockerfileParser(fileobj=f)
    # do stuff with dockerfile

# can't use dockerfile anymore, fileobj is closed

Or, if using a real file object is not convenient:

import io
import dockerfile_parse

with open('./dockerfile', 'rb') as f:
    in_memory_file = io.BytesIO(f.read())

dockerfile = dockerfile_parse.DockerfileParser(fileobj=in_memory_file)
# note that writes to the dockerfile (e.g. via the `envs` or `labels` attributes)
#   will only be reflected in the in_memory_file, not on disk

Hey, @chmeliik Thanks for getting back to me. Tried out your suggestion and seems to work. However, the only downside is having to use the DockerfileParser object while the file is opened or using a yield rather than return in the case where the object is created in another function, but this shouldn't be a problem as I have a work-around for this. Thanks! :)

from dockerfile-parse.

MartinBasti avatar MartinBasti commented on September 3, 2024

Can we close this issue then?

from dockerfile-parse.

ElijahAhianyo avatar ElijahAhianyo commented on September 3, 2024

ah yes sure

from dockerfile-parse.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.