Solve Script Issues with GitAttributes
Solve Script Running Issues with .gitattributes
Today at work I was running into a pesky error when trying to run a service with
internal-service | /bin/sh: ./start.sh: not found
I had used a team GraphQL service template to generate my service and what was strange was that the current services not using the template were running fine with Docker Compose but every single one I generated failed!
After seeing that the problem was not just in my service but in the docker config of the template itself, I knew I had to contact the developer of the template. First we were stumped -the docker-compose.yml, Dockerfile, and aws.yml files were identical between working services and the ones failing based off of the template. But after some digging with the other developer, he suggested line endings being the problem:
bash-4.4$ ./start.sh bash: ./start.sh: /bin/bash^M: bad interpreter: No such file or directory bash-4.4$
In which the setup script he wrote contained Windows line CLRF endings, and when run in a Linux environment the lines caused a syntax error.
I was sure this was a common problem and sure enough I found articles that helped me discover .gitattributes files:
- First article
- Article on how to change all the line endings of a repo with .gitattributes
- Another article confirming problem was due to line endings
- Great summary of gitattributes
So the problem was that Windows CLRF line endings were causing our script to fail.
At this point, it was a simple fix using a .gitattributes file, which I will be using for future projects.
Add to the file:
* text=auto *.sh text eol=lf
git add --renormalize .: Change all line endings
git push: Problem solved!