Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ Start a mix session with `iex -S mix` and type the following instructions
path = Path.expand("~/workspace/elixir-docker-guide")

{:ok, image_id} = Path.join([path, "Dockerfile"]) |>
ExDockerBuild.DockerfileParser.parse!() |>
ExDockerBuild.DockerfileParser.parse_file!() |>
ExDockerBuild.DockerBuild.build(path)
```

Expand All @@ -68,7 +68,7 @@ $> mkdir ~/test
path = Path.expand("./test/fixtures")

{:ok, image_id} = Path.join([path, "Dockerfile_bind.dockerfile"]) |>
ExDockerBuild.DockerfileParser.parse!() |>
ExDockerBuild.DockerfileParser.parse_file!() |>
ExDockerBuild.DockerBuild.build(path)
```

Expand Down
19 changes: 11 additions & 8 deletions lib/ex_docker_build/dockerfile_parser.ex
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,18 @@ defmodule ExDockerBuild.DockerfileParser do
@continuation ~r/^.*\\\s*$/
@instruction ~r/^\s*(\w+)\s+(.*)$/

@spec parse!(Path.t() | String.t()) :: list(String.t()) | no_return()
def parse!(path_or_content) do
content =
if File.exists?(path_or_content) do
File.read!(path_or_content)
else
path_or_content
end
@spec parse_file!(Path.t()) :: list(String.t()) | no_return()
def parse_file!(path) do
path
|> File.read!()
|> do_parse()
end

@spec parse_content!(String.t()) :: list(String.t()) | no_return()
def parse_content!(content), do: do_parse(content)

@spec do_parse(String.t()) :: list(String.t())
defp do_parse(content) do
{parsed_lines, _} =
content
|> String.split("\n")
Expand Down
4 changes: 2 additions & 2 deletions test/dockerfile_parser_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ defmodule ExDockerBuild.DockerfileParserTest do

def parse(base_dir, file) do
Path.join([base_dir, file])
|> Parser.parse!()
|> Parser.parse_file!()
end

test "parses correctly a simple Dockerfile", %{base_dir: base_dir} do
Expand Down Expand Up @@ -67,7 +67,7 @@ defmodule ExDockerBuild.DockerfileParserTest do
CMD ["cat", "/data/myfile.txt"]
"""

result = Parser.parse!(content)
result = Parser.parse_content!(content)

assert result == [
{"FROM", "elixir:1.7.3"},
Expand Down