Current section

11 Versions

Jump to

Compare versions

10 files changed
+148 additions
-89 deletions
  @@ -19,3 +19,5 @@ Documentation can be generated with [ExDoc](https://github.com/elixir-lang/ex_do
19 19 and published on [HexDocs](https://hexdocs.pm). Once published, the docs can
20 20 be found at <https://hexdocs.pm/aws_runtime>.
21 21
22 +
23 + Source: "https://bernerbits.medium.com/erlang-and-elixir-in-aws-lambda-using-container-images-part-2-ad7b9863cfd4"
  @@ -5,7 +5,10 @@
5 5 {<<"elixir">>,<<"~> 1.13">>}.
6 6 {<<"files">>,
7 7 [<<"lib">>,<<"lib/aws_runtime">>,<<"lib/aws_runtime/application.ex">>,
8 + <<"lib/templates">>,<<"lib/templates/base_dockerfile.eex">>,
9 + <<"lib/templates/makefile.eex">>,<<"lib/templates/dockerfile.eex">>,
8 10 <<"lib/mix">>,<<"lib/mix/tasks">>,<<"lib/mix/tasks/gen_dockerfile.ex">>,
11 + <<"lib/mix/tasks/gen_makefile.ex">>,
9 12 <<"lib/mix/tasks/gen_lambda_release.ex">>,<<"lib/aws_runtime.ex">>,
10 13 <<".formatter.exs">>,<<"mix.exs">>,<<"README.md">>,<<"LICENSE.md">>,
11 14 <<"CHANGELOG.md">>]}.
  @@ -15,4 +18,4 @@
15 18 <<"https://github.com/NeoArcanjo/aws-lambda-runtime-boilerplate">>}]}.
16 19 {<<"name">>,<<"aws_runtime">>}.
17 20 {<<"requirements">>,[]}.
18 - {<<"version">>,<<"0.1.4-alpha">>}.
21 + {<<"version">>,<<"0.1.4">>}.
  @@ -2,17 +2,4 @@ defmodule AwsRuntime do
2 2 @moduledoc """
3 3 Documentation for `AwsRuntime`.
4 4 """
5 -
6 - @doc """
7 - Hello world.
8 -
9 - ## Examples
10 -
11 - iex> AwsRuntime.hello()
12 - :world
13 -
14 - """
15 - def hello do
16 - :world
17 - end
18 5 end
  @@ -16,7 +16,6 @@ defmodule Mix.Tasks.Aws.Gen.Dockerfile do
16 16 end
17 17
18 18 def run(args) do
19 - # todo: obter do cli a elixir version e erlang version
20 19 name =
21 20 Mix.Project.config()
22 21 |> Keyword.fetch!(:app)
  @@ -37,84 +36,33 @@ defmodule Mix.Tasks.Aws.Gen.Dockerfile do
37 36
38 37 iex_version = Keyword.get(opts, :elixir, "1.13.1")
39 38 erl_version = Keyword.get(opts, :erlang, "24.3.2")
39 + path = Application.app_dir(:aws_runtime, "lib/templates")
40 + IO.inspect(path)
41 + IO.inspect(File.ls!(path))
42 + Mix.Generator.copy_template(Path.join(path, "dockerfile.eex"), "Dockerfile", app: name)
40 43
41 - Mix.Generator.create_file(
42 - "Dockerfile",
43 - dockerfile_template(:app, name)
44 + Mix.Generator.copy_template(Path.join(path, "base_dockerfile.eex"), "images/base.Dockerfile",
45 + elixir_version: iex_version,
46 + otp_version: erl_version
44 47 )
45 48
46 - Mix.Generator.create_file(
47 - "images/base.Dockerfile",
48 - dockerfile_template(:base, iex_version, erl_version)
49 - )
49 + Mix.Generator.copy_file(".gitignore", ".dockerignore")
50 + File.write!(".dockerignore", dockerignore(), [:append])
50 51 end
51 52
52 - defp dockerfile_template(:base, iex_version, erl_version) do
53 + defp dockerignore do
53 54 """
54 - FROM public.ecr.aws/amazonlinux/amazonlinux:latest as root
55 + /.make/
56 + /images/
57 + Dockerfile
58 + .dockerignore
59 + .gitignore
60 + Makefile
61 + README.md
55 62
56 - RUN yum install deltarpm -y
57 - RUN yum update -y
58 - RUN yum install https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm -y
59 - RUN yum install ncurses-libs openssl-libs flex java-1.8.0-openjdk libxslt fop -y
60 -
61 - ENV LANG=c.UTF-8
62 - ENV LC_COLLATE="en_US.UTF-8"
63 - ENV LC_CTYPE="en_US.UTF-8"
64 - ENV LC_MESSAGES="en_US.UTF-8"
65 - ENV LC_MONETARY="en_US.UTF-8"
66 - ENV LC_NUMERIC="en_US.UTF-8"
67 - ENV LC_TIME="en_US.UTF-8"
68 - ENV LC_ALL="en_US.UTF-8"
69 - ENV ELIXIR_VERSION="v#{iex_version}"
70 - ENV OTP_VERSION="OTP-#{erl_version}"
71 -
72 - FROM root as buildelixir
73 -
74 - RUN yum install git perl ncurses-devel openssl-devel flex-devel java-1.8.0-openjdk-devel libxslt-devel sed -y
75 - RUN yum groupinstall "Development Tools" -y
76 - RUN git clone https://github.com/erlang/otp.git erlang
77 - RUN git clone https://github.com/elixir-lang/elixir.git
78 -
79 - ENV ERL_TOP=/erlang
80 - WORKDIR /erlang
81 - RUN git checkout $OTP_VERSION
82 - RUN ./configure --prefix=/opt/erlang
83 - RUN make
84 - RUN make release_tests
85 - WORKDIR /erlang/release/tests/test_server
86 - RUN /erlang/bin/erl -s ts install -s ts smoke_test batch -s init stop
87 - WORKDIR /erlang
88 - RUN make install
89 -
90 - ENV PATH="$PATH:/opt/erlang/bin:/opt/erlang/lib"
91 - WORKDIR /elixir
92 - RUN git checkout ${ELIXIR_VERSION}
93 - RUN make clean test
94 - RUN make install PREFIX=/opt/elixir
95 -
96 - FROM root
97 -
98 - COPY --from=buildelixir /opt/erlang /opt/erlang
99 - COPY --from=buildelixir /opt/elixir /opt/elixir
100 - ENV PATH="$PATH:/opt/erlang/bin:/opt/erlang/lib:/opt/elixir/bin:/opt/elixir/lib"
101 - RUN mix local.hex --force
102 - RUN epmd -daemon
103 - """
104 - end
105 -
106 - defp dockerfile_template(:app, app) do
107 - """
108 - FROM elixirbase:latest
109 -
110 - ENV MIX_ENV=dev
111 -
112 - COPY . /#{app}
113 - WORKDIR /#{app}
114 -
115 - RUN mix deps.get
116 - RUN mix compile
117 - CMD mix app.start
63 + # IntelliJ files
64 + /.idea/
65 + \*.iml
118 66 """
119 67 end
120 68 end
  @@ -1,11 +1,11 @@
1 1 defmodule Mix.Tasks.GenLambdaRelease do
2 2 @moduledoc """
3 - Generate a distillery release configuration file for lambda release builds.
3 + Generate a release configuration file for lambda release builds.
4 4 """
5 5
6 6 use Mix.Task
7 7
8 - @shortdoc "Generate a distillery release for AWS Lambda"
8 + @shortdoc "Generate a release for AWS Lambda"
9 9 def run(_) do
10 10 name =
11 11 Mix.Project.config()
Loading more files…