Azure / azure-dev

A developer CLI that reduces the time it takes for you to get started on Azure. The Azure Developer CLI (azd) provides a set of developer-friendly commands that map to key stages in your workflow - code, build, deploy, monitor, repeat.
https://aka.ms/azd
MIT License
402 stars 195 forks source link

[Bug] App Service can't run files with improper Windows CRLF line endings #563

Open charris-msft opened 2 years ago

charris-msft commented 2 years ago

Output from azd version azd version 0.1.0-beta.5 (commit 7bd25dd6f1b1899abf63b5f6f36d268a465183e4)

Output from az version "azure-cli": "2.39.0"

Describe the bug On Windows 11 when running azd up https://github.com/tonybaloney/django-on-azure the files in the repo are downloaded, the line endings are changed to CRLF, and when App Service attempts to run the startup.sh script, it errors out with `Unknown command: 'migrate\r'. Did you mean migrate?

image

To Reproduce

  1. azd up https://github.com/tonybaloney/django-on-azure
  2. view log stream for the App Service

Expected behavior I expect the azd to know that it is packaging files for App Service Linux and configure the line endings appropriately (LF).

Environment Information on your environment:

Additional context I have a video showing the whole experience of reproducing the issue and fixing it by saving the file with LF line endings in VS Code if you would like to review it.

weikanglim commented 2 years ago

@charris-msft The way azd up currently works is by calling git clone <templateUrl> --depth 1 and removing Git history. There is thinking to avoid git clone entirely in the future but there are other complications currently.

I suspect core.autocrlf = true might be setup on the Windows machine, which is causing the files to be rewritten to CRLF on checkout. For now, I think this can be resolved by adding .gitattributes file in your Git repository with contents:

*.sh text eol=lf

This might just be good practice to allow *.sh to be interpreted correctly for any cloned repositories and should resolve your problem.

charris-msft commented 2 years ago

editing the .gitattributes does sound like a nice, albeit non-obvious, workaround. I think it's great for templates we create, and perhaps we should even build something that scans Azure-Samples for azd templates to make sure it's specified. Would love to get @tonybaloney's take as he's more acquainted with this than I am.