mix.exs 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. defmodule Toy.MixProject do
  2. use Mix.Project
  3. def project do
  4. [
  5. app: :toy,
  6. version: from_file(),
  7. elixir: "~> 1.7",
  8. elixirc_paths: elixirc_paths(Mix.env()),
  9. compilers: [:phoenix, :gettext] ++ Mix.compilers(),
  10. start_permanent: Mix.env() == :prod,
  11. aliases: aliases(),
  12. deps: deps(),
  13. releases: [toy: [steps: [:assemble, &export_sha1/1, &export_docker_image_tag/1, :tar]]]
  14. ]
  15. end
  16. # Configuration for the OTP application.
  17. #
  18. # Type `mix help compile.app` for more information.
  19. def application do
  20. [
  21. mod: {Toy.Application, []},
  22. extra_applications: [:logger, :runtime_tools]
  23. ]
  24. end
  25. # Specifies which paths to compile per environment.
  26. defp elixirc_paths(:test), do: ["lib", "config", "test/support"]
  27. defp elixirc_paths(_), do: ["lib", "config"]
  28. # Specifies your project dependencies.
  29. #
  30. # Type `mix help deps` for examples and options.
  31. defp deps do
  32. [
  33. {:phoenix, "~> 1.5.9"},
  34. {:phoenix_ecto, "~> 4.1"},
  35. {:ecto_sql, "~> 3.4"},
  36. {:postgrex, ">= 0.0.0"},
  37. {:phoenix_live_view, "~> 0.15.1"},
  38. {:floki, ">= 0.30.0", only: :test},
  39. {:phoenix_html, "~> 2.11"},
  40. {:phoenix_live_reload, "~> 1.2", only: :dev},
  41. {:phoenix_live_dashboard, "~> 0.4"},
  42. {:telemetry_metrics, "~> 0.4"},
  43. {:telemetry_poller, "~> 0.4"},
  44. {:gettext, "~> 0.11"},
  45. {:jason, "~> 1.0"},
  46. {:plug_cowboy, "~> 2.0"}
  47. ]
  48. end
  49. # Aliases are shortcuts or tasks specific to the current project.
  50. # For example, to install project dependencies and perform other setup tasks, run:
  51. #
  52. # $ mix setup
  53. #
  54. # See the documentation for `Mix` for more info on aliases.
  55. defp aliases do
  56. [
  57. setup: ["deps.get", "ecto.setup", "cmd npm install --prefix assets"],
  58. "ecto.setup": ["ecto.create", "ecto.migrate", "run priv/repo/seeds.exs"],
  59. "ecto.reset": ["ecto.drop", "ecto.setup"],
  60. test: ["ecto.create --quiet", "ecto.migrate --quiet", "test"],
  61. version: ["run -e \"Mix.Project.config[:version] |> IO.puts\""]
  62. ]
  63. end
  64. defp from_file(file \\ "VERSION") do
  65. with {:ok, described} <- File.read(file),
  66. {:ok, version} <- described |> String.trim() |> to_semver_string() do
  67. version
  68. end
  69. end
  70. defp to_semver_string(described) when is_binary(described) do
  71. with {:ok, _} <- described |> Version.parse(), do: {:ok, described}
  72. end
  73. defp export_sha1(rel) when is_struct(rel, Mix.Release) do
  74. with {sha1, 0} <- System.cmd("git", ["rev-parse", "HEAD"]),
  75. :ok <- rel |> write_in_rel_path("git-sha1", sha1),
  76. do: rel
  77. end
  78. defp export_docker_image_tag(rel) when is_struct(rel, Mix.Release) do
  79. with image_tag when not is_nil(image_tag) <- System.get_env("DOCKER_IMAGE_TAG"),
  80. :ok <- rel |> write_in_rel_path("docker-image-tag", "#{image_tag}\n") do
  81. rel
  82. else
  83. nil -> rel
  84. end
  85. end
  86. defp write_in_rel_path(%{version_path: path}, file_path, content) do
  87. path |> Path.join(file_path) |> File.write(content)
  88. end
  89. end