Skip to content

Commit

Permalink
Merge pull request #1 from alertlogic/v2
Browse files Browse the repository at this point in the history
do not include JS/npm and doing real BYOL Erlang
  • Loading branch information
Evgeny Bob authored Nov 11, 2018
2 parents c76f529 + 0064478 commit e491e80
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 29 deletions.
4 changes: 2 additions & 2 deletions priv/templates/erllambda.cfn
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,9 @@
]
}
},
"Handler": "index.handler",
"Handler": "{{name}}",
"Role": {"Fn::GetAtt": ["Role", "Arn"]},
"Runtime": "nodejs6.10",
"Runtime": "byol",
"MemorySize": 512,
"Timeout": 15
}
Expand Down
32 changes: 5 additions & 27 deletions src/rebar3_erllambda_release.erl
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,7 @@ do( State ) ->
StartScript = start_script( ErllambdaDir ),
{Command, _} = HandlerInfo = handler_info( State ),
TargetDir = rebar3_erllambda:target_dir( State ),

generate_npm_install( ErllambdaDir, TargetDir ),
generate_start_script( TargetDir, Command, StartScript ),
generate_handler_file( TargetDir, HandlerInfo ),
{ok, State}
catch
throw:Error ->
Expand All @@ -84,42 +81,23 @@ format_error( Error ) ->
%%============================================================================
%% Internal Functions
%%============================================================================
generate_npm_install( ErllambdaDir, Dir ) ->
rebar_api:info( "generating erllambda npm install", [] ),
Command = [ErllambdaDir, "/priv/npm-install ", ErllambdaDir, $ , Dir],
case rebar3_erllambda:os_cmd( Command ) of
0 -> ok;
Status -> throw( {npm_install_failed, Status} )
end.


generate_start_script( Dir, Command, Script ) ->
rebar_api:info( "generating start script bin/~s", [Command] ),
Filename = filename:join( [Dir, rebar3_erllambda:list(Command)] ),
case file:write_file( Filename, Script ) of
ok -> generate_start_script( Filename );
ok ->
ok = generate_start_script( Dir, Filename ),
%% create necessary symlink
ok = file:make_symlink( "/var/task/" ++ rebar3_erllambda:list(Command), filename:join( [Dir, "bootstrap"]));
{error, Reason} -> throw( {generate_start_script_failed, Reason} )
end.

generate_start_script( Filename ) ->
generate_start_script( Dir, Filename ) ->
Mode = 8#00755,
case file:change_mode( Filename, Mode ) of
ok -> ok;
{error, Reason} -> throw( {generate_start_script_failed, Reason} )
end.


generate_handler_file( Dir, {Command, Module} ) ->
rebar_api:info( "generating config file etc/handler.json", [] ),
Filename = filename:join( [Dir, "etc", "handler.json"] ),
Content = iolist_to_binary(
["{\"command\": \"", rebar3_erllambda:list(Command), "\","
" \"module\": \"", rebar3_erllambda:list(Module), "\"}"] ),
filelib:ensure_dir( Filename ),
case file:write_file( Filename, Content ) of
ok -> ok;
{error, Reason} -> throw( {generate_handler_file_failed, Reason} )
end.


handler_info( State ) ->
Expand Down

0 comments on commit e491e80

Please sign in to comment.