Skip to content

Commit

Permalink
AL: Added directive parser
Browse files Browse the repository at this point in the history
  • Loading branch information
adalundhe committed Jan 12, 2024
1 parent 3c8011f commit 32415ec
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.1.4
0.1.5
23 changes: 21 additions & 2 deletions dcrx/directive.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,14 +183,33 @@ def __contains__(
def parse(
self,
dockerfile: str | List[str] | bytes | List[bytes]
):
) -> List[
Add |
Arg |
Cmd |
Copy |
Entrypoint |
Env |
Expose |
Healthcheck |
Label |
Maintainer |
OnBuild |
Run |
Shell |
Stage |
StopSignal |
User |
Volume |
Workdir
]:

if isinstance(dockerfile, str):
self._file_data.extend(
dockerfile.split('\n')
)

elif isinstance(bytes):
elif isinstance(dockerfile, bytes):
self._file_data.extend(
dockerfile.decode().split('\n')
)
Expand Down
29 changes: 29 additions & 0 deletions dcrx/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
Volume,
Workdir
)
from .directive import Directives
from .layers.mount_types import (
BindMount,
CacheMount,
Expand Down Expand Up @@ -96,9 +97,37 @@ def __init__(
'tmpfs': lambda config: TMPFSMount(**config)
}

self.directives = Directives()

@property
def full_name(self):
return f'{self.name}:{self.tag}'

def from_string(
self,
dockerfile: str
):
self.layers.extend(
self.directives.parse(dockerfile)
)

return self

def from_file(
self,
filepath: str
):
filename = pathlib.Path(filepath).name
self.filename = filename

with open(filepath) as dockerfile:
self.layers.append(
self.directives.parse(
dockerfile.readlines()
)
)

return self

def to_string(self) -> str:
return '\n\n'.join([
Expand Down

0 comments on commit 32415ec

Please sign in to comment.