diff --git a/.github/workflows/elixir.yml b/.github/workflows/elixir.yml index db68f02..7d00a8f 100644 --- a/.github/workflows/elixir.yml +++ b/.github/workflows/elixir.yml @@ -16,15 +16,6 @@ jobs: strategy: matrix: include: - - elixir: "1.9" - otp_release: 21 - - - elixir: "1.9" - otp_release: 22 - - - elixir: "1.10" - otp_release: 23 - - elixir: "1.13" otp_release: 24 @@ -33,7 +24,7 @@ jobs: steps: - uses: actions/checkout@v3 - name: Set up Elixir - uses: erlef/setup-beam@988e02bfe678367a02564f65ca2e37726dc0268f + uses: erlef/setup-beam@v1 with: elixir-version: ${{ matrix.elixir }} otp-version: ${{ matrix.otp_release }} diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 77c8eaf..e199a29 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -6,30 +6,21 @@ on: - "v*" jobs: - build: - name: Build + build-escript: + name: Build escripts runs-on: ubuntu-latest strategy: matrix: include: - - elixir: "1.9" - otp_release: 21 - - - elixir: "1.9" - otp_release: 22 - - - elixir: "1.10" - otp_release: 23 - - elixir: "1.13" - otp_release: 24 + otp_release: "24" - - elixir: "1.13" - otp_release: 25 + - elixir: "1.14" + otp_release: "25" steps: - uses: actions/checkout@v3 - name: Set up Elixir - uses: erlef/setup-beam@988e02bfe678367a02564f65ca2e37726dc0268f + uses: erlef/setup-beam@v1 with: elixir-version: ${{ matrix.elixir }} otp-version: ${{ matrix.otp_release }} @@ -46,11 +37,35 @@ jobs: name: otp-${{ matrix.otp_release }} path: smppsend-${{ matrix.otp_release }} + build-burrito: + name: Build Burrito executables + runs-on: ubuntu-latest + env: + MIX_ENV: prod + steps: + - uses: actions/checkout@v2 + - name: Set up Elixir + uses: erlef/setup-beam@v1 + with: + elixir-version: "1.14" + otp-version: "25" + + - uses: goto-bus-stop/setup-zig@v2 + with: + version: 0.10.1 + - name: Build Burrito + run: ./burrito/build.sh + - uses: actions/upload-artifact@v3 + with: + name: burrito-images + path: burrito_out/* + tagged-release: name: "Tagged Release" runs-on: "ubuntu-latest" needs: - - build + - build-escript + - build-burrito steps: - name: Download artifacts uses: actions/download-artifact@v3 @@ -61,3 +76,4 @@ jobs: title: Precompiled `smppsend` for the latest OTP versions files: | otp-*/smppsend-* + burrito-images/* diff --git a/.gitignore b/.gitignore index 9865034..51cc00d 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,5 @@ erl_crash.dump /smppsend /bin /bin.tar.gz +burrito_out/ +/burrito/otp/versions diff --git a/.tool-versions b/.tool-versions new file mode 100644 index 0000000..68e7120 --- /dev/null +++ b/.tool-versions @@ -0,0 +1,2 @@ +elixir 1.14.3-otp-25 +erlang 25.2.3 diff --git a/burrito/build.sh b/burrito/build.sh new file mode 100755 index 0000000..fe744b8 --- /dev/null +++ b/burrito/build.sh @@ -0,0 +1,17 @@ +#!/bin/sh + +set -xe + +mix deps.get +mix compile + +otp_version=$(mix burrito.otp.version) +ssl_version=$(mix burrito.ssl.version) + +OTP_VERSION="${otp_version}" ARCH=x86_64 OPENSSL_VERSION="${ssl_version}" ./burrito/download/macos.sh +OTP_VERSION="${otp_version}" ARCH=aarch64 OPENSSL_VERSION="${ssl_version}" ./burrito/download/macos.sh + +OTP_VERSION="${otp_version}" ARCH=x86_64 LIBC=gnu OPENSSL_VERSION="${ssl_version}" ./burrito/download/linux.sh +OTP_VERSION="${otp_version}" ARCH=aarch64 LIBC=gnu OPENSSL_VERSION="${ssl_version}" ./burrito/download/linux.sh + +mix release smppsend --overwrite diff --git a/burrito/download/linux.sh b/burrito/download/linux.sh new file mode 100755 index 0000000..336e2ce --- /dev/null +++ b/burrito/download/linux.sh @@ -0,0 +1,26 @@ +#!/bin/sh + +set -ex + +name="otp_${OTP_VERSION}_linux_${LIBC}_${ARCH}_ssl_${OPENSSL_VERSION}" +targz_name="${name}.tar.gz" +otp_dir="./burrito/otp/versions" + +url="https://burrito-otp.b-cdn.net/OTP-${OTP_VERSION}/linux/${ARCH}/${LIBC}/${targz_name}?please-respect-my-bandwidth-costs=thank-you" + +dst_name="otp-${OTP_VERSION}-linux-${ARCH}" +dst_targz_name="${dst_name}.tar.gz" + +mkdir -p "$otp_dir" + +wget --no-verbose "$url" -O "$otp_dir/${targz_name}" + +tar xf "$otp_dir/${targz_name}" -C "$otp_dir/" +rm -rf "$otp_dir/${targz_name}" + +mv "$otp_dir/${name}" "$otp_dir/${dst_name}" +tar czf "$otp_dir/${dst_targz_name}" -C "$otp_dir/" "$dst_name" + +rm -rf "$otp_dir/${dst_name}" + + diff --git a/burrito/download/macos.sh b/burrito/download/macos.sh new file mode 100755 index 0000000..f6baacc --- /dev/null +++ b/burrito/download/macos.sh @@ -0,0 +1,26 @@ +#!/bin/sh + +set -ex + +name="otp_${OTP_VERSION}_darwin_${ARCH}_ssl_${OPENSSL_VERSION}" +targz_name="${name}.tar.gz" +otp_dir="./burrito/otp/versions" + +url="https://burrito-otp.b-cdn.net/OTP-${OTP_VERSION}/darwin/${ARCH}/${targz_name}?please-respect-my-bandwidth-costs=thank-you" + +dst_name="otp-${OTP_VERSION}-darwin-${ARCH}" +dst_targz_name="${dst_name}.tar.gz" + +mkdir -p "$otp_dir" + +wget --no-verbose "$url" -O "$otp_dir/${targz_name}" + +tar xf "$otp_dir/${targz_name}" -C "$otp_dir/" +rm -rf "$otp_dir/${targz_name}" + +mv "$otp_dir/${name}" "$otp_dir/${dst_name}" +tar czf "$otp_dir/${dst_targz_name}" -C "$otp_dir/" "$dst_name" + +rm -rf "$otp_dir/${dst_name}" + + diff --git a/config/prod.exs b/config/prod.exs new file mode 100644 index 0000000..06ed978 --- /dev/null +++ b/config/prod.exs @@ -0,0 +1,6 @@ +import Config + +config :logger, level: :info + +config :smppsend, + main_in_app_start: true diff --git a/lib/mix/tasks/burrito_otp_version.ex b/lib/mix/tasks/burrito_otp_version.ex new file mode 100644 index 0000000..8e93813 --- /dev/null +++ b/lib/mix/tasks/burrito_otp_version.ex @@ -0,0 +1,10 @@ +defmodule Mix.Tasks.Burrito.Otp.Version do + @moduledoc "Export OTP version for Burrito builds: `mix help burrito_otp_version`" + @shortdoc "Print OTP version for burrito builds" + use Mix.Task + + @impl Mix.Task + def run(_) do + IO.puts(Mix.Project.config()[:burrito_otp_version]) + end +end diff --git a/lib/mix/tasks/burrito_ssl_version.ex b/lib/mix/tasks/burrito_ssl_version.ex new file mode 100644 index 0000000..2b5c335 --- /dev/null +++ b/lib/mix/tasks/burrito_ssl_version.ex @@ -0,0 +1,11 @@ +defmodule Mix.Tasks.Burrito.Ssl.Version do + @moduledoc "Export OpenSSL version for Burrito builds: `mix help burrito_otp_version`" + @shortdoc "Print OpenSSL version for burrito builds" + use Mix.Task + + @impl Mix.Task + def run(_) do + IO.puts(Mix.Project.config()[:burrito_ssl_version]) + end +end + diff --git a/lib/smppsend.ex b/lib/smppsend.ex index dca8870..6110dec 100644 --- a/lib/smppsend.ex +++ b/lib/smppsend.ex @@ -102,6 +102,21 @@ defmodule SMPPSend do System.halt(code) end + @main_in_app_start Application.compile_env(:smppsend, :main_in_app_start, false) + @env Mix.env() + + ## For Burrito + def start(_, _) do + IO.puts("@main_in_app_start: #{@main_in_app_start}, env: #{@env}") + case @main_in_app_start do + true -> + Burrito.Util.Args.get_arguments() + |> main() + false -> + Supervisor.start_link([], strategy: :one_for_one) + end + end + defp parse(args) do {parsed, remaining, invalid} = OptionParser.parse(args, switches: @switches, allow_nonexistent_atoms: true) diff --git a/mix.exs b/mix.exs index 9b5e7fb..a242cca 100644 --- a/mix.exs +++ b/mix.exs @@ -1,6 +1,9 @@ defmodule Smppsend.Mixfile do use Mix.Project + @burrito_otp_version "25.2.3" + @burrito_ssl_version "1.1.1s" + def project do [ app: :smppsend, @@ -11,26 +14,64 @@ defmodule Smppsend.Mixfile do elixirc_paths: elixirc_paths(Mix.env()), deps: deps(), escript: escript(), - test_coverage: [tool: Coverex.Task] + test_coverage: [tool: Coverex.Task], + releases: releases(), + burrito_otp_version: @burrito_otp_version, + burrito_ssl_version: @burrito_ssl_version ] end def application do [ - extra_applications: [:logger, :runtime_tools, :xmerl] + extra_applications: [:logger, :runtime_tools, :xmerl], + mod: {SMPPSend, []} ] end defp elixirc_paths(:test), do: ["lib", "test/support"] defp elixirc_paths(_), do: ["lib"] + def releases do + [ + smppsend: [ + steps: [:assemble, &Burrito.wrap/1], + burrito: [ + targets: [ + # linux_aarch64: [ + # os: :linux, + # cpu: :aarch64, + # custom_erts: "burrito/otp/versions/otp-#{@burrito_otp_version}-linux-aarch64.tar.gz" + # ], + linux_x86_64: [ + os: :linux, + cpu: :x86_64, + custom_erts: "burrito/otp/versions/otp-#{@burrito_otp_version}-linux-x86_64.tar.gz" + ], + # darwin_aarch64: [ + # os: :darwin, + # cpu: :aarch64, + # custom_erts: "burrito/otp/versions/otp-#{@burrito_otp_version}-darwin-aarch64.tar.gz" + # ], + # darwin_x86_64: [ + # os: :darwin, + # cpu: :x86_64, + # custom_erts: "burrito/otp/versions/otp-#{@burrito_otp_version}-linux-x86_64.tar.gz" + # ], + ] + ] + ] + ] + end + defp deps do [ {:smppex, "~> 2.0"}, {:dye, "~> 0.4.0"}, + {:codepagex, "~> 0.1.6"}, + {:burrito, github: "burrito-elixir/burrito"}, + {:coverex, "~> 1.4.1", only: :test}, - {:mox, "~> 1.0", only: :test}, - {:codepagex, "~> 0.1.6"} + {:mox, "~> 1.0", only: :test} ] end diff --git a/mix.lock b/mix.lock index 1e44c62..cb908ba 100644 --- a/mix.lock +++ b/mix.lock @@ -1,17 +1,29 @@ %{ + "burrito": {:git, "https://github.com/burrito-elixir/burrito.git", "425613d6f0760b283df004e30e50cbec66d10800", []}, + "castore": {:hex, :castore, "0.1.22", "4127549e411bedd012ca3a308dede574f43819fe9394254ca55ab4895abfa1a2", [:mix], [], "hexpm", "c17576df47eb5aa1ee40cc4134316a99f5cad3e215d5c77b8dd3cfef12a22cac"}, "certifi": {:hex, :certifi, "2.9.0", "6f2a475689dd47f19fb74334859d460a2dc4e3252a3324bd2111b8f0429e7e21", [:rebar3], [], "hexpm", "266da46bdb06d6c6d35fde799bcb28d36d985d424ad7c08b5bb48f5b5cdd4641"}, "codepagex": {:hex, :codepagex, "0.1.6", "49110d09a25ee336a983281a48ef883da4c6190481e0b063afe2db481af6117e", [:mix], [], "hexpm", "1521461097dde281edf084062f525a4edc6a5e49f4fd1f5ec41c9c4955d5bd59"}, "coverex": {:hex, :coverex, "1.4.15", "60fadf825a6c0439b79d1f98cdb54b6733cdd5cb1b35d15d56026c44ed15a5a8", [:mix], [{:hackney, "~> 1.5", [hex: :hackney, repo: "hexpm", optional: false]}, {:poison, "~> 1.5 or ~> 2.0 or ~> 3.0", [hex: :poison, repo: "hexpm", optional: false]}], "hexpm", "bfde7ad7ecb83e0199902d087caf570057047aa004cfd2eafef3b42a5428103c"}, "dye": {:hex, :dye, "0.4.1", "e8d4b548fd17b441ebaaa53c823c29026bd17704bc9057304f15befb7e180df3", [:mix], [], "hexpm", "d8bccef998e1b5800c7a433ea027df83103ae98c0be5a19d03216b320986bf74"}, + "finch": {:hex, :finch, "0.14.0", "619bfdee18fc135190bf590356c4bf5d5f71f916adb12aec94caa3fa9267a4bc", [:mix], [{:castore, "~> 0.1", [hex: :castore, repo: "hexpm", optional: false]}, {:mime, "~> 1.0 or ~> 2.0", [hex: :mime, repo: "hexpm", optional: false]}, {:mint, "~> 1.3", [hex: :mint, repo: "hexpm", optional: false]}, {:nimble_options, "~> 0.4", [hex: :nimble_options, repo: "hexpm", optional: false]}, {:nimble_pool, "~> 0.2.6", [hex: :nimble_pool, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "5459acaf18c4fdb47a8c22fb3baff5d8173106217c8e56c5ba0b93e66501a8dd"}, "hackney": {:hex, :hackney, "1.18.1", "f48bf88f521f2a229fc7bae88cf4f85adc9cd9bcf23b5dc8eb6a1788c662c4f6", [:rebar3], [{:certifi, "~>2.9.0", [hex: :certifi, repo: "hexpm", optional: false]}, {:idna, "~>6.1.0", [hex: :idna, repo: "hexpm", optional: false]}, {:metrics, "~>1.0.0", [hex: :metrics, repo: "hexpm", optional: false]}, {:mimerl, "~>1.1", [hex: :mimerl, repo: "hexpm", optional: false]}, {:parse_trans, "3.3.1", [hex: :parse_trans, repo: "hexpm", optional: false]}, {:ssl_verify_fun, "~>1.1.0", [hex: :ssl_verify_fun, repo: "hexpm", optional: false]}, {:unicode_util_compat, "~>0.7.0", [hex: :unicode_util_compat, repo: "hexpm", optional: false]}], "hexpm", "a4ecdaff44297e9b5894ae499e9a070ea1888c84afdd1fd9b7b2bc384950128e"}, + "hpax": {:hex, :hpax, "0.1.2", "09a75600d9d8bbd064cdd741f21fc06fc1f4cf3d0fcc335e5aa19be1a7235c84", [:mix], [], "hexpm", "2c87843d5a23f5f16748ebe77969880e29809580efdaccd615cd3bed628a8c13"}, "idna": {:hex, :idna, "6.1.1", "8a63070e9f7d0c62eb9d9fcb360a7de382448200fbbd1b106cc96d3d8099df8d", [:rebar3], [{:unicode_util_compat, "~>0.7.0", [hex: :unicode_util_compat, repo: "hexpm", optional: false]}], "hexpm", "92376eb7894412ed19ac475e4a86f7b413c1b9fbb5bd16dccd57934157944cea"}, + "jason": {:hex, :jason, "1.4.0", "e855647bc964a44e2f67df589ccf49105ae039d4179db7f6271dfd3843dc27e6", [:mix], [{:decimal, "~> 1.0 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm", "79a3791085b2a0f743ca04cec0f7be26443738779d09302e01318f97bdb82121"}, "metrics": {:hex, :metrics, "1.0.1", "25f094dea2cda98213cecc3aeff09e940299d950904393b2a29d191c346a8486", [:rebar3], [], "hexpm", "69b09adddc4f74a40716ae54d140f93beb0fb8978d8636eaded0c31b6f099f16"}, + "mime": {:hex, :mime, "2.0.3", "3676436d3d1f7b81b5a2d2bd8405f412c677558c81b1c92be58c00562bb59095", [:mix], [], "hexpm", "27a30bf0db44d25eecba73755acf4068cbfe26a4372f9eb3e4ea3a45956bff6b"}, "mimerl": {:hex, :mimerl, "1.2.0", "67e2d3f571088d5cfd3e550c383094b47159f3eee8ffa08e64106cdf5e981be3", [:rebar3], [], "hexpm", "f278585650aa581986264638ebf698f8bb19df297f66ad91b18910dfc6e19323"}, + "mint": {:hex, :mint, "1.5.1", "8db5239e56738552d85af398798c80648db0e90f343c8469f6c6d8898944fb6f", [:mix], [{:castore, "~> 0.1.0 or ~> 1.0", [hex: :castore, repo: "hexpm", optional: true]}, {:hpax, "~> 0.1.1", [hex: :hpax, repo: "hexpm", optional: false]}], "hexpm", "4a63e1e76a7c3956abd2c72f370a0d0aecddc3976dea5c27eccbecfa5e7d5b1e"}, "mox": {:hex, :mox, "1.0.2", "dc2057289ac478b35760ba74165b4b3f402f68803dd5aecd3bfd19c183815d64", [:mix], [], "hexpm", "f9864921b3aaf763c8741b5b8e6f908f44566f1e427b2630e89e9a73b981fef2"}, + "nimble_options": {:hex, :nimble_options, "0.5.2", "42703307b924880f8c08d97719da7472673391905f528259915782bb346e0a1b", [:mix], [], "hexpm", "4da7f904b915fd71db549bcdc25f8d56f378ef7ae07dc1d372cbe72ba950dce0"}, + "nimble_pool": {:hex, :nimble_pool, "0.2.6", "91f2f4c357da4c4a0a548286c84a3a28004f68f05609b4534526871a22053cde", [:mix], [], "hexpm", "1c715055095d3f2705c4e236c18b618420a35490da94149ff8b580a2144f653f"}, "parse_trans": {:hex, :parse_trans, "3.3.1", "16328ab840cc09919bd10dab29e431da3af9e9e7e7e6f0089dd5a2d2820011d8", [:rebar3], [], "hexpm", "07cd9577885f56362d414e8c4c4e6bdf10d43a8767abb92d24cbe8b24c54888b"}, "poison": {:hex, :poison, "3.1.0", "d9eb636610e096f86f25d9a46f35a9facac35609a7591b3be3326e99a0484665", [:mix], [], "hexpm", "fec8660eb7733ee4117b85f55799fd3833eb769a6df71ccf8903e8dc5447cfce"}, "ranch": {:hex, :ranch, "1.8.0", "8c7a100a139fd57f17327b6413e4167ac559fbc04ca7448e9be9057311597a1d", [:make, :rebar3], [], "hexpm", "49fbcfd3682fab1f5d109351b61257676da1a2fdbe295904176d5e521a2ddfe5"}, + "req": {:hex, :req, "0.3.6", "541350d2cc359a8ad17059f2629c18be56d0c85ce0e4ddb27694b6ba482fe923", [: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", "9181047f32b05f8737f6b5917af5ee5385219158bbe4e507f4ec57791a0a78c3"}, "smppex": {:hex, :smppex, "2.4.0", "c4dc9ebaf5b80a3d3b640c74d4fbdbe5e64dff2cb9c88c90c80b776539c4fa58", [:mix], [{:poison, "~> 3.0", [hex: :poison, repo: "hexpm", optional: false]}, {:ranch, "~> 1.3", [hex: :ranch, repo: "hexpm", optional: false]}], "hexpm", "81e576d9b99186eec2bab9ff18278191ba50ee7661b9bb9d84f597746651be2c"}, "ssl_verify_fun": {:hex, :ssl_verify_fun, "1.1.6", "cf344f5692c82d2cd7554f5ec8fd961548d4fd09e7d22f5b62482e5aeaebd4b0", [:make, :mix, :rebar3], [], "hexpm", "bdb0d2471f453c88ff3908e7686f86f9be327d065cc1ec16fa4540197ea04680"}, + "telemetry": {:hex, :telemetry, "1.2.1", "68fdfe8d8f05a8428483a97d7aab2f268aaff24b49e0f599faa091f1d4e7f61c", [:rebar3], [], "hexpm", "dad9ce9d8effc621708f99eac538ef1cbe05d6a874dd741de2e689c47feafed5"}, + "typed_struct": {:hex, :typed_struct, "0.3.0", "939789e3c1dca39d7170c87f729127469d1315dcf99fee8e152bb774b17e7ff7", [:mix], [], "hexpm", "c50bd5c3a61fe4e198a8504f939be3d3c85903b382bde4865579bc23111d1b6d"}, "unicode_util_compat": {:hex, :unicode_util_compat, "0.7.0", "bc84380c9ab48177092f43ac89e4dfa2c6d62b40b8bd132b1059ecc7232f9a78", [:rebar3], [], "hexpm", "25eee6d67df61960cf6a794239566599b09e17e668d3700247bc498638152521"}, }