bitwalker / distillery

Simplify deployments in Elixir with OTP releases!
MIT License
2.97k stars 398 forks source link

[Windows] custom command parameter passing is wonky #649

Open hlampert opened 5 years ago

hlampert commented 5 years ago

Steps to reproduce

  1. Create a custom command that accepts parameters - for example: GetTagHistory.ReleaseTasks.process, with appropriate process function and process.ps1 file.

  2. From a command prompt, call the command with parameters, for example: set "COOKIE=SOME_SECRET_COOKIE" && dl_posbypass_umbrella process --location mylocation --tagfile tagfile.txt

  3. Get parameter list in process function that looks like either an empty list (if Release-Ctl eval --mfa "GetTagHistory.ReleaseTasks.process/1" --argv -- "$args" is called), or something strange like ["mylocation", "mylocation", "--tagfile", "tagFile.txt", "--location", "mylocation", "--tagfile", "tagFile.txt", "--location", "mylocation", "--tagfile", "tagFile.txt"]' if Release-Ctl is called with Release-Ctl eval --mfa "GetTagHistory.ReleaseTasks.process/1" --argv -- $args (No quotes around the $args).

Verbose Logs

Paste the output of the release command you ran with the --verbose flag below in the summary tags (this helps keep the issue easy to navigate):

(Sorry, this doesn't work for me)

``` # Put your logs here! ```

Description of issue

use Mix.Releases.Config,

This sets the default release built by mix release

default_release: :default,
# This sets the default environment used by `mix release`
default_environment: Mix.env()

For a full list of config options for both releases

and environments, visit https://hexdocs.pm/distillery/config/distillery.html

You may define one or more environments in this file,

an environment's settings will override those of a release

when building in that environment, this combination of release

and environment configuration is called a profile

environment :dev do

If you are running Phoenix, you should make sure that

server: true is set and the code reloader is disabled,

even in dev mode.

It is recommended that you build with MIX_ENV=prod and pass

the --env flag to Distillery explicitly if you want to use

dev mode.

set dev_mode: true set include_erts: false set cookie: :"" end

environment :prod do

set include_erts: true

set include_erts: "C:/Program Files/erl10.2" set include_src: false set cookie: :":E|Z!Qf=.$S!o4c$F_h7NV{th71pn16Fu_M==}wxMd>d.1SVD&|mNNH7Wr`H}^" set vm_args: "rel/vm.args" end

You may define one or more releases in this file.

If you have not set a default release, or selected one

when running mix release, the first release in the file

will be used by default

release :dl_posbypass_umbrella do set version: "0.1.0" set applications: [ :runtime_tools, dl_posbypass_gettaghistory: :permanent, dl_posbypass_gettaghistory_consoleio: :permanent ] set commands: [ process: "rel/commands/win/process.ps1" ] set overlays: [ {:mkdir, "releases/<%= release_version %>/commands/win"}, {:copy, "rel/commands/win/process.ps1", "releases/<%= release_version %>/commands/win/process.ps1"} ] end


Here is the process.ps1 file (without quotes around $args):

Write-Host "Running process command..." Write-host "args: '$($args)'" Release-Ctl eval --mfa "GetTagHistory.ReleaseTasks.process/1" --argv -- $args


Here is the process.ps1 file (with quotes around $args):

Write-Host "Running process command..." Write-host "args: '$($args)'" Release-Ctl eval --mfa "GetTagHistory.ReleaseTasks.process/1" --argv -- "$args"


Here is the GetTagHistory.ReleaseTasks module:

defmodule GetTagHistory.ReleaseTasks do

alias GetTagHistory.ConsoleIO.CLI, as: ConsoleIO

@start_apps [:dl_posbypass_gettaghistory, :retryable, :dl_posbypass_gettaghistory_consoleio]

def process(my_args) do IO.puts "received args: '#{inspect my_args}'" start_services() ConsoleIO.main(my_args) stop_services() end

defp start_services do IO.puts("Starting dependencies...") Enum.each(@start_apps, &Application.ensure_all_started/1) end

defp stop_services do IO.puts("Stopping dependencies.") :init.stop() end end

bitwalker commented 5 years ago

Unfortunately I'm not able to test on Windows at the moment, and it's not clear to me how you are invoking the release script (from conhost? from powershell?) and what the arguments are. From glancing through the scripts, I don't see anywhere that we are duplicating argument lists, but it may be some implicit behavior in powershell. Unfortunately command line argument parsing on Windows is a nightmare :(