Skip to content

Conversation

@BYK
Copy link
Member

@BYK BYK commented Oct 30, 2020

When using sentry-cli through Docker, the bash hook does not work as:

  1. The inferred path of sentry-cli becomes the path inside the container, and does not apply to the host
  2. The files used for reporting live outside the container and they need to be mapped to the container when running it.

This patch chooses the more flexible --cli argument to solve both problems where one can do something like

docker run --rm getsentry/sentry-cli bash-hook --cli='docker run --rm -v "$_SENTRY_TRACEBACK_FILE:$SENTRY_TRACEBACK_FILE" -v "$_SENTRY_LOG_FILE:$_SENTRY_LOG_FILE" getsentry/sentry-cli

Now that's ugly as hell, yes and we may opt to have auto detection for running inside docker to handle this. The downside is then we'd not support any other container engine.

When using `sentry-cli` through Docker, the bash hook does not work as:
1. The inferred path of `sentry-cli` becomes the path inside the container, and does not apply to the host
2. The files used for reporting live outside the container and they need to be mapped to the container when running it.

This patche choses the more flexible `--cli` argument to solve both problemes where one can do something like

```docker run --rm getsentry/sentry-cli bash-hook --cli='docker run --rm -v "$_SENTRY_TRACEBACK_FILE:$SENTRY_TRACEBACK_FILE" -v "$_SENTRY_LOG_FILE:$_SENTRY_LOG_FILE" getsentry/sentry-cli
```

Now that's ugly as hell, yes and we may opt to have auto detection for running inside docker to handle this. The downside is then we'd not support any other container engine.
@BYK BYK requested review from jan-auer and untitaker October 30, 2020 11:32
Comment on lines 197 to 204
if matches.is_present("cli") {
script = script.replace(
"___SENTRY_CLI___",
&env::current_exe().unwrap().display().to_string(),
);
matches.value_of("cli").unwrap()
);
} else {
script = script.replace("__SENTRY_CLI__", &env::current_exe().unwrap().display().to_string());
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of this, I tried every possible variation of matcher and unwrap_or_else etc. but they gave me hell with the temporary return value of the env::current_exe().unwrap().display().to_string() call or some weird mismatch between String and str types.

Open to suggestions to make this more "rustic".

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.replace(
  "__SENTRY_CLI__",
  matches
    .value_of("cli")
    .unwrap_or(&env::current_exe().unwrap().display().to_string()),
);

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kamilogorek that runs the expression &env::current_exe().unwrap().display().to_string() for the fallback unconditionally, which is why I went with this path (after exhausting the path of closures)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True, that'll be eagerly evaluated, and returning a ref from unwrap_or_else is tricky.

Comment on lines 197 to 204
if matches.is_present("cli") {
script = script.replace(
"___SENTRY_CLI___",
&env::current_exe().unwrap().display().to_string(),
);
matches.value_of("cli").unwrap()
);
} else {
script = script.replace("__SENTRY_CLI__", &env::current_exe().unwrap().display().to_string());
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.replace(
  "__SENTRY_CLI__",
  matches
    .value_of("cli")
    .unwrap_or(&env::current_exe().unwrap().display().to_string()),
);

@BYK BYK requested a review from kamilogorek November 2, 2020 10:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants