Skip to content

Add docker build files#236

Draft
SteffenDE wants to merge 1 commit intohexpm:mainfrom
SteffenDE:sd-docker-txt
Draft

Add docker build files#236
SteffenDE wants to merge 1 commit intohexpm:mainfrom
SteffenDE:sd-docker-txt

Conversation

@SteffenDE
Copy link
Copy Markdown

Closes #234.

This uses a lot of Enum calls, so it is very much not memory efficient, but I don't know if that's a problem.

I decided to just assume that the cached tags are available. Since I have no good way to test this code in full, I wrote it in a Livebook with the Repo and Cache stubbed: https://gist.github.com/SteffenDE/c523ea5ccd9b97711ba07918d45e905d

(Note that it uses the files I scraped from Docker Hub, available at https://hex-bob-docker.steffend.me/all.zip)

@SteffenDE
Copy link
Copy Markdown
Author

Also, this always rewrites all files, even if the content is the same.

Comment on lines +212 to +247
defp to_matchable(string) do
destructure [version, pre], String.split(string, "-", parts: 2)

components =
version
|> String.split(".")
|> Enum.map(&String.to_integer/1)

{components, pre || []}
end

defp cmp_erlang_components({[left | lefts], left_pre}, {[right | rights], right_pre}) do
cond do
left > right -> :gt
left < right -> :lt
true -> cmp_erlang_components({lefts, left_pre}, {rights, right_pre})
end
end

defp cmp_erlang_components({[], left_pre}, {[], right_pre}) do
cond do
left_pre == [] and right_pre != [] -> :gt
left_pre != [] and right_pre == [] -> :lt
left_pre > right_pre -> :gt
left_pre < right_pre -> :lt
true -> :eq
end
end

defp cmp_erlang_components({[], _left_pre}, {_rights, _right_pre}) do
:lt
end

defp cmp_erlang_components({_lefts, _left_pre}, {[], _right_pre}) do
:gt
end
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

That could live in some shared utils module. Taken from DockerChecker.

Comment on lines +58 to +61
# elixir:1.19.5-erlang-28.3.1.txt
1.19.5-erlang-28.3.1-ubuntu-noble-20260210.1 amd64,arm64
1.19.5-erlang-28.3.1-debian-trixie-20260202-slim amd64,arm64
1.19.5-erlang-28.3.1-debian-bookworm-20260202-slim amd64,arm64
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

We could think about adding a header line or first line comment explaining that people consuming this should be prepared to handle added columns in the future.

# If you consume this file programmatically, always skip the first line. The second line contains a header. Columns are whitespace separated and we may add new columns in the future.
# tag architectures
# ...

],
[
module: Bob.Job.DockerTxtUpdater,
period: {60, :min},
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

No idea what's appropriate there.


key =
"builds/docker/" <>
String.trim_leading(repo, "hexpm/") <> ":" <> elixir <> "-erlang-" <> erlang <> ".txt"
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

As you likely want to replace only the first occurrence? Not sure if you have multiple anyway...

Suggested change
String.trim_leading(repo, "hexpm/") <> ":" <> elixir <> "-erlang-" <> erlang <> ".txt"
String.replace_leading(repo, "hexpm/", "") <> ":" <> elixir <> "-erlang-" <> erlang <> ".txt"

Comment on lines +251 to +256
|> Enum.map(fn {elixir, erlang} ->
parsed_erl = to_matchable(erlang)
{Version.parse!(normalize_version(elixir)), parsed_erl}
end)
|> Enum.filter(fn {vsn, {_erl_major, erl_pre}} -> vsn.pre == [] and erl_pre == [] end)
|> Enum.group_by(fn {vsn, _} -> {vsn.major, vsn.minor} end)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

If the concern is performance, this could be a single Enum.reduce with a Map.update(...) but, other than that, I haven't seen many more optimization points.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add txt files for docker builds

2 participants