Skip to content
This repository was archived by the owner on Jun 13, 2019. It is now read-only.

Commit 65a8b82

Browse files
committed
Filter the args passed down to docker build.
Given the args are passed down to docker build and that Docker emits an error on a arg it does not know, we need to filter out our own args to keep Docker happy.
1 parent 2101e86 commit 65a8b82

1 file changed

Lines changed: 21 additions & 4 deletions

File tree

lib/mix_docker.ex

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ defmodule MixDocker do
1616

1717
def build(args) do
1818
with_dockerfile @dockerfile_build, fn ->
19-
docker :build, @dockerfile_build, image(:build), args
19+
docker :build, @dockerfile_build, image(:build), docker_build_args(args)
2020
end
2121

2222
Mix.shell.info "Docker image #{image(:build)} has been successfully created"
@@ -43,7 +43,7 @@ defmodule MixDocker do
4343
end
4444

4545
def publish(args) do
46-
name = image(version: image_version(args))
46+
name = image(version: image_version(mix_args(args)))
4747

4848
docker :tag, image(:release), name
4949
docker :push, name
@@ -100,11 +100,28 @@ defmodule MixDocker do
100100
end
101101
defp image_tag(tag), do: tag
102102

103-
defp image_version(args) do
104-
OptionParser.parse(args) |> elem(0) |> Keyword.get(:version)
103+
defp image_version(mix_args) do
104+
mix_args |> Keyword.get(:version)
105105
|| Application.get_env(:mix_docker, :version)
106106
|| "$mix_version.$git_count-$git_sha"
107107
end
108+
109+
@valid_args [:version]
110+
defp mix_args(args) do
111+
parse_args(args)
112+
|> Keyword.take(@valid_args)
113+
end
114+
115+
defp docker_build_args(args) do
116+
parse_args(args)
117+
|> Keyword.drop(@valid_args)
118+
|> OptionParser.to_argv
119+
end
120+
121+
defp parse_args(args) do
122+
{parsed, [], []} = OptionParser.parse(args, switches: [label: :keep], allow_nonexistent_atoms: true)
123+
parsed
124+
end
108125

109126
defp docker(:cp, cid, source, dest) do
110127
system! "docker", ["cp", "#{cid}:#{source}", dest]

0 commit comments

Comments
 (0)