nicklockwood / SwiftFormat

A command-line tool and Xcode Extension for formatting Swift code
MIT License
7.86k stars 638 forks source link

Swiftformat not working from the docker image #1626

Open rswave opened 7 months ago

rswave commented 7 months ago

I'm trying to use swiftformat from the docker image and it always throws an error about not finding swiftformat.

Here are my steps Download the image:

docker pull ghcr.io/nicklockwood/swiftformat

Run it on the current directory which is my project folder

docker run -v `pwd`:`pwd`:rw -w `pwd` --rm ghcr.io/nicklockwood/swiftformat swiftformat ios
error: File not found at /Users/User/project/ios/swiftformat.

# just to test I moved to root folder and tried again
cd /
docker run -v `pwd`:`pwd`:rw -w `pwd` --rm ghcr.io/nicklockwood/swiftformat swiftformat .
error: File not found at /swiftformat.

I have tried different directories and still get the same error. Checked the path and swiftformat is present. I accessed the terminal in the docker and it is showing the binary in the /usr/bin folder when I run which swiftformat.

And this command like --help works and outputs properly

docker run -v `pwd`:`pwd`:rw -w `pwd` --rm ghcr.io/nicklockwood/swiftformat swiftformat --help

I'm running the image on Apple M1 Sonoma 14.1

I tried building the image myself on Apple M1 and it works as expected but when I build it on a x86 machine that image wouldn't work on the Apple SIlicone is another observation. The error I get is the same error I posted above.

nicklockwood commented 7 months ago

I don't use Docker myself and I'm not sure how to test it, but @vox-humana submitted the Docker action originally - perhaps he has some insight?

vox-humana commented 7 months ago

Hey @rswave Dockerfile already has swiftformat as an entry point so you don't need to provide an extra swiftformat argument (see some examples in the README). So in your case this should work:

docker run -v `pwd`:`pwd`:rw -w `pwd` --rm ghcr.io/nicklockwood/swiftformat ios