az containerapp exec fails to run shell scripts in non-interactive environment
- Dominant language
- Python
- Stars
- 4.6k
- Forks
- 3.5k
- Avg merge
- 3d 2h
- Merged PRs (30d)
- 60
Description
**Related command**
```powershell
$cmd = "/app/data/clean.sh"
& az containerapp exec `
--name $container_name `
--resource-group $rg_name `
--command $cmd `
--debug
```
**Describe the bug**
When running az containerapp exec non-interactively, terminal control operation fails. The azure cli tries to resize the terminal (evidenced by `os.get_terminal_size()` call followed by `OSError: [Errno 25] Inappropriate ioctl for device` error). The underlying error happens in `termios.tcgetattr(fd)` function. See Additional Context below for details.
**To Reproduce**
1. Deploy Container Apps Environment
2. Create a shell script (hello.sh)
```bash
#!/bin/bash
echo 'hello'
```
4. Deploy Container with the shell script
```dockerfile
FROM mcr.microsoft.com/dotnet/runtime:6.0-jammy
COPY ./hello.sh /hello.sh
RUN chmod +x /hello.sh
ENTRYPOINT ["tail", "-f", "/dev/null"]
```
5. Run the shell script with `az containerapp exec` locally to verify it works (it should work both on windows and ubuntu)
6. Run the shell script with `az containerapp exec` in github actions (it fails, both with ubuntu-latest and windows-latest)
**Expected behavior**
Should echo 'hello'
**Environment summary**
> Github Actions
```
Current runner version:
Operating System
Ubuntu
22.04
LTS
Runner Image
Image: ubuntu-22.04
Version: 20230409
Included Software: https://github.com/actions/runner-images/blob/ubuntu22/20230409.1/images/linux/Ubuntu2204-Readme.md
Image Release: https://github.com/actions/runner-images/releases/tag/ubuntu22%2F20230409.1
Runner Image Provisioner
5.0.139.1
```
**Additional context**
```pwsh
Exception in thread Thread-1 (read_ssh):
Traceback (most recent call last):
File "/opt/az/lib/python3.10/threading.py", line 1016, in _bootstrap_inner
self.run()
File "/opt/az/lib/python3.10/threading.py", line 953, in run
self._target(*self._args, **self._kwargs)
File "/opt/az/azcliextensions/containerapp/azext_containerapp/_ssh_utils.py", line 123, in read_ssh
_resize_terminal(connection)
File "/opt/az/azcliextensions/containerapp/azext_containerapp/_ssh_utils.py", line 154, in _resize_terminal
size = os.get_terminal_size()
OSError: [Errno 25] Inappropriate ioctl for device
DEBUG: cli.azure.cli.core.azclierror: Traceback (most recent call last):
File "/opt/az/lib/python3.10/site-packages/knack/cli.py", line 233, in invoke
cmd_result = self.invocation.execute(args)
File "/opt/az/lib/python3.10/site-packages/azure/cli/core/commands/__init__.py", line 663, in execute
raise ex
File "/opt/az/lib/python3.10/site-packages/azure/cli/core/commands/__init__.py", line 726, in _run_jobs_serially
results.append(self._run_job(expanded_arg, cmd_copy))
File "/opt/az/lib/python3.10/site-packages/azure/cli/core/commands/__init__.py", line 697, in _run_job
result = cmd_copy(params)
File "/opt/az/lib/python3.10/site-packages/azure/cli/core/commands/__init__.py", line 333, in __call__
return self.handler(*args, **kwargs)
File "/opt/az/lib/python3.10/site-packages/azure/cli/core/commands/command_operation.py", line 121, in handler
return op(**command_args)
File "/opt/az/azcliextensions/containerapp/azext_containerapp/custom.py", line 2716, in containerapp_ssh
writer = get_stdin_writer(conn)
File "/opt/az/azcliextensions/containerapp/azext_containerapp/_ssh_utils.py", line 187, in get_stdin_writer
tty.setcbreak(sys.stdin.fileno()) # needed to prevent printing arrow key characters
File "/opt/az/lib/python3.10/tty.py", line 32, in setcbreak
mode = tcgetattr(fd)
termios.error: (25, 'Inappropriate ioctl for device')
```
Contributor guide
Assessment
This issue has not been assessed yet.