hashrocket / gatling

Deployment tool for Phoenix apps
496 stars 17 forks source link

Upgrade issue with `--upfrom=#{last_release}` #27

Closed sircharleswatson closed 7 years ago

sircharleswatson commented 7 years ago

I've been trying to upgrade my app recently and it kept giving me no_matching_releup errors and no matter what i did, it would always automatically use --upfrom=0.0.9 but I just figured out why it's doing that.

The culprit is this code:

  def mix_release(env) do
    last_release = List.last(env.releases)
    bash("mix", ~w[release --upgrade --upfrom=#{last_release} --warnings-as-errors --env=prod], cd: env.build_dir)
    env
  end

In particular, the List.last(env.releases) part.

env.releases is a list of strings and that means "0.0.9" ends up at the end of the list rather than newer releases like "0.0.10" or "0.0.11"

Here's the output from my env.releases:

["0.0.1", "0.0.10", "0.0.11", "0.0.12", "0.0.2", "0.0.4", "0.0.5", "0.0.6",
 "0.0.7", "0.0.8", "0.0.9"]

Since it keeps using 0.0.9 I can't actually upgrade past that unless I increment other parts of the version number, which I'm not ready to do.

sircharleswatson commented 7 years ago

Some additional info...

I believe that this issue can be fixed with the following code:

     Enum.sort(env.releases, fn (a, b) ->
       case Version.compare(a, b) do
         :gt -> false
         :lt -> true
         :eq -> true
       end
     end)

This uses Elixir's built-in Version module to check the versions against each other and sorts them from oldest to newest.

Altogether with the code for mix release, it'd be something like this:

  @spec mix_release(gatling_env) :: gatling_env
  @doc """
  Generate a release of the deploying project with [Distillery](http://github.com/bitwalker/distillery)
  """
  def mix_release(env) do
     sorted_releases = Enum.sort(env.releases, fn (a, b) ->
       case Version.compare(a, b) do
         :gt -> false
         :lt -> true
         :eq -> true
       end
     end)

    last_release = List.last(sorted_releases)
    bash("mix", ~w[release --upgrade --upfrom=#{last_release} --warnings-as-errors --env=prod], cd: env.build_dir)
    env
  end

Obviously that sort method could be split out to its own function.