Current section

Files

Jump to
lambda_base lib mix tasks lambda_release.ex
Raw

lib/mix/tasks/lambda_release.ex

defmodule Mix.Tasks.LambdaRelease do
use Mix.Task
@bootstrap """
#!/bin/sh
set -euo pipefail
export HOME=/
RESPONSE=$(bin/app eval "$(echo "$_HANDLER").start()")
"""
@impl Mix.Task
def run(_args) do
app_name = Mix.Project.config |> Keyword.get(:app) |> to_string
Mix.Shell.cmd("rm -f -R ./_build/.tmp", &IO.puts/1)
Mix.Shell.cmd("mkdir -p ./_build/.tmp", &IO.puts/1)
Mix.env(:prod)
Mix.Task.run("release")
Mix.Shell.cmd("cp -a ./_build/prod/rel/bot_lambda/* ./_build/.tmp/", &IO.puts/1)
File.write("./_build/.tmp/bootstrap", @bootstrap)
Mix.Shell.cmd("mv ./_build/.tmp/bin/#{app_name} ./_build/.tmp/bin/app", &IO.puts/1)
Mix.Shell.cmd("rm -f ./_build/.tmp/bin/#{app_name}.bat", &IO.puts/1)
Mix.Shell.cmd("chmod +x ./_build/.tmp/bin/app", &IO.puts/1)
Mix.Shell.cmd("chmod +x ./_build/.tmp/releases/0.1.0/elixir", &IO.puts/1)
Mix.Shell.cmd("chmod +x ./_build/.tmp/erts-10.6/bin/erl", &IO.puts/1)
Mix.Shell.cmd("chmod +x ./_build/.tmp/bootstrap", &IO.puts/1)
Mix.Shell.cmd("cd ./_build/.tmp; zip #{app_name} -r *", &IO.puts/1)
Mix.Shell.cmd("mv -f ./_build/.tmp/#{app_name}.zip ./_build/", &IO.puts/1)
Mix.Shell.cmd("rm -f -R ./_build/.tmp", &IO.puts/1)
end
end