Skip to content
Open
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
8 changes: 6 additions & 2 deletions lib/ex_docker_build/docker_build.ex
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,12 @@ defmodule ExDockerBuild.DockerBuild do
|> ExDockerBuild.create_layer()
end

# defp exec({"ARG", args}, context, _path) do
# end
defp exec({"ARG", args}, context, _path) do
args = String.split(args, "=")

Map.merge(context, %{"Args" => Enum.at(args, 2)})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Args attribute doesn't exist, doing a short search through google i didn't found anything related to this, so, don't even know if this is possible, did you test it?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i found something https://docs.docker.com/engine/api/v1.37/#operation/ImageBuild, it has an attribute called buildargs which is only used when building the image, but not the container

Copy link
Contributor Author

@filipevarjao filipevarjao Jan 23, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't test using for real, only the test cover. I thought we had some args in the Bryan example.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can see an example of use here - and here

Copy link
Contributor

@sescobb27 sescobb27 Jan 24, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven’t been able to find anything about how to add support for ARG, I found about buildargs but is only supported when building a Dockerfile via build but we are not using it because we are building it manually (https://docs.docker.com/engine/api/v1.37/#operation/ImageBuild).

|> ExDockerBuild.create_layer()
end

# Supports:
# VOLUME volume_name for named volumes
Expand Down
2 changes: 1 addition & 1 deletion mix.lock
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@
"redbug": {:hex, :redbug, "1.2.1", "9153ee50e42c39ce3f6efa65ee746f4a52896da66862cfb59e7c0f838b7b8414", [:rebar3], [], "hexpm"},
"rexbug": {:hex, :rexbug, "1.0.0", "52b5d25c423f1c31ecce6960a556cac6391f62d61945f305248b07149567456c", [:mix], [{:redbug, "~> 1.2", [hex: :redbug, repo: "hexpm", optional: false]}], "hexpm"},
"ssl_verify_fun": {:hex, :ssl_verify_fun, "1.1.1", "28a4d65b7f59893bc2c7de786dec1e1555bd742d336043fe644ae956c3497fbe", [:make, :rebar], [], "hexpm"},
"tracer": {:git, "git@github.com:gabiz/tracer.git", "4659bf3cc9e0cc86e653794b800e9eb5bbe9f0a2", [branch: "master"]},
"tracer": {:git, "https://github.com/gabiz/tracer.git", "4659bf3cc9e0cc86e653794b800e9eb5bbe9f0a2", [branch: "master"]},
"unicode_util_compat": {:hex, :unicode_util_compat, "0.3.1", "a1f612a7b512638634a603c8f401892afbf99b8ce93a45041f8aaca99cadb85e", [:rebar3], [], "hexpm"},
}
46 changes: 46 additions & 0 deletions test/integration/docker_build_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -259,4 +259,50 @@ defmodule ExDockerBuild.Integration.DockerBuildTest do
assert "/bin/sh -c #(nop) ADD file:" <> <<_::binary-size(64)>> <> " in / " = command
end
end

describe "defining variables at build-time" do
test "setting ARG instruction" do
instructions = [
{"FROM", "alpine:latest"},
{"ARG", "tag=\"latest\""},
{"RUN", "mkdir /myvol"},
{"RUN", "echo \"hello-world!!!!\" > /myvol/greeting"}
]

log =
capture_log(fn ->
assert {:ok, image_id} = DockerBuild.build(instructions, "")
end)

assert log =~ "STEP 1/4 : FROM alpine:latest"
assert log =~ "pulling image alpine:latest"
assert log =~ "STEP 2/4 : ARG tag=\"latest\""
assert log =~ "STEP 3/4 : RUN mkdir /myvol"
assert log =~ "STEP 4/4 : RUN echo \"hello-world!!!!\" > /myvol/greeting"
end

test "setting multiple args" do
instructions = [
{"FROM", "alpine:latest"},
{"ARG", "tag=\"latest\""},
{"ARG", "A_VARIABLE="},
{"ENV", "an_env_var=$A_VARIABLE"},
{"RUN", "mkdir /myvol"},
{"RUN", "echo \"hello-world!!!!\" > /myvol/greeting"}
]

log =
capture_log(fn ->
assert {:ok, image_id} = DockerBuild.build(instructions, "")
end)

assert log =~ "STEP 1/6 : FROM alpine:latest"
assert log =~ "pulling image alpine:latest"
assert log =~ "STEP 2/6 : ARG tag=\"latest\""
assert log =~ "STEP 3/6 : ARG A_VARIABLE="
assert log =~ "STEP 4/6 : ENV an_env_var=$A_VARIABLE"
assert log =~ "STEP 5/6 : RUN mkdir /myvol"
assert log =~ "STEP 6/6 : RUN echo \"hello-world!!!!\" > /myvol/greeting"
end
end
end