serversideup / spin

🚀 Replicate your production environment locally using Docker. Just run "spin up". It's really that easy.
https://serversideup.net/open-source/spin/
GNU General Public License v3.0
1.2k stars 42 forks source link

Git line endings can cause issues with some WSL2 installations ($'\r': command not found) #99

Closed vresende closed 1 month ago

vresende commented 1 month ago

Current Behavior

"When trying to execute the command spin new laravel my-billion-dollar-idea, I am receiving the following error.

I am running this on Ubuntu via WSL2.

The error seems to be related to charset; running dos2unix on the file will probably fix it.

➜  spin new laravel my-billion-dollar-idea
🔄 Downloading template...
Cloning from git@github.com:serversideup/spin-template-laravel-basic.git
Cloning into '/tmp/tmp.nueE4nmBWp'...
remote: Enumerating objects: 417, done.
remote: Counting objects: 100% (32/32), done.
remote: Compressing objects: 100% (24/24), done.
remote: Total 417 (delta 11), reused 21 (delta 6), pack-reused 385 (from 1)
Receiving objects: 100% (417/417), 125.41 KiB | 465.00 KiB/s, done.
Resolving deltas: 100% (237/237), done.
/tmp/tmp.nueE4nmBWp/install.sh: line 3: $'\r': command not found

Expected Behavior

"The expected behavior is the creation of a new Laravel project using Spin."

Steps To Reproduce

  1. Install Spin according to the documentation.
  2. When trying to run spin version" or "spin --version, you will receive an error.
  3. Run find ~/.spin -type f -exec dos2unix {} ; to fix the error.
  4. Run spin version" or "spin --version again. It should return the expected output.
  5. Run spin new laravel my-billion-dollar-idea and you will receive the error mentioned in the issue description.

Environment

➜  spin debug
Spin Version:
v2.0.2 [stable] (User Installed)

Operating System Version:
PRETTY_NAME="Ubuntu 22.04.4 LTS"
NAME="Ubuntu"
VERSION_ID="22.04"
VERSION="22.04.4 LTS (Jammy Jellyfish)"
VERSION_CODENAME=jammy
ID=ubuntu
ID_LIKE=debian
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
UBUNTU_CODENAME=jammy

Docker Info:
WARNING: Plugin "/usr/local/lib/docker/cli-plugins/docker-scan" is not valid: failed to fetch metadata: fork/exec /usr/local/lib/docker/cli-plugins/docker-scan: no such file or directory
WARNING: No blkio throttle.read_bps_device support
WARNING: No blkio throttle.write_bps_device support
WARNING: No blkio throttle.read_iops_device support
WARNING: No blkio throttle.write_iops_device support
WARNING: daemon is not using the default seccomp profile
Client:
 Version:    27.1.1
 Context:    default
 Debug Mode: false
 Plugins:
  buildx: Docker Buildx (Docker Inc.)
    Version:  v0.16.1-desktop.1
    Path:     /usr/local/lib/docker/cli-plugins/docker-buildx
  compose: Docker Compose (Docker Inc.)
    Version:  v2.29.1-desktop.1
    Path:     /usr/local/lib/docker/cli-plugins/docker-compose
  debug: Get a shell into any image or container (Docker Inc.)
    Version:  0.0.34
    Path:     /usr/local/lib/docker/cli-plugins/docker-debug
  dev: Docker Dev Environments (Docker Inc.)
    Version:  v0.1.2
    Path:     /usr/local/lib/docker/cli-plugins/docker-dev
  extension: Manages Docker extensions (Docker Inc.)
    Version:  v0.2.25
    Path:     /usr/local/lib/docker/cli-plugins/docker-extension
  feedback: Provide feedback, right in your terminal! (Docker Inc.)
    Version:  v1.0.5
    Path:     /usr/local/lib/docker/cli-plugins/docker-feedback
  init: Creates Docker-related starter files for your project (Docker Inc.)
    Version:  v1.3.0
    Path:     /usr/local/lib/docker/cli-plugins/docker-init
  sbom: View the packaged-based Software Bill Of Materials (SBOM) for an image (Anchore Inc.)
    Version:  0.6.0
    Path:     /usr/local/lib/docker/cli-plugins/docker-sbom
  scout: Docker Scout (Docker Inc.)
    Version:  v1.11.0
    Path:     /usr/local/lib/docker/cli-plugins/docker-scout

Server:
 Containers: 32
  Running: 1
  Paused: 0
  Stopped: 31
 Images: 90
 Server Version: 27.1.1
 Storage Driver: overlay2
  Backing Filesystem: extfs
  Supports d_type: true
  Using metacopy: false
  Native Overlay Diff: true
  userxattr: false
 Logging Driver: json-file
 Cgroup Driver: cgroupfs
 Cgroup Version: 1
 Plugins:
  Volume: local
  Network: bridge host ipvlan macvlan null overlay
  Log: awslogs fluentd gcplogs gelf journald json-file local splunk syslog
 Swarm: inactive
 Runtimes: io.containerd.runc.v2 runc
 Default Runtime: runc
 Init Binary: docker-init
 containerd version: 2bf793ef6dc9a18e00cb12efb64355c2c9d5eb41
 runc version: v1.1.13-0-g58aa920
 init version: de40ad0
 Security Options:
  seccomp
   Profile: unconfined
 Kernel Version: 5.15.153.1-microsoft-standard-WSL2
 Operating System: Docker Desktop
 OSType: linux
 Architecture: x86_64
 CPUs: 16
 Total Memory: 23.43GiB
 Name: docker-desktop
 ID: e7cfdbe7-6c2d-435e-81d1-46f032cd2882
 Docker Root Dir: /var/lib/docker
 Debug Mode: false
 HTTP Proxy: http.docker.internal:3128
 HTTPS Proxy: http.docker.internal:3128
 No Proxy: hubproxy.docker.internal
 Labels:
  com.docker.desktop.address=unix:///var/run/docker-cli.sock
 Experimental: false
 Insecure Registries:
  hubproxy.docker.internal:5555
  127.0.0.0/8
 Live Restore Enabled: false

Anything else?

No

sueboy19 commented 1 month ago

https://forums.docker.com/t/no-blkio-warnings-on-docker-info/115857

meyay: It’s a warning that indicates that the kernel does not support blkio throttle settings for the containers.

If you really need that feature, you will have to compile your own WSL2 kernel and configure WSL2 to use it. The origin and fix are outside of docker’s reach.

YevheniiVolosiuk commented 1 month ago

The error command not found: $'\r' usually occurs when there are line-ending issues in a shell script. It typically happens when a script is created or edited on a Windows system, which uses carriage return and newline (\r\n) for line endings, rather than just newline (\n) used in Unix/Linux systems.

sed -i 's/\r$//' /tmp/tmp.yH8VAj9gTF/install.sh

But I can't find a place where it's located to see how it is written. This line /tmp/tmp.nueE4nmBWp/install.sh: line 3: $'\r': command not found

vresende commented 1 month ago

O erro command not found: $'\r' geralmente ocorre quando há problemas de fim de linha em um script de shell. Isso geralmente acontece quando um script é criado ou editado em um sistema Windows, que usa retorno de carro e nova linha (\r\n) para fins de linha, em vez de apenas nova linha (\n) usada em sistemas Unix/Linux.

sed -i 's/\r$//' /tmp/tmp.yH8VAj9gTF/install.sh

Mas não consigo encontrar um lugar onde ele esteja localizado para ver como está escrito. Esta linha/tmp/tmp.nueE4nmBWp/install.sh: line 3: $'\r': command not found

Exactly.

I need to use dos2unix to install spin.

The error is apparently in this file: https://github.com/serversideup/spin-template-laravel-basic/blob/main/install.sh I don't know if it's possible to make a PR with the fix.

jaydrogers commented 1 month ago

I'll be taking a look into this so you can run it natively with WLS2. Thanks for your patience!

YevheniiVolosiuk commented 1 month ago

O erro command not found: $'\r' geralmente ocorre quando há problemas de fim de linha em um script de shell. Isso geralmente acontece quando um script é criado ou editado em um sistema Windows, que usa retorno de carro e nova linha (\r\n) para fins de linha, em vez de apenas nova linha (\n) usada em sistemas Unix/Linux. sed -i 's/\r$//' /tmp/tmp.yH8VAj9gTF/install.sh Mas não consigo encontrar um lugar onde ele esteja localizado para ver como está escrito. Esta linha/tmp/tmp.nueE4nmBWp/install.sh: line 3: $'\r': command not found

Exactly.

I need to use dos2unix to install spin.

The error is apparently in this file: https://github.com/serversideup/spin-template-laravel-basic/blob/main/install.sh I don't know if it's possible to make a PR with the fix.

This is a fix for this error without any installation (natively).

https://github.com/serversideup/spin/pull/100

vresende commented 1 month ago

Thanks YevheniiVolosiuk

jaydrogers commented 1 month ago

Update

I was hoping to get to this today, but I ran into issues on another task (gotta love Fridays).

I am hoping next week will be a majority of my time towards Spin. I will keep you all posted!

jaydrogers commented 1 month ago

Another update

I am unfortunately not able to replicate this.

Video of my steps

https://github.com/user-attachments/assets/2568c6de-2947-4ee5-99d4-468c5158acde

Checklist/Questions

jaydrogers commented 1 month ago

The GitHub automation automatically closed this, but I will definitely re-open this if we can replicate it

vresende commented 1 month ago

@jaydrogers

Outra atualização

Infelizmente não consigo replicar isso.

Vídeo dos meus passos

SpinNewLaravel.mp4

Lista de verificação/perguntas

  • Todos estão executando o Spin v2.0.2?
  • Parece que estamos todos executando o Jammy (Ubuntu 22.04) no WSL
  • Certifique-se de que você está executando wslantes de executar qualquer comando. dos2unixNÃO deve ser necessário

I’m using WSL2 but with Ubuntu. If you run the same command through the Ubuntu terminal, it will show this error.

The Pull Request will solve this. It will adjust the file according to the environment. If you can approve it, I would be grateful.

jaydrogers commented 1 month ago

Thanks @vresende, I am grateful for your changes but I am always hesitant to publish a fix without having a full ability to replicate the bug and ensure the fix isn't going to cause issues on other platforms.

Are you able to record a screen walking through your steps showing the error?

It's odd that I cannot replicate it on my end because I have a pretty vanilla Ubuntu WSL setup. Nothing fancy with it.

vresende commented 1 month ago

@jaydrogers if possible, try using Windows with WSL2 to install Spin via the Ubuntu terminal, not PowerShell, and with that, you should be able to replicate the reported issue.

jaydrogers commented 1 month ago

Here is a video using the Ubuntu shell. I am very confused why I wouldn't be able to replicate the issue.

Are you able to record your screen showing that it's not working?

https://github.com/user-attachments/assets/18fc0bb6-d731-4d11-ad34-54a208f109e5

vresende commented 1 month ago

In the video below, I removed the installation of Spin and reinstalled it, as you will see, an error occurs.

I can work around the error by applying dos2unix to remove invalid line breaks.

However, when running the command spin new laravel my-app, the error persists.

https://github.com/user-attachments/assets/d612c3a7-174c-4e06-8d83-23fd051b1993

YevheniiVolosiuk commented 1 month ago

In the video below, I removed the installation of Spin and reinstalled it, as you will see, an error occurs.

I can work around the error by applying dos2unix to remove invalid line breaks.

However, when running the command spin new laravel my-app, the error persists. capture.mp4

can you show your

git config --edit --global

for these 2 options?

image

if it's not I have tried to make it like this and check if it helps. For me, it works. After new changes try to install (clone) a spin and new laravel one more time.

vresende commented 1 month ago

No vídeo abaixo, removi a instalação do Spin e reinstalei, como vocês verão, ocorre um erro. Posso contornar o erro aplicando dos2unix para remover quebras de linha inválidas. Porém, ao executar o comando spin new laravel my-app, o erro persiste. capture.mp4

você pode mostrar seu

git configuração --editar --global

para essas 2 opções?

imagem

se não for, tentei fazer assim e ver se ajuda. Para mim, funciona. Após novas mudanças, tente instalar (clonar) um spin e um novo laravel mais uma vez.

@YevheniiVolosiuk worked! After adding these configurations, I reinstalled and it resolved the issue.

Thank you very much.

If you could add this information to the documentation.

Best regards

jaydrogers commented 1 month ago

I greatly appreciate you both working through this!

Is there something I can do on the Spin side that would prevent these line endings?

I was just hesitant with the sed implementation because it was a file modification on the fly.

If there is a way I can set a Vscode setting or something, I'd love to see how that works.

vresende commented 1 month ago

I believe that adding this information to the documentation, specifically in the installation section for WSL2 and Linux, would be helpful. It should mention that if this error occurs, the following commands need to be executed:

git config --global core.autocrlf input
git config --global core.eol lf

Explanation of the command:

autocrlf = input: This means Git will convert CRLF (end of line in Windows) to LF (end of line in Unix) when committing. eol = lf: Defines that line breaks (End Of Line) should be LF.

YevheniiVolosiuk commented 1 month ago

I greatly appreciate you both working through this!

Is there something I can do on the Spin side that would prevent these line endings?

I was just hesitant with the sed implementation because it was a file modification on the fly.

If there is a way I can set a Vscode setting or something, I'd love to see how that works.

  1. Configure VSCode to Use LF for Line Endings

You can configure VSCode to use Unix-style line endings (LF) instead of Windows-style (CRLF):

Open the problematic file in VSCode.
Look at the bottom-right corner of the VSCode window. You'll see either CRLF or LF.
Click on CRLF and select LF from the pop-up menu.
Save the file. This will convert all line endings to LF.

To make this the default setting for all new files:

Open Settings in VSCode (Ctrl + ,).
Search for EOL or end of line.
Set Files: Eol to \n (Unix).
  1. Set Up a .gitattributes File in Your Repository

You can create a .gitattributes file to enforce Unix-style line endings:

Create a .gitattributes file in the root of your repository.

Add the following content to ensure all shell scripts (*.sh) use LF:

text

*.sh text eol=lf

Commit the .gitattributes file to your repository.

This ensures consistent line endings across all environments and prevents line-ending issues when pulling or cloning the repository.

Some ideas on how it can be resolved also need a test.

jaydrogers commented 1 month ago

Thanks for putting me down the right path @YevheniiVolosiuk!

I forgot that I am doing a sparse checkout on install:

https://github.com/serversideup/spin/blob/64fc817cce22be02d281811f2fb64d8fce34c5e1/tools/install.sh#L235-L258

In the upgrade script I had references to resolve line endings from there (a concept from the OhMyZSH team). I added this to the install script.

Testing

@vresende: Could you do me a favor and help me test the latest v2.1.0-alpha1 release?

Steps to follow

If you could perform these steps on your machine:

Remove spin

 rm -rf ~/.spin

Undo your changes from before

git config --global --unset core.autocrlf
git config --global --unset core.eol

Reinstall spin with alpha install script

bash -c "$(curl -fsSL -H "Cache-Control: no-cache" https://raw.githubusercontent.com/serversideup/spin/v2.1.0-alpha1/tools/install.sh)" "" --beta

Run "spin version"

spin version

This should hopefully work and be an automated fix with no user interaction 😅

YevheniiVolosiuk commented 1 month ago

"Happy to help! I'm glad we could resolve this together! :v:

vresende commented 1 month ago

image @jaydrogers tested and approved.

jaydrogers commented 1 month ago

Awesome!! Thanks for working through this!

Once v2.1.0 is stable and released, I would advise to remove ~/.spin and reinstall from the stable channel.

quantumwebco commented 3 weeks ago

I'm on 2.1.5 but still get this issue. Do we need to edit git config?

Spin Version: 
v2.1.5 [stable] (User Installed)

spin init laravel

image

UPDATE: solved by running

git config --global core.autocrlf input
git config --global core.eol lf
jaydrogers commented 3 weeks ago

I'm on 2.1.5 but still get this issue. Do we need to edit git config?


Spin Version: 

v2.1.5 [stable] (User Installed)

spin init laravel

image

UPDATE: solved by running


git config --global core.autocrlf input

git config --global core.eol lf

You may have to remove spin first, then redownload it to get the fix:

rm -rf ~/.spin

On install, it will run the commands for you to fix this.

quantumwebco commented 3 weeks ago

I did that. I had to rmrf it because it wouldn't update. So installed fresh but still had the issue. Solved it by running

git config --global core.autocrlf input
git config --global core.eol lf
jaydrogers commented 3 weeks ago

Can you share more details on your environment so I can see if I can replicate in WSL2?

quantumwebco commented 3 weeks ago

I posted more info in the already open issue. Sorry should have checked first before posting here https://github.com/serversideup/spin/issues/99 and here https://github.com/serversideup/spin-template-laravel-basic/issues/9

quantumwebco commented 3 weeks ago

FYI just running on our other devs machines and same issue