Browse Source

update erlang runtime and dependencies (#7685)

Chris Garvis 2 years ago
parent
commit
b92eba2221

+ 1 - 1
frameworks/Erlang/chicagoboss/chicagoboss.dockerfile

@@ -1,4 +1,4 @@
-FROM erlang:18.3.4.8
+FROM erlang:25.1-alpine
 
 
 ADD ./ /chicagoboss
 ADD ./ /chicagoboss
 WORKDIR /chicagoboss
 WORKDIR /chicagoboss

+ 1 - 1
frameworks/Erlang/chicagoboss/rebar.config

@@ -1,5 +1,5 @@
 {deps, [
 {deps, [
-  {boss, ".*", {git, "git://github.com/ChicagoBoss/ChicagoBoss.git", {tag, "v0.9.pre-alpha-2"}}}
+  {boss, ".*", {git, "git://github.com/ChicagoBoss/ChicagoBoss.git", {tag, "0.9.0"}}}
 ]}.
 ]}.
 {plugin_dir, ["priv/rebar"]}.
 {plugin_dir, ["priv/rebar"]}.
 {plugins, [boss_plugin]}.
 {plugins, [boss_plugin]}.

+ 1 - 1
frameworks/Erlang/cowboy/cowboy.dockerfile

@@ -1,4 +1,4 @@
-FROM erlang:21.1.1
+FROM erlang:25.1
 
 
 ADD ./ /cowboy
 ADD ./ /cowboy
 WORKDIR /cowboy
 WORKDIR /cowboy

+ 2 - 2
frameworks/Erlang/cowboy/rebar.config

@@ -1,7 +1,7 @@
 {deps,
 {deps,
  [
  [
-  {jiffy, ".*", {git, "https://github.com/davisp/jiffy.git", {tag, "0.15.2"}}},
+  {jiffy, ".*", {git, "https://github.com/davisp/jiffy.git", {tag, "1.1.1"}}},
   {mimetypes, ".*", {git, "http://github.com/spawngrid/mimetypes.git", {branch, master}}},
   {mimetypes, ".*", {git, "http://github.com/spawngrid/mimetypes.git", {branch, master}}},
   {emysql, ".*", {git, "https://github.com/deadtrickster/Emysql.git", "52b802098322aad372198b9f5fa9ae9a4c758ad1"}},
   {emysql, ".*", {git, "https://github.com/deadtrickster/Emysql.git", "52b802098322aad372198b9f5fa9ae9a4c758ad1"}},
-  {cowboy, ".*", {git, "https://github.com/ninenines/cowboy.git", {tag, "2.5.0"}}}
+  {cowboy, ".*", {git, "https://github.com/ninenines/cowboy.git", {tag, "2.9.0"}}}
  ]}.
  ]}.

+ 18 - 18
frameworks/Erlang/cowboy/src/hello_world_app.erl

@@ -17,23 +17,23 @@
 
 
 
 
 start(_Type, _Args) ->
 start(_Type, _Args) ->
-        crypto:start(),
-        application:start(emysql),
-        emysql:add_pool(test_pool, 256,
-          "benchmarkdbuser", "benchmarkdbpass", "tfb-database", 3306,
-          "hello_world", utf8),
-	emysql:prepare(db_stmt, <<"SELECT * FROM World where id = ?">>),
-	Dispatch = cowboy_router:compile([
-		{'_', [
-      {"/plaintext", plaintext_handler, []},
-			{"/json", json_handler, []},
-			{"/db", db_handler, []},
-      {"/query", query_handler, []}
-		]}
-	]),
-	{ok, _} = cowboy:start_clear(http, [{port, 8080}], #{env => #{dispatch => Dispatch}}
-	),
-	hello_world_sup:start_link().
+    crypto:start(),
+    application:start(emysql),
+    emysql:add_pool(test_pool, 256,
+                    "benchmarkdbuser", "benchmarkdbpass", "tfb-database", 3306,
+                    "hello_world", utf8),
+    emysql:prepare(db_stmt, <<"SELECT * FROM World where id = ?">>),
+    Dispatch = cowboy_router:compile([
+                                      {'_', [
+                                             {"/plaintext", plaintext_handler, []},
+                                             {"/json", json_handler, []},
+                                             {"/db", db_handler, []},
+                                             {"/query", query_handler, []}
+                                            ]}
+                                     ]),
+    {ok, _} = cowboy:start_clear(http, [{port, 8080}], #{env => #{dispatch => Dispatch}}
+                                ),
+    hello_world_sup:start_link().
 
 
 stop(_State) ->
 stop(_State) ->
-	ok.
+    ok.

+ 1 - 1
frameworks/Erlang/elli/elli.dockerfile

@@ -1,4 +1,4 @@
-FROM erlang:18.3.4.8
+FROM erlang:25.1
 
 
 WORKDIR /elli
 WORKDIR /elli
 COPY src src
 COPY src src

+ 2 - 2
frameworks/Erlang/elli/rebar.config

@@ -1,6 +1,6 @@
 {deps,
 {deps,
  [
  [
-  {jiffy, ".*", {git, "https://github.com/davisp/jiffy.git", {tag, "0.15.0"}}},
+  {jiffy, ".*", {git, "https://github.com/davisp/jiffy.git", {tag, "1.1.1"}}},
   {emysql, ".*", {git, "https://github.com/deadtrickster/Emysql.git", "52b802098322aad372198b9f5fa9ae9a4c758ad1"}},
   {emysql, ".*", {git, "https://github.com/deadtrickster/Emysql.git", "52b802098322aad372198b9f5fa9ae9a4c758ad1"}},
-  {elli, "", {git, "https://github.com/knutin/elli.git", {tag, "v1.0.5"}}}
+  {elli, ".*", {git, "https://github.com/elli-lib/elli.git", {tag, "3.3.0"}}}
  ]}.
  ]}.

+ 1 - 1
frameworks/Erlang/mochiweb/mochiweb.dockerfile

@@ -1,4 +1,4 @@
-FROM erlang:18.3.4.8
+FROM erlang:23
 
 
 ADD ./ /mochiweb
 ADD ./ /mochiweb
 WORKDIR /mochiweb
 WORKDIR /mochiweb

+ 3 - 3
frameworks/Erlang/mochiweb/rebar.config

@@ -1,9 +1,9 @@
 %% -*- erlang -*-
 %% -*- erlang -*-
 {deps, [
 {deps, [
-  {mochiweb, "2.9.0", {git, "https://github.com/mochi/mochiweb.git", {tag, "v2.9.0"}}},
-  {jsonx, ".*", {git, "https://github.com/iskra/jsonx.git", "9c95948c6835827ed61a9506ae4a9aba61acf335"}},
+  {mochiweb, ".*", {git, "https://github.com/mochi/mochiweb.git", {tag, "v2.20.1"}}},
+  {jiffy, ".*", {git, "https://github.com/davisp/jiffy.git", {tag, "1.1.1"}}},
   {emysql, ".*", {git, "https://github.com/deadtrickster/Emysql.git"}},
   {emysql, ".*", {git, "https://github.com/deadtrickster/Emysql.git"}},
-  {erlydtl, "0.11.1", {git, "https://github.com/erlydtl/erlydtl.git", {tag, "0.11.1"}}}
+  {erlydtl, ".*", {git, "https://github.com/erlydtl/erlydtl.git", {tag, "0.14.0"}}}
 ]}.
 ]}.
 {erlydtl_opts, [
 {erlydtl_opts, [
     {doc_root,   "priv/templates"},
     {doc_root,   "priv/templates"},

+ 6 - 8
frameworks/Erlang/mochiweb/src/erl_bench.erl

@@ -2,22 +2,20 @@
 -export([hello_json/0, hello_plain/0, random_json/0, randoms_json/1, update_randoms_json/1, fortunes_html/0]).
 -export([hello_json/0, hello_plain/0, random_json/0, randoms_json/1, update_randoms_json/1, fortunes_html/0]).
 
 
 hello_json() ->
 hello_json() ->
-    jsonx:encode([{<<"message">>, <<"Hello, World!">>}]).
+    {[{<<"message">>, <<"Hello, World!">>}]}.
 
 
 hello_plain() ->
 hello_plain() ->
     <<"Hello, world!">>.
     <<"Hello, world!">>.
 
 
 random_json() ->
 random_json() ->
     RandomId = randoms:random_id(),
     RandomId = randoms:random_id(),
-    jsonx:encode(find(RandomId)).
+    find(RandomId).
 
 
 randoms_json(Count) ->
 randoms_json(Count) ->
-    Json = [find(Id) || Id <- randoms:random_ids(Count)],
-    jsonx:encode(Json).
+    [find(Id) || Id <- randoms:random_ids(Count)].
 
 
 update_randoms_json(Count) ->
 update_randoms_json(Count) ->
-    Json = [update(Id) || Id <- randoms:random_ids(Count)],
-    jsonx:encode(Json).
+    [update(Id) || Id <- randoms:random_ids(Count)].
 
 
 fortunes_html() ->
 fortunes_html() ->
     Props = [[{message, Message}, {id, Id}] || {Message, Id} <- fortunes:all()],
     Props = [[{message, Message}, {id, Id}] || {Message, Id} <- fortunes:all()],
@@ -28,8 +26,8 @@ fortunes_html() ->
 
 
 find(Id) ->
 find(Id) ->
     {Id, RandomNumber} = randoms:find(Id),
     {Id, RandomNumber} = randoms:find(Id),
-    [{<<"id">>, Id}, {<<"randomNumber">>, RandomNumber}].
+    {[{<<"id">>, Id}, {<<"randomNumber">>, RandomNumber}]}.
 
 
 update(Id) ->
 update(Id) ->
     {Id, RandomNumber} = randoms:update(Id),
     {Id, RandomNumber} = randoms:update(Id),
-    [{<<"id">>, Id}, {<<"randomNumber">>, RandomNumber}].
+    {[{<<"id">>, Id}, {<<"randomNumber">>, RandomNumber}]}.

+ 2 - 3
frameworks/Erlang/mochiweb/src/randoms.erl

@@ -4,11 +4,10 @@
 -define(world_max_records, 10000).
 -define(world_max_records, 10000).
 
 
 init() ->
 init() ->
-    random:seed(erlang:now()),
     emysql:prepare(find_random, <<"SELECT id, randomNumber FROM World WHERE id = ? LIMIT 1;">>),
     emysql:prepare(find_random, <<"SELECT id, randomNumber FROM World WHERE id = ? LIMIT 1;">>),
     emysql:prepare(update_random, <<"UPDATE World SET randomNumber = ? WHERE id = ? LIMIT 1;">>).
     emysql:prepare(update_random, <<"UPDATE World SET randomNumber = ? WHERE id = ? LIMIT 1;">>).
 
 
-random_id() -> random:uniform(?world_max_records).
+random_id() -> rand:uniform(?world_max_records).
 
 
 random_ids(Times) -> random_ids(Times, []).
 random_ids(Times) -> random_ids(Times, []).
 
 
@@ -20,7 +19,7 @@ find(Id) ->
     {Id, RandomNumber}.
     {Id, RandomNumber}.
 
 
 update(Id) ->
 update(Id) ->
-    NewRandomNumber = random:uniform(10000),
+    NewRandomNumber = rand:uniform(10000),
     emysql:execute(db_pool, update_random, [NewRandomNumber, Id]),
     emysql:execute(db_pool, update_random, [NewRandomNumber, Id]),
     {Id, NewRandomNumber}.
     {Id, NewRandomNumber}.
 
 

+ 16 - 18
frameworks/Erlang/mochiweb/src/web_handler.erl

@@ -9,51 +9,49 @@ stop() ->
     mochiweb_http:stop(?MODULE).
     mochiweb_http:stop(?MODULE).
 
 
 dispatch(Req) ->
 dispatch(Req) ->
-    Method = Req:get(method),
-    Path = string:tokens(Req:get(path), "/"),
+    Method = mochiweb_request:get(method, Req),
+    Path = mochiweb_request:get(path, Req),
     handle(Method, Path, Req).
     handle(Method, Path, Req).
 
 
 %% handle
 %% handle
 
 
-handle('GET', ["json"], Req) ->
+handle('GET', "/json", Req) ->
     json(Req, erl_bench:hello_json());
     json(Req, erl_bench:hello_json());
 
 
-handle('GET', ["plaintext"], Req) ->
+handle('GET', "/plaintext", Req) ->
     plain(Req, erl_bench:hello_plain());
     plain(Req, erl_bench:hello_plain());
 
 
-handle('GET', ["db"], Req) ->
-    json(Req, erl_bench:random_json());
+handle('GET', "/db", Req) ->
+    Json = erl_bench:random_json(),
+    json(Req, Json);
 
 
-handle('GET', ["queries"], Req) ->
+handle('GET', "/queries", Req) ->
     Queries = queries(Req),
     Queries = queries(Req),
     json(Req, erl_bench:randoms_json(Queries));
     json(Req, erl_bench:randoms_json(Queries));
 
 
-handle('GET', ["updates"], Req) ->
+handle('GET', "/updates", Req) ->
     Queries = queries(Req),
     Queries = queries(Req),
     json(Req, erl_bench:update_randoms_json(Queries));
     json(Req, erl_bench:update_randoms_json(Queries));
 
 
-handle('GET', ["fortunes"], Req) ->
-    fortune(Req, erl_bench:fortunes_html());
+handle('GET', "/fortunes", Req) ->
+    html(Req, erl_bench:fortunes_html());
 
 
 handle(_Method, _Path, Req) ->
 handle(_Method, _Path, Req) ->
-    Req:respond({404, [{"Content-Type", "text/plain"}], "Not Found"}).
+    mochiweb_request:respond({404, [{"Content-Type", "text/plain"}], "404 Not Found"}, Req).
 
 
 %% private
 %% private
 
 
 json(Req, Json) ->
 json(Req, Json) ->
-    Req:ok({"application/json", Json}).
+    mochiweb_request:ok({"application/json", jiffy:encode(Json)}, Req).
 
 
 plain(Req, Text) ->
 plain(Req, Text) ->
-    Req:ok({"text/plain", Text}).
+    mochiweb_request:ok({"text/plain", Text}, Req).
 
 
 html(Req, Html) ->
 html(Req, Html) ->
-    Req:ok({"text/html", Html}).
-
-fortune(Req, Html) ->
-    Req:ok({"text/html;charset=UTF-8", Html}).
+    mochiweb_request:ok({"text/html;charset=UTF-8", Html}, Req).
 
 
 queries(Req) ->
 queries(Req) ->
-    Params = Req:parse_qs(),
+    Params = mochiweb_request:parse_qs(Req),
     Queries = (catch list_to_integer(proplists:get_value("queries", Params, "1"))),
     Queries = (catch list_to_integer(proplists:get_value("queries", Params, "1"))),
     case {is_number(Queries), Queries > 500} of
     case {is_number(Queries), Queries > 500} of
         {true, true} -> 500;
         {true, true} -> 500;