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

Commit b883c88

Browse files
committed
Use simple String replacements instead of Code.eval_string
1 parent b688ef4 commit b883c88

2 files changed

Lines changed: 12 additions & 8 deletions

File tree

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,19 +72,19 @@ config :hello, Hello.Mailer,
7272

7373
#### How to configure the image version?
7474

75-
By default, the image version uses the following format: `#{mix_version}.#{git_count}-#{git_sha}`
75+
By default, the image version uses the following format: `$mix_version.$git_count-$git_sha`
7676
You can provide your own version in `config/prod.exs` like this:
7777

7878
```elixir
7979
# config/config.exs
8080
config :mix_docker,
81-
version: "\#{mix_version}_\#{git_sha}"
81+
version: "$mix_version_$git_sha"
8282
```
8383

8484
Additionally, you can pass the version as an argument to `mix docker.publish` and `mix docker.shipit`:
8585

8686
```bash
87-
mix docker.publish --version "#{mix_version}_#{git_sha}"
87+
mix docker.publish --version "$mix_version_$git_sha"
8888
```
8989

9090

lib/mix_docker.ex

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ defmodule MixDocker do
6767
{sha, 0} <- System.cmd("git", ["rev-parse", "HEAD"]) do
6868
String.slice(sha, 0, 10)
6969
else
70-
_ -> nil
70+
_ -> ""
7171
end
7272
end
7373

@@ -76,7 +76,7 @@ defmodule MixDocker do
7676
{count, 0} <- System.cmd("git", ["rev-list", "--count", "HEAD"]) do
7777
String.trim(count)
7878
else
79-
_ -> nil
79+
_ -> ""
8080
end
8181
end
8282

@@ -93,13 +93,17 @@ defmodule MixDocker do
9393
count = git_commit_count()
9494
sha = git_head_sha()
9595

96-
Code.eval_string(version_template, mix_version: version, git_count: count, git_sha: sha) |> elem(0)
96+
version_template
97+
|> String.replace("$mix_version", version)
98+
|> String.replace("$git_count", count)
99+
|> String.replace("$git_sha", sha)
97100
end
98101
defp image_tag(tag), do: tag
99102

100103
defp image_version(args) do
101-
version = (OptionParser.parse(args) |> elem(0) |> Keyword.get(:version, Application.get_env(:mix_docker, :version, "\#{mix_version}.\#{git_count}-\#{git_sha}")))
102-
"\"" <> version <> "\""
104+
OptionParser.parse(args) |> elem(0) |> Keyword.get(:version)
105+
|| Application.get_env(:mix_docker, :version)
106+
|| "$mix_version.$git_count-$git_sha"
103107
end
104108

105109
defp docker(:cp, cid, source, dest) do

0 commit comments

Comments
 (0)