Skip to content

Commit 5a6e98a

Browse files
authored
feat(bash-hook): Add cli arg to override sentry-cli command (#852)
* feat(bash-hook): Add cli arg to override sentry-cli command 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.
1 parent 7f24f03 commit 5a6e98a

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

src/bashsupport.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ _sentry_err_trap() {
3030
echo "@exit_code:${_exit_code}" >> "$_SENTRY_TRACEBACK_FILE"
3131

3232
: >> "$_SENTRY_LOG_FILE"
33-
export SENTRY_LAST_EVENT=$("___SENTRY_CLI___" bash-hook --send-event --traceback "$_SENTRY_TRACEBACK_FILE" --log "$_SENTRY_LOG_FILE" ___SENTRY_NO_ENVIRON___)
33+
export SENTRY_LAST_EVENT=$(___SENTRY_CLI___ bash-hook --send-event --traceback "$_SENTRY_TRACEBACK_FILE" --log "$_SENTRY_LOG_FILE" ___SENTRY_NO_ENVIRON___)
3434
rm -f "$_SENTRY_TRACEBACK_FILE" "$_SENTRY_LOG_FILE"
3535
}
3636

src/commands/bash_hook.rs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,12 @@ pub fn make_app<'a, 'b: 'a>(app: App<'a, 'b>) -> App<'a, 'b> {
3535
.long("no-environ")
3636
.help("Do not send environment variables along"),
3737
)
38+
.arg(
39+
Arg::with_name("cli")
40+
.long("cli")
41+
.value_name("CMD")
42+
.help("Explicitly set/override the sentry-cli command"),
43+
)
3844
.arg(
3945
Arg::with_name("send_event")
4046
.long("send-event")
@@ -186,11 +192,16 @@ pub fn execute<'a>(matches: &ArgMatches<'a>) -> Result<(), Error> {
186192
"___SENTRY_TRACEBACK_FILE___",
187193
&traceback.display().to_string(),
188194
)
189-
.replace("___SENTRY_LOG_FILE___", &log.display().to_string())
190-
.replace(
191-
"___SENTRY_CLI___",
195+
.replace("___SENTRY_LOG_FILE___", &log.display().to_string());
196+
197+
if matches.is_present("cli") {
198+
script = script.replace("___SENTRY_CLI___", matches.value_of("cli").unwrap());
199+
} else {
200+
script = script.replace(
201+
"__SENTRY_CLI__",
192202
&env::current_exe().unwrap().display().to_string(),
193203
);
204+
}
194205

195206
if matches.is_present("no_environ") {
196207
script = script.replace("___SENTRY_NO_ENVIRON___", "--no-environ");

0 commit comments

Comments
 (0)