Comments (5)
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.
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.
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 closedOr, 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.
Can we close this issue then?
from dockerfile-parse.
ah yes sure
from dockerfile-parse.
Related Issues (20)
- [packit] Propose update failed for release 0.0.17
- Proposal - add more complex FROM clause parsing HOT 4
- Parser ignores RUN statements if comments are in them HOT 2
- Handle escape directive for Dockerfiles HOT 2
- dockerfile-parse creates a Dockerfile file HOT 3
- ARG's are not inherited from a parent stage - only the last stage is considered HOT 7
- Add support for dockerfile stages HOT 2
- Add support for updating global ARGs
- make dockerfile-parse an RPM available on src.fedoraproject.org/projects/rpms/ HOT 4
- Interpret shell substitution for build arguments HOT 1
- Option to only write data back to disk when explicitly requested HOT 3
- Base image is incorrect when FROM statement has --platform HOT 3
- Incompatibility with pytest 7.2.0 HOT 1
- Support heredocs
- Support parsing individual commands? HOT 1
- ARGs are not handled in FROM instruction HOT 6
- Keeping comments in the parsed result HOT 3
- What if "apt-get" becomes an instruction? HOT 6
- Incorrectly appending 'Dockerfile' to path HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from dockerfile-parse.