az acr build : UnicodeEncodeError: 'charmap' codec can't encode characters in position 57-96
See original GitHub issueDescribe the bug
When an az acr build
is run on Windows 10 using Git Bash and pip, it appears that the pip package install progress characters crash the log from the build. The build succeeds and the image is created in the container registry, even though the build is reported to have failed. The failure appears to be only associated with the log stream.
If the same command is run using a command prompt and az acr build
it succeeds. If the command is used with Git Bash and Docker desktop, it also succeeds.
Command Name
az acr build
Errors:
The command failed with an unexpected error. Here is the traceback:
'charmap' codec can't encode characters in position 57-96: character maps to <undefined>
Traceback (most recent call last):
File "D:\a\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\knack/cli.py", line 231, in invoke
File "D:\a\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/core/commands/__init__.py", line 658, in execute
File "D:\a\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/core/commands/__init__.py", line 721, in _run_jobs_serially
File "D:\a\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/core/commands/__init__.py", line 692, in _run_job
File "D:\a\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/core/commands/__init__.py", line 328, in __call__
File "D:\a\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/core/commands/command_operation.py", line 121, in handler
File "D:\a\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/command_modules/acr/build.py", line 143, in acr_build
File "D:\a\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/command_modules/acr/_stream_utils.py", line 58, in stream_logs
File "D:\a\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/command_modules/acr/_stream_utils.py", line 143, in _stream_logs
File "D:\a\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\colorama/ansitowin32.py", line 41, in write
File "D:\a\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\colorama/ansitowin32.py", line 162, in write
File "D:\a\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\colorama/ansitowin32.py", line 187, in write_and_convert
File "D:\a\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\colorama/ansitowin32.py", line 195, in write_plain_text
File "encodings\cp1252.py", line 19, in encode
UnicodeEncodeError: 'charmap' codec can't encode characters in position 57-96: character maps to <undefined>
To Reproduce:
Steps to reproduce the behaviour. Note that argument values have been redacted, as they may contain sensitive information.
The present working directory should contain Dockerfile
, app.py
, requirements.txt
.
app.py
from flask import Flask
from flask import request
app = Flask(__name__)
@app.route("/")
def hello_server():
host_and_port = request.headers.get('Host')
fragments = host_and_port.split(":")
hostname = fragments[0]
port = "80"
if len(fragments) > 1:
port = fragments[1]
return f"<p>Hello from {hostname}, listening on port {port}.</p>"
if __name__ == '__main__':
app.run(debug=True)
requirements.txt
Flask>=2.0
gunicorn>20.0
az acr build --resource-group {} --registry {} --image {} {}
The az acr build
from Git Bash with and the Dockerfile:
# syntax=docker/dockerfile:1
FROM python:slim-bullseye
WORKDIR /app
COPY . .
RUN pip3 install --upgrade pip && pip3 install -r requirements.txt
ENV PORT=5000
CMD ["sh", "-c", "gunicorn --bind 0.0.0.0:$PORT app:app"]
crashes.
However, the az acr build
from Git Bash and the Dockerfile:
# syntax=docker/dockerfile:1
FROM python:slim-bullseye
WORKDIR /app
COPY . .
RUN pip3 install --upgrade --progress-bar off pip && pip3 install --progress-bar off -r requirements.txt
ENV PORT=5000
CMD ["sh", "-c", "gunicorn --bind 0.0.0.0:$PORT app:app"]
succeeds.
Expected Behaviour
I expect that the build log should not crash when the build is run from Git Bash.
Environment Summary
Windows-10-10.0.19042-SP0
Python 3.10.4
Installer: MSI
azure-cli 2.36.0
Extensions:
account 0.2.2
azure-devops 0.23.0
db-up 0.2.6
Dependencies:
msal 1.17.0
azure-mgmt-resource 20.0.0
Additional Context
Issue Analytics
- State:
- Created a year ago
- Reactions:1
- Comments:10 (6 by maintainers)
Top GitHub Comments
Unfortunately, we can see the same issue with our Azure Pipeline
@AndreyBespamyatnov If you are seeing the same issue with Windows image in Azure Devops Pipeline then the same above plan can be done by implementing this via registry key using PS. You can run the below PS script for that:
More Info here. Hope this helps.