Skip to content

Commit

Permalink
feat: Update elixir and erlang versions (#41)
Browse files Browse the repository at this point in the history
  • Loading branch information
dazuma authored Mar 25, 2022
1 parent d5069cc commit 879bcc1
Show file tree
Hide file tree
Showing 13 changed files with 167 additions and 107 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ jobs:
- name: Install Elixir
uses: actions/setup-elixir@v1
with:
otp-version: "23.3.1"
elixir-version: "1.11.4"
otp-version: "23.3.4.11"
elixir-version: "1.13.3"
experimental-otp: true
- name: Checkout repo
uses: actions/checkout@v2
Expand Down
2 changes: 2 additions & 0 deletions elixir-generate-dockerfile/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ ARG builder_image=""
ARG prebuilt_erlang_images=""
ARG default_erlang_version=""
ARG default_elixir_version=""
ARG old_distillery_erlang_version=""
ARG old_distillery_elixir_version=""

ENV DEFAULT_OS_IMAGE=${os_image} \
Expand All @@ -40,6 +41,7 @@ ENV DEFAULT_OS_IMAGE=${os_image} \
DEFAULT_PREBUILT_ERLANG_IMAGES=${prebuilt_erlang_images} \
DEFAULT_ERLANG_VERSION=${default_erlang_version} \
DEFAULT_ELIXIR_VERSION=${default_elixir_version} \
OLD_DISTILLERY_ERLANG_VERSION=${old_distillery_erlang_version} \
OLD_DISTILLERY_ELIXIR_VERSION=${old_distillery_elixir_version}

# Install the wrapper script and templates.
Expand Down
27 changes: 20 additions & 7 deletions elixir-generate-dockerfile/src/lib/app_config.ex
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,15 @@ defmodule GenerateDockerfile.AppConfig do
workspace_dir = Keyword.fetch!(args, :workspace_dir)
default_erlang_version = Keyword.fetch!(args, :default_erlang_version)
default_elixir_version = Keyword.fetch!(args, :default_elixir_version)
old_distillery_erlang_version = Keyword.fetch!(args, :old_distillery_erlang_version)
old_distillery_elixir_version = Keyword.fetch!(args, :old_distillery_elixir_version)

data =
build_data(
workspace_dir,
default_erlang_version,
default_elixir_version,
old_distillery_erlang_version,
old_distillery_elixir_version
)

Expand All @@ -90,6 +92,7 @@ defmodule GenerateDockerfile.AppConfig do
workspace_dir,
default_erlang_version,
default_elixir_version,
old_distillery_erlang_version,
old_distillery_elixir_version
) do
project_id = get_project()
Expand All @@ -101,9 +104,11 @@ defmodule GenerateDockerfile.AppConfig do
phoenix_version = Map.get(deps_info, :phoenix)
phoenix_prefix = get_phoenix_prefix(phoenix_version)

default_elixir_version =
adjust_default_elixir_version(
{default_erlang_version, default_elixir_version} =
adjust_default_erlang_and_elixir_versions(
default_erlang_version,
default_elixir_version,
old_distillery_erlang_version,
old_distillery_elixir_version,
distillery_version
)
Expand Down Expand Up @@ -212,19 +217,27 @@ defmodule GenerateDockerfile.AppConfig do
if Version.compare(version, "1.3.0") == :lt, do: "phoenix", else: "phx"
end

defp adjust_default_elixir_version(default_elixir_version, _old_distillery_elixir_version, nil) do
default_elixir_version
defp adjust_default_erlang_and_elixir_versions(
default_erlang_version,
default_elixir_version,
_old_distillery_erlang_version,
_old_distillery_elixir_version,
nil
) do
{default_erlang_version, default_elixir_version}
end

defp adjust_default_elixir_version(
defp adjust_default_erlang_and_elixir_versions(
default_erlang_version,
default_elixir_version,
old_distillery_erlang_version,
old_distillery_elixir_version,
distillery_version
) do
if Version.compare(distillery_version, "2.1.0") == :lt do
old_distillery_elixir_version
{old_distillery_erlang_version, old_distillery_elixir_version}
else
default_elixir_version
{default_erlang_version, default_elixir_version}
end
end

Expand Down
28 changes: 27 additions & 1 deletion elixir-generate-dockerfile/src/lib/generator.ex
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,13 @@ defmodule GenerateDockerfile.Generator do
default_elixir_version =
Keyword.get(opts, :default_elixir_version, System.get_env("DEFAULT_ELIXIR_VERSION"))

old_distillery_erlang_version =
Keyword.get(
opts,
:old_distillery_erlang_version,
System.get_env("OLD_DISTILLERY_ERLANG_VERSION")
)

old_distillery_elixir_version =
Keyword.get(
opts,
Expand All @@ -72,6 +79,7 @@ defmodule GenerateDockerfile.Generator do
workspace_dir,
default_erlang_version,
default_elixir_version,
old_distillery_erlang_version,
old_distillery_elixir_version
)

Expand All @@ -95,6 +103,7 @@ defmodule GenerateDockerfile.Generator do
_workspace_dir,
"",
_default_elixir_version,
_old_distillery_erlang_version,
_old_distillery_elixir_version
) do
GenerateDockerfile.error("Missing default erlang version")
Expand All @@ -104,26 +113,43 @@ defmodule GenerateDockerfile.Generator do
_workspace_dir,
_default_erlang_version,
"",
_old_distillery_erlang_version,
_old_distillery_elixir_version
) do
GenerateDockerfile.error("Missing default elixir version")
end

defp start_app_config(_workspace_dir, _default_erlang_version, _default_elixir_version, "") do
defp start_app_config(
_workspace_dir,
_default_erlang_version,
_default_elixir_version,
"",
_old_distillery_elixir_version) do
GenerateDockerfile.error("Missing default erlang version for old distillery")
end

defp start_app_config(
_workspace_dir,
_default_erlang_version,
_default_elixir_version,
_old_distillery_erlang_version,
"") do
GenerateDockerfile.error("Missing default elixir version for old distillery")
end

defp start_app_config(
workspace_dir,
default_erlang_version,
default_elixir_version,
old_distillery_erlang_version,
old_distillery_elixir_version
) do
{:ok, _} =
AppConfig.start_link(
workspace_dir: workspace_dir,
default_erlang_version: default_erlang_version,
default_elixir_version: default_elixir_version,
old_distillery_erlang_version: old_distillery_erlang_version,
old_distillery_elixir_version: old_distillery_elixir_version
)

Expand Down
1 change: 1 addition & 0 deletions elixir-generate-dockerfile/src/lib/main.ex
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ defmodule GenerateDockerfile do
prebuilt_erlang_images: :keep,
default_erlang_version: :string,
default_elixir_version: :string,
old_distillery_erlang_version: :string,
old_distillery_elixir_version: :string,
template_dir: :string
],
Expand Down
6 changes: 3 additions & 3 deletions elixir-generate-dockerfile/src/mix.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
%{
"mime": {:hex, :mime, "1.5.0", "203ef35ef3389aae6d361918bf3f952fa17a09e8e43b5aa592b93eba05d0fb8d", [:mix], [], "hexpm", "55a94c0f552249fc1a3dd9cd2d3ab9de9d3c89b559c2bd01121f824834f24746"},
"mime": {:hex, :mime, "1.6.0", "dabde576a497cef4bbdd60aceee8160e02a6c89250d6c0b29e56c0dfb00db3d2", [:mix], [], "hexpm", "31a1a8613f8321143dde1dafc36006a17d28d02bdfecb9e95a880fa7aabd19a7"},
"poison": {:hex, :poison, "3.1.0", "d9eb636610e096f86f25d9a46f35a9facac35609a7591b3be3326e99a0484665", [:mix], [], "hexpm", "fec8660eb7733ee4117b85f55799fd3833eb769a6df71ccf8903e8dc5447cfce"},
"tesla": {:hex, :tesla, "0.10.0", "e588c7e7f1c0866c81eeed5c38f02a4a94d6309eede336c1e6ca08b0a95abd3f", [:mix], [{:exjsx, ">= 0.1.0", [hex: :exjsx, repo: "hexpm", optional: true]}, {:fuse, "~> 2.4", [hex: :fuse, repo: "hexpm", optional: true]}, {:hackney, "~> 1.6", [hex: :hackney, repo: "hexpm", optional: true]}, {:ibrowse, "~> 4.2", [hex: :ibrowse, repo: "hexpm", optional: true]}, {:mime, "~> 1.0", [hex: :mime, repo: "hexpm", optional: false]}, {:poison, ">= 1.0.0", [hex: :poison, repo: "hexpm", optional: true]}], "hexpm", "bb10f37d124e2a04950e1642437fc30368cd992bd7370b38eeb3af1ebf1c2029"},
"yamerl": {:hex, :yamerl, "0.8.0", "8214cfe16bbabe5d1d6c14a14aea11c784b9a21903dd6a7c74f8ce180adae5c7", [:rebar3], [], "hexpm", "010634477bf9c208a0767dcca89116c2442cf0b5e87f9c870f85cd1c3e0c2aab"},
"yaml_elixir": {:hex, :yaml_elixir, "2.5.0", "45de762be6d75fa5a8b5f44ddff8c30f64c26526eab5b1d72e36d616007b7796", [:mix], [{:yamerl, "~> 0.7", [hex: :yamerl, repo: "hexpm", optional: false]}], "hexpm", "80fe4e43f05582f2a90f2dcd73fc6171fbd65f2e6836f71fe4ce2154ef358c36"},
"yamerl": {:hex, :yamerl, "0.10.0", "4ff81fee2f1f6a46f1700c0d880b24d193ddb74bd14ef42cb0bcf46e81ef2f8e", [:rebar3], [], "hexpm", "346adb2963f1051dc837a2364e4acf6eb7d80097c0f53cbdc3046ec8ec4b4e6e"},
"yaml_elixir": {:hex, :yaml_elixir, "2.8.0", "c7ff0034daf57279c2ce902788ce6fdb2445532eb4317e8df4b044209fae6832", [:mix], [{:yamerl, "~> 0.8", [hex: :yamerl, repo: "hexpm", optional: false]}], "hexpm", "4b674bd881e373d1ac6a790c64b2ecb69d1fd612c2af3b22de1619c15473830b"},
}
22 changes: 12 additions & 10 deletions elixir-generate-dockerfile/src/test/app_config_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@ defmodule AppConfigTest do
@test_dir __DIR__
@cases_dir Path.join(@test_dir, "app_config")
@tmp_dir Path.join(@test_dir, "tmp")
@default_erlang_version "22.0.7"
@default_elixir_version "1.9.0-otp-22"
@default_erlang_version "23.3.4.11"
@default_elixir_version "1.13.3-otp-23"
@old_distillery_erlang_version "22.3.4.17"
@old_distillery_elixir_version "1.8.2-otp-22"

@minimal_config """
Expand Down Expand Up @@ -64,6 +65,7 @@ defmodule AppConfigTest do
workspace_dir: @tmp_dir,
default_erlang_version: @default_erlang_version,
default_elixir_version: @default_elixir_version,
old_distillery_erlang_version: @old_distillery_erlang_version,
old_distillery_elixir_version: @old_distillery_elixir_version,
register_module: false
)
Expand Down Expand Up @@ -232,8 +234,8 @@ defmodule AppConfigTest do
"cd assets && npm install && node_modules/webpack/bin/webpack.js --mode production && cd .. && mix phx.digest"
]

assert AppConfig.get!(:erlang_version, pid) == "22.0.7"
assert AppConfig.get!(:elixir_version, pid) == "1.9.0-otp-22"
assert AppConfig.get!(:erlang_version, pid) == @default_erlang_version
assert AppConfig.get!(:elixir_version, pid) == @default_elixir_version
end

test "phoenix 1.4 with release" do
Expand All @@ -255,8 +257,8 @@ defmodule AppConfigTest do
"cd assets && npm install && node_modules/webpack/bin/webpack.js --mode production && cd .. && mix phx.digest"
]

assert AppConfig.get!(:erlang_version, pid) == "22.0.7"
assert AppConfig.get!(:elixir_version, pid) == "1.9.0-otp-22"
assert AppConfig.get!(:erlang_version, pid) == @default_erlang_version
assert AppConfig.get!(:elixir_version, pid) == @default_elixir_version
end

test "phoenix 1.3 defaults" do
Expand All @@ -271,8 +273,8 @@ defmodule AppConfigTest do
"cd assets && npm install && node_modules/brunch/bin/brunch build --production && cd .. && mix phx.digest"
]

assert AppConfig.get!(:erlang_version, pid) == "22.0.7"
assert AppConfig.get!(:elixir_version, pid) == "1.8.2-otp-22"
assert AppConfig.get!(:erlang_version, pid) == @old_distillery_erlang_version
assert AppConfig.get!(:elixir_version, pid) == @old_distillery_elixir_version
end

test "phoenix umbrella 1.3 defaults" do
Expand All @@ -287,8 +289,8 @@ defmodule AppConfigTest do
"cd apps/blog_web/assets && npm install && node_modules/brunch/bin/brunch build --production && cd .. && mix phx.digest"
]

assert AppConfig.get!(:erlang_version, pid) == "22.0.7"
assert AppConfig.get!(:elixir_version, pid) == "1.9.0-otp-22"
assert AppConfig.get!(:erlang_version, pid) == @default_erlang_version
assert AppConfig.get!(:elixir_version, pid) == @default_elixir_version
end

test "phoenix 1.2 defaults" do
Expand Down
56 changes: 31 additions & 25 deletions elixir-generate-dockerfile/src/test/generator_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ defmodule GeneratorTest do
@tmp_dir Path.join(@test_dir, "tmp")
@template_dir Path.expand("../../app", @test_dir)

@default_erlang_version "23.3.4.11"
@default_elixir_version "1.13.3-otp-23"
@old_distillery_erlang_version "22.3.4.17"
@old_distillery_elixir_version "1.8.2-otp-22"

@minimal_config """
env: flex
runtime: gs://elixir-runtime/elixir.yaml
Expand All @@ -35,8 +40,8 @@ defmodule GeneratorTest do
assert_dockerfile_line("## Project: (unknown)")
assert_dockerfile_line("FROM gcr.io/gcp-elixir/runtime/ubuntu18/builder AS app-build")
assert_dockerfile_line("# && apt-get install -y -q package-name")
assert_dockerfile_line("ARG erlang_version=\"22.0.7\"")
assert_dockerfile_line("ARG elixir_version=\"1.9.0-otp-22\"")
assert_dockerfile_line("ARG erlang_version=\"#{@default_erlang_version}\"")
assert_dockerfile_line("ARG elixir_version=\"#{@default_elixir_version}\"")
assert_dockerfile_line("RUN asdf plugin-update erlang")
assert_dockerfile_line("# RUN gcloud config set project my-project-id")
assert_dockerfile_line("# ENV NAME=\"value\"")
Expand Down Expand Up @@ -149,8 +154,8 @@ defmodule GeneratorTest do

run_generator("minimal", config: config)
assert_dockerfile_line("FROM gcr.io/gcp-elixir/runtime/ubuntu18/builder AS app-build")
assert_dockerfile_line("ARG erlang_version=\"22.0.7\"")
assert_dockerfile_line("ARG elixir_version=\"1.9.0-otp-22\"")
assert_dockerfile_line("ARG erlang_version=\"#{@default_erlang_version}\"")
assert_dockerfile_line("ARG elixir_version=\"#{@default_elixir_version}\"")
assert_dockerfile_line("RUN asdf plugin-update erlang")
assert_dockerfile_line("RUN mix release")
assert_dockerfile_line("COPY --from=app-build /app/_build/prod/rel/my_app /app/")
Expand Down Expand Up @@ -199,8 +204,8 @@ defmodule GeneratorTest do
run_generator("phoenix_1_3")
assert_ignore_line("priv/static")
assert_ignore_line("assets/node_modules")
assert_dockerfile_line("ARG erlang_version=\"22.0.7\"")
assert_dockerfile_line("ARG elixir_version=\"1.8.2-otp-22\"")
assert_dockerfile_line("ARG erlang_version=\"#{@old_distillery_erlang_version}\"")
assert_dockerfile_line("ARG elixir_version=\"#{@old_distillery_elixir_version}\"")
refute_dockerfile_line("RUN mix release")
refute_dockerfile_line("RUN mix distillery.release")
end
Expand All @@ -219,8 +224,8 @@ defmodule GeneratorTest do
run_generator("phoenix_umbrella_1_3")
assert_ignore_line("priv/static")
assert_ignore_line("apps/blog_web/assets/node_modules")
assert_dockerfile_line("ARG erlang_version=\"22.0.7\"")
assert_dockerfile_line("ARG elixir_version=\"1.9.0-otp-22\"")
assert_dockerfile_line("ARG erlang_version=\"#{@default_erlang_version}\"")
assert_dockerfile_line("ARG elixir_version=\"#{@default_elixir_version}\"")
refute_dockerfile_line("RUN mix release")
refute_dockerfile_line("RUN mix distillery.release")
end
Expand All @@ -244,8 +249,8 @@ defmodule GeneratorTest do
"""

run_generator("phoenix_1_3", config: config)
assert_dockerfile_line("ARG erlang_version=\"22.0.7\"")
assert_dockerfile_line("ARG elixir_version=\"1.8.2-otp-22\"")
assert_dockerfile_line("ARG erlang_version=\"#{@old_distillery_erlang_version}\"")
assert_dockerfile_line("ARG elixir_version=\"#{@old_distillery_elixir_version}\"")
assert_dockerfile_line("RUN mix release --env=prod --verbose")
end

Expand Down Expand Up @@ -276,8 +281,8 @@ defmodule GeneratorTest do
"""

run_generator("phoenix_umbrella_1_3", config: config)
assert_dockerfile_line("ARG erlang_version=\"22.0.7\"")
assert_dockerfile_line("ARG elixir_version=\"1.9.0-otp-22\"")
assert_dockerfile_line("ARG erlang_version=\"#{@default_erlang_version}\"")
assert_dockerfile_line("ARG elixir_version=\"#{@default_elixir_version}\"")
assert_dockerfile_line("RUN mix release blog")
end

Expand Down Expand Up @@ -323,8 +328,8 @@ defmodule GeneratorTest do
"""

run_generator("phoenix_1_4", config: config)
assert_dockerfile_line("ARG erlang_version=\"22.0.7\"")
assert_dockerfile_line("ARG elixir_version=\"1.9.0-otp-22\"")
assert_dockerfile_line("ARG erlang_version=\"#{@default_erlang_version}\"")
assert_dockerfile_line("ARG elixir_version=\"#{@default_elixir_version}\"")
assert_dockerfile_line("RUN mix distillery.release --env=prod --verbose")
end

Expand Down Expand Up @@ -362,12 +367,12 @@ defmodule GeneratorTest do
end

test "minimal directory with prebuilt erlang" do
run_generator("minimal", prebuilt_erlang_versions: "22.0.7")
assert_dockerfile_line("ARG erlang_version=\"22.0.7\"")
assert_dockerfile_line("ARG elixir_version=\"1.9.0-otp-22\"")
run_generator("minimal", prebuilt_erlang_versions: @default_erlang_version)
assert_dockerfile_line("ARG erlang_version=\"#{@default_erlang_version}\"")
assert_dockerfile_line("ARG elixir_version=\"#{@default_elixir_version}\"")

assert_dockerfile_line(
"COPY --from=gcr.io/gcp-elixir/runtime/ubuntu18/prebuilt/otp-22.0.7:latest"
"COPY --from=gcr.io/gcp-elixir/runtime/ubuntu18/prebuilt/otp-#{@default_erlang_version}:latest"
)
end

Expand All @@ -379,12 +384,12 @@ defmodule GeneratorTest do
release_app: my_app
"""

run_generator("minimal", config: config, prebuilt_erlang_versions: "22.0.7")
assert_dockerfile_line("ARG erlang_version=\"22.0.7\"")
assert_dockerfile_line("ARG elixir_version=\"1.9.0-otp-22\"")
run_generator("minimal", config: config, prebuilt_erlang_versions: @default_erlang_version)
assert_dockerfile_line("ARG erlang_version=\"#{@default_erlang_version}\"")
assert_dockerfile_line("ARG elixir_version=\"#{@default_elixir_version}\"")

assert_dockerfile_line(
"COPY --from=gcr.io/gcp-elixir/runtime/ubuntu18/prebuilt/otp-22.0.7:latest"
"COPY --from=gcr.io/gcp-elixir/runtime/ubuntu18/prebuilt/otp-#{@default_erlang_version}:latest"
)
end

Expand Down Expand Up @@ -434,9 +439,10 @@ defmodule GeneratorTest do
os_image: "gcr.io/gcp-elixir/runtime/ubuntu18",
asdf_image: "gcr.io/gcp-elixir/runtime/ubuntu18/asdf",
builder_image: "gcr.io/gcp-elixir/runtime/ubuntu18/builder",
default_erlang_version: "22.0.7",
default_elixir_version: "1.9.0-otp-22",
old_distillery_elixir_version: "1.8.2-otp-22"
default_erlang_version: @default_erlang_version,
default_elixir_version: @default_elixir_version,
old_distillery_erlang_version: @old_distillery_erlang_version,
old_distillery_elixir_version: @old_distillery_elixir_version
]

opts =
Expand Down
Loading

0 comments on commit 879bcc1

Please sign in to comment.