mix.exs 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. defmodule Vaccins.MixProject do
  2. use Mix.Project
  3. def project do
  4. [
  5. app: :vaccins,
  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: [vaccins: [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: {Vaccins.Application, []},
  22. extra_applications: [:logger, :runtime_tools]
  23. ]
  24. end
  25. # Specifies which paths to compile per environment.
  26. defp elixirc_paths(:test), do: ["config", "lib", "test/support"]
  27. defp elixirc_paths(_), do: ["config", "lib"]
  28. # Specifies your project dependencies.
  29. #
  30. # Type `mix help deps` for examples and options.
  31. defp deps do
  32. [
  33. {:phoenix, "> 1.5.3"},
  34. {:phoenix_live_view, "> 0.13.0"},
  35. {:phoenix_html, "> 2.11.0"},
  36. {:phoenix_live_reload, "> 1.2.0", only: :dev},
  37. {:phoenix_live_dashboard, "> 0.2.0"},
  38. {:telemetry_metrics, "> 0.4.0"},
  39. {:telemetry_poller, "> 0.4.0"},
  40. {:gettext, "> 0.11.0"},
  41. {:jason, "> 1.0.0"},
  42. {:plug_cowboy, "> 2.0.0"},
  43. {:floki, "~> 0.30.0"},
  44. {:finch, "~> 0.6"},
  45. {:ex2ms, "~> 1.0"},
  46. {:ecto, "~> 3.6"},
  47. {:phoenix_ecto, "~> 4.1"},
  48. {:tzdata, "~> 1.1"}
  49. ]
  50. end
  51. # Aliases are shortcuts or tasks specific to the current project.
  52. # For example, to install project dependencies and perform other setup tasks, run:
  53. #
  54. # $ mix setup
  55. #
  56. # See the documentation for `Mix` for more info on aliases.
  57. defp aliases do
  58. [
  59. setup: ["deps.get", "cmd npm install --prefix assets"],
  60. deploy: [
  61. "cmd npm --prefix ./assets ci --progress=false --no-audit --loglevel=error",
  62. "cmd npm run --prefix ./assets deploy",
  63. "phx.digest",
  64. "release"
  65. ]
  66. ]
  67. end
  68. defp from_file(file \\ "VERSION") do
  69. with {:ok, described} <- File.read(file),
  70. {:ok, version} <- described |> String.trim() |> to_semver_string() do
  71. version
  72. end
  73. end
  74. defp to_semver_string(described) when is_binary(described) do
  75. with {:ok, _} <- described |> Version.parse(), do: {:ok, described}
  76. end
  77. defp export_sha1(rel) when is_struct(rel, Mix.Release) do
  78. with {sha1, 0} <- System.cmd("git", ["rev-parse", "HEAD"]),
  79. :ok <- rel |> write_in_rel_path("git-sha1", sha1),
  80. do: rel
  81. end
  82. defp export_docker_image_tag(rel) when is_struct(rel, Mix.Release) do
  83. with image_tag when not is_nil(image_tag) <- System.get_env("DOCKER_IMAGE_TAG"),
  84. :ok <- rel |> write_in_rel_path("docker-image-tag", image_tag) do
  85. rel
  86. else
  87. nil -> rel
  88. end
  89. end
  90. defp write_in_rel_path(%{version_path: path}, file_path, content) do
  91. path |> Path.join(file_path) |> File.write(content)
  92. end
  93. end