Skip to content

Commit

Permalink
Add CLI (#14)
Browse files Browse the repository at this point in the history
* add CLI

* add comment to build_binary.sh
  • Loading branch information
mat-hek authored Aug 19, 2024
1 parent 4ade6ed commit ab533fe
Show file tree
Hide file tree
Showing 10 changed files with 143 additions and 11 deletions.
8 changes: 4 additions & 4 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,20 @@ workflows:
build:
jobs:
- elixir/build_test:
cache-version: 6
cache-version: 7
filters: &filters
tags:
only: /v.*/
- elixir/test:
cache-version: 6
cache-version: 7
filters:
<<: *filters
- elixir/lint:
cache-version: 6
cache-version: 7
filters:
<<: *filters
- elixir/hex_publish:
cache-version: 6
cache-version: 7
requires:
- elixir/build_test
- elixir/test
Expand Down
12 changes: 7 additions & 5 deletions .formatter.exs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
inputs = [
"{lib,test,config}/**/*.{ex,exs}",
".formatter.exs",
"*.exs"
]

[
inputs: [
"{lib,test,config}/**/*.{ex,exs}",
".formatter.exs",
"*.exs"
],
inputs: inputs ++ Enum.map(inputs, &"boombox_burrito/#{&1}"),
import_deps: [:membrane_core]
]
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/boombox
compile_commands.json
.gdb_history
bundlex.sh
Expand Down
25 changes: 25 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,31 @@ end

See `examples.livemd` for usage examples.

## CLI app

To build a CLI app, clone the repo and run

```
mix deps.get
./build_binary.sh
```

It should generate a single executable called `boombox`, which you can run.

The CLI API is similar to the Elixir API, for example:

```elixir
Boombox.run(input: "file.mp4", output: {:webrtc, "ws://localhost:8830"})
```

is equivalent to:

```
./boombox -i file.mp4 -o -webrtc ws://localhost:8830
```

The first run of the CLI may take longer than usual, as the necessary artifacts are installed in the system.

## Copyright and License

Copyright 2020, [Software Mansion](https://swmansion.com/?utm_source=git&utm_medium=readme&utm_campaign=boombox)
Expand Down
10 changes: 10 additions & 0 deletions build_binary.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
MIX_ENV=prod BOOMBOX_BURRITO=true mix release --overwrite && \
mv burrito_out/boombox_current boombox && \
rm -r burrito_out && \
# Burrito extracts the compressed artifacts into a common
# location in the system on a first run, and then reuses
# those artifacts and checks the version in mix.exs to
# know whether it car reuse them. So we need to uninstall
# the artifacts to force burrito to extract them again
# even if the version in mix.exs didn't change
yes | ./boombox maintenance uninstall
5 changes: 5 additions & 0 deletions config/config.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import Config

if config_env() == :prod do
config :logger, level: :warning
end
22 changes: 22 additions & 0 deletions lib/boombox.ex
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,26 @@ defmodule Boombox do
{:DOWN, _monitor, :process, ^supervisor, _reason} -> :ok
end
end

@spec run_cli([String.t()]) :: :ok
def run_cli(args \\ System.argv()) do
args =
Enum.map(args, fn
"-" <> value -> String.to_atom(value)
value -> value
end)

run(input: parse_cli_io(:i, args), output: parse_cli_io(:o, args))
end

defp parse_cli_io(type, args) do
args
|> Enum.drop_while(&(&1 != type))
|> Enum.drop(1)
|> Enum.take_while(&(&1 not in [:i, :o]))
|> case do
[value] -> value
[_h | _t] = values -> List.to_tuple(values)
end
end
end
12 changes: 12 additions & 0 deletions lib/boombox/utils/burrito_app.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
defmodule Boombox.Utils.BurritoApp do
@moduledoc false

use Application

@dialyzer {:no_return, {:start, 2}}
@impl true
def start(_type, _args) do
Boombox.run_cli(Burrito.Util.Args.argv())
System.halt()
end
end
55 changes: 54 additions & 1 deletion mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ defmodule Boombox.Mixfile do
start_permanent: Mix.env() == :prod,
deps: deps(),
dialyzer: dialyzer(),
releases: releases(),

# hex
description: "Boombox",
Expand All @@ -27,10 +28,18 @@ defmodule Boombox.Mixfile do

def application do
[
extra_applications: []
extra_applications: [],
mod:
if burrito?() do
{Boombox.Utils.BurritoApp, []}
else
[]
end
]
end

defp burrito?, do: System.get_env("BOOMBOX_BURRITO") != nil

defp elixirc_paths(:test), do: ["lib", "test/support"]
defp elixirc_paths(_env), do: ["lib"]

Expand All @@ -48,6 +57,7 @@ defmodule Boombox.Mixfile do
{:membrane_rtmp_plugin, github: "membraneframework/membrane_rtmp_plugin"},
{:membrane_ffmpeg_swresample_plugin, "~> 0.20.0"},
{:membrane_hackney_plugin, "~> 0.11.0"},
{:burrito, "~> 1.0", runtime: burrito?()},
{:ex_doc, ">= 0.0.0", only: :dev, runtime: false},
{:dialyxir, ">= 0.0.0", only: :dev, runtime: false},
{:credo, ">= 0.0.0", only: :dev, runtime: false}
Expand Down Expand Up @@ -87,4 +97,47 @@ defmodule Boombox.Mixfile do
nest_modules_by_prefix: [Boombox]
]
end

defp releases() do
if burrito?() do
burrito_releases()
else
[]
end
end

defp burrito_releases() do
current_os =
case :os.type() do
{:win32, _} -> :windows
{:unix, :darwin} -> :darwin
{:unix, :linux} -> :linux
end

arch_string =
:erlang.system_info(:system_architecture)
|> to_string()
|> String.downcase()
|> String.split("-")
|> List.first()

current_cpu =
case arch_string do
"x86_64" -> :x86_64
"arm64" -> :aarch64
"aarch64" -> :aarch64
_ -> :unknown
end

[
boombox: [
steps: [:assemble, &Burrito.wrap/1],
burrito: [
targets: [
current: [os: current_os, cpu: current_cpu]
]
]
]
]
end
end
4 changes: 3 additions & 1 deletion mix.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"bunch_native": {:hex, :bunch_native, "0.5.0", "8ac1536789a597599c10b652e0b526d8833348c19e4739a0759a2bedfd924e63", [:mix], [{:bundlex, "~> 1.0", [hex: :bundlex, repo: "hexpm", optional: false]}], "hexpm", "24190c760e32b23b36edeb2dc4852515c7c5b3b8675b1a864e0715bdd1c8f80d"},
"bundlex": {:hex, :bundlex, "1.5.3", "35d01e5bc0679510dd9a327936ffb518f63f47175c26a35e708cc29eaec0890b", [:mix], [{:bunch, "~> 1.0", [hex: :bunch, repo: "hexpm", optional: false]}, {:elixir_uuid, "~> 1.2", [hex: :elixir_uuid, repo: "hexpm", optional: false]}, {:qex, "~> 0.5", [hex: :qex, repo: "hexpm", optional: false]}, {:req, ">= 0.4.0", [hex: :req, repo: "hexpm", optional: false]}, {:zarex, "~> 1.0", [hex: :zarex, repo: "hexpm", optional: false]}], "hexpm", "debd0eac151b404f6216fc60222761dff049bf26f7d24d066c365317650cd118"},
"bunt": {:hex, :bunt, "1.0.0", "081c2c665f086849e6d57900292b3a161727ab40431219529f13c4ddcf3e7a44", [:mix], [], "hexpm", "dc5f86aa08a5f6fa6b8096f0735c4e76d54ae5c9fa2c143e5a1fc7c1cd9bb6b5"},
"burrito": {:hex, :burrito, "1.1.0", "4f26919234e144be9c3f5eb3fbd01e63395816376cf742b3570433167e46ede4", [:mix], [{:jason, "~> 1.2", [hex: :jason, repo: "hexpm", optional: false]}, {:req, "0.4.0", [hex: :req, repo: "hexpm", optional: false]}, {:typed_struct, "~> 0.2.0 or ~> 0.3.0", [hex: :typed_struct, repo: "hexpm", optional: false]}], "hexpm", "decda65f57271d38c84a34e262b40636414f9f58b2b22f243e782938bfc2a414"},
"castore": {:hex, :castore, "1.0.8", "dedcf20ea746694647f883590b82d9e96014057aff1d44d03ec90f36a5c0dc6e", [:mix], [], "hexpm", "0b2b66d2ee742cb1d9cb8c8be3b43c3a70ee8651f37b75a8b982e036752983f1"},
"certifi": {:hex, :certifi, "2.12.0", "2d1cca2ec95f59643862af91f001478c9863c2ac9cb6e2f89780bfd8de987329", [:rebar3], [], "hexpm", "ee68d85df22e554040cdb4be100f33873ac6051387baf6a8f6ce82272340ff1c"},
"coerce": {:hex, :coerce, "1.0.1", "211c27386315dc2894ac11bc1f413a0e38505d808153367bd5c6e75a4003d096", [:mix], [], "hexpm", "b44a691700f7a1a15b4b7e2ff1fa30bebd669929ac8aa43cffe9e2f8bf051cf1"},
Expand Down Expand Up @@ -82,13 +83,14 @@
"plug_crypto": {:hex, :plug_crypto, "2.1.0", "f44309c2b06d249c27c8d3f65cfe08158ade08418cf540fd4f72d4d6863abb7b", [:mix], [], "hexpm", "131216a4b030b8f8ce0f26038bc4421ae60e4bb95c5cf5395e1421437824c4fa"},
"qex": {:hex, :qex, "0.5.1", "0d82c0f008551d24fffb99d97f8299afcb8ea9cf99582b770bd004ed5af63fd6", [:mix], [], "hexpm", "935a39fdaf2445834b95951456559e9dc2063d0a055742c558a99987b38d6bab"},
"ratio": {:hex, :ratio, "4.0.1", "3044166f2fc6890aa53d3aef0c336f84b2bebb889dc57d5f95cc540daa1912f8", [:mix], [{:decimal, "~> 1.6 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: true]}, {:numbers, "~> 5.2.0", [hex: :numbers, repo: "hexpm", optional: false]}], "hexpm", "c60cbb3ccdff9ffa56e7d6d1654b5c70d9f90f4d753ab3a43a6bf40855b881ce"},
"req": {:hex, :req, "0.5.6", "8fe1eead4a085510fe3d51ad854ca8f20a622aae46e97b302f499dfb84f726ac", [:mix], [{:brotli, "~> 0.3.1", [hex: :brotli, repo: "hexpm", optional: true]}, {:ezstd, "~> 1.0", [hex: :ezstd, repo: "hexpm", optional: true]}, {:finch, "~> 0.17", [hex: :finch, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}, {:mime, "~> 2.0.6 or ~> 2.1", [hex: :mime, repo: "hexpm", optional: false]}, {:nimble_csv, "~> 1.0", [hex: :nimble_csv, repo: "hexpm", optional: true]}, {:plug, "~> 1.0", [hex: :plug, repo: "hexpm", optional: true]}], "hexpm", "cfaa8e720945d46654853de39d368f40362c2641c4b2153c886418914b372185"},
"req": {:hex, :req, "0.4.0", "1c759054dd64ef1b1a0e475c2d2543250d18f08395d3174c371b7746984579ce", [:mix], [{:brotli, "~> 0.3.1", [hex: :brotli, repo: "hexpm", optional: true]}, {:ezstd, "~> 1.0", [hex: :ezstd, repo: "hexpm", optional: true]}, {:finch, "~> 0.9", [hex: :finch, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}, {:mime, "~> 1.6 or ~> 2.0", [hex: :mime, repo: "hexpm", optional: false]}, {:nimble_csv, "~> 1.0", [hex: :nimble_csv, repo: "hexpm", optional: true]}, {:plug, "~> 1.0", [hex: :plug, repo: "hexpm", optional: true]}], "hexpm", "f53eadc32ebefd3e5d50390356ec3a59ed2b8513f7da8c6c3f2e14040e9fe989"},
"shmex": {:hex, :shmex, "0.5.1", "81dd209093416bf6608e66882cb7e676089307448a1afd4fc906c1f7e5b94cf4", [:mix], [{:bunch_native, "~> 0.5.0", [hex: :bunch_native, repo: "hexpm", optional: false]}, {:bundlex, "~> 1.0", [hex: :bundlex, repo: "hexpm", optional: false]}], "hexpm", "c29f8286891252f64c4e1dac40b217d960f7d58def597c4e606ff8fbe71ceb80"},
"ssl_verify_fun": {:hex, :ssl_verify_fun, "1.1.7", "354c321cf377240c7b8716899e182ce4890c5938111a1296add3ec74cf1715df", [:make, :mix, :rebar3], [], "hexpm", "fe4c190e8f37401d30167c8c405eda19469f34577987c76dde613e838bbc67f8"},
"telemetry": {:hex, :telemetry, "1.2.1", "68fdfe8d8f05a8428483a97d7aab2f268aaff24b49e0f599faa091f1d4e7f61c", [:rebar3], [], "hexpm", "dad9ce9d8effc621708f99eac538ef1cbe05d6a874dd741de2e689c47feafed5"},
"telemetry_metrics": {:hex, :telemetry_metrics, "0.6.2", "2caabe9344ec17eafe5403304771c3539f3b6e2f7fb6a6f602558c825d0d0bfb", [:mix], [{:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "9b43db0dc33863930b9ef9d27137e78974756f5f198cae18409970ed6fa5b561"},
"thousand_island": {:hex, :thousand_island, "1.3.5", "6022b6338f1635b3d32406ff98d68b843ba73b3aa95cfc27154223244f3a6ca5", [:mix], [{:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "2be6954916fdfe4756af3239fb6b6d75d0b8063b5df03ba76fd8a4c87849e180"},
"unicode_util_compat": {:hex, :unicode_util_compat, "0.7.0", "bc84380c9ab48177092f43ac89e4dfa2c6d62b40b8bd132b1059ecc7232f9a78", [:rebar3], [], "hexpm", "25eee6d67df61960cf6a794239566599b09e17e668d3700247bc498638152521"},
"typed_struct": {:hex, :typed_struct, "0.3.0", "939789e3c1dca39d7170c87f729127469d1315dcf99fee8e152bb774b17e7ff7", [:mix], [], "hexpm", "c50bd5c3a61fe4e198a8504f939be3d3c85903b382bde4865579bc23111d1b6d"},
"unifex": {:hex, :unifex, "1.2.0", "90d1ec5e6d788350e07e474f7bd8b0ee866d6606beb9ca4e20dbb26328712a84", [:mix], [{:bunch, "~> 1.0", [hex: :bunch, repo: "hexpm", optional: false]}, {:bundlex, "~> 1.4", [hex: :bundlex, repo: "hexpm", optional: false]}, {:shmex, "~> 0.5.0", [hex: :shmex, repo: "hexpm", optional: false]}], "hexpm", "7a8395aabc3ba6cff04bbe5b995de7f899a38eb57f189e49927d6b8b6ccb6883"},
"websock": {:hex, :websock, "0.5.3", "2f69a6ebe810328555b6fe5c831a851f485e303a7c8ce6c5f675abeb20ebdadc", [:mix], [], "hexpm", "6105453d7fac22c712ad66fab1d45abdf049868f253cf719b625151460b8b453"},
"websock_adapter": {:hex, :websock_adapter, "0.5.6", "0437fe56e093fd4ac422de33bf8fc89f7bc1416a3f2d732d8b2c8fd54792fe60", [:mix], [{:bandit, ">= 0.6.0", [hex: :bandit, repo: "hexpm", optional: true]}, {:plug, "~> 1.14", [hex: :plug, repo: "hexpm", optional: false]}, {:plug_cowboy, "~> 2.6", [hex: :plug_cowboy, repo: "hexpm", optional: true]}, {:websock, "~> 0.5", [hex: :websock, repo: "hexpm", optional: false]}], "hexpm", "e04378d26b0af627817ae84c92083b7e97aca3121196679b73c73b99d0d133ea"},
Expand Down

0 comments on commit ab533fe

Please sign in to comment.