diff --git a/lib/steps/fetch/fetch_musl.ex b/lib/steps/fetch/fetch_musl.ex index 27657fb..5f6fc60 100644 --- a/lib/steps/fetch/fetch_musl.ex +++ b/lib/steps/fetch/fetch_musl.ex @@ -53,7 +53,17 @@ defmodule Burrito.Steps.Fetch.FetchMusl do defp do_download(url, cache_key) do {:ok, _} = Application.ensure_all_started(:req) Log.info(:step, "Downloading file: #{url}") - resp = Req.get!(url, raw: true) + + resp = + case Burrito.Util.get_proxy() do + proxy = %{scheme: scheme, host: host, port: port} when scheme in ["http", "https"] -> + Log.info(:step, "Using PROXY: #{proxy}") + proxy = {String.to_atom(scheme), host, port, []} + Req.get!(url, raw: true, connect_options: [proxy: proxy]) + + _ -> + Req.get!(url, raw: true) + end if resp.status != 200 do raise "Failed to fetch musl runtime: #{url}! (Got #{resp.status}) -- please file an issue! Thanks!" diff --git a/lib/util/default_erts_resolver.ex b/lib/util/default_erts_resolver.ex index 660c129..8185c99 100644 --- a/lib/util/default_erts_resolver.ex +++ b/lib/util/default_erts_resolver.ex @@ -98,7 +98,17 @@ defmodule Burrito.Util.DefaultERTSResolver do defp do_download(url, cache_key) do {:ok, _} = Application.ensure_all_started(:req) Log.info(:step, "Downloading file: #{url}") - resp = Req.get!(url, raw: true) + + resp = + case Burrito.Util.get_proxy() do + proxy = %{scheme: scheme, host: host, port: port} when scheme in ["http", "https"] -> + Log.info(:step, "Using PROXY: #{proxy}") + proxy = {String.to_atom(scheme), host, port, []} + Req.get!(url, raw: true, connect_options: [proxy: proxy]) + + _ -> + Req.get!(url, raw: true) + end if resp.status != 200 do raise "Failed to fetch #{url}! (Got #{resp.status}) Perhaps we haven't built a pre-compiled Erlang for this release yet? If this was a 404, please file an issue! Thanks!" diff --git a/lib/util/util.ex b/lib/util/util.ex index 417ca6b..8e19b85 100644 --- a/lib/util/util.ex +++ b/lib/util/util.ex @@ -47,4 +47,24 @@ defmodule Burrito.Util do def running_standalone?() do System.get_env("__BURRITO") != nil end + + @doc """ + Gets the HTTP or HTTPS proxy from environment variables, if set. + 1. Checks `HTTP_PROXY` and `http_proxy` + 2. Checks `HTTPS_PROXY` and `https_proxy` + 3. Returns `nil` if no proxy is set + """ + @spec get_proxy :: URI.t() | nil + def get_proxy do + cond do + proxy = System.get_env("HTTP_PROXY") || System.get_env("http_proxy") -> + URI.parse(proxy) + + proxy = System.get_env("HTTPS_PROXY") || System.get_env("https_proxy") -> + URI.parse(proxy) + + true -> + nil + end + end end