Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Docker won't install on MacOS #432

Closed
aravindreddykrishna opened this issue Aug 26, 2023 · 4 comments
Closed

Docker won't install on MacOS #432

aravindreddykrishna opened this issue Aug 26, 2023 · 4 comments

Comments

@aravindreddykrishna
Copy link

aravindreddykrishna commented Aug 26, 2023

kamal setup
Acquiring the deploy lock...
INFO [9a8f3599] Running docker -v on 192.*******
INFO [9a8f3599] Finished in 0.021 seconds with exit status 127 (failed).
INFO [84e85df9] Running [ "${EUID:-$(id -u)}" -eq 0 ] on 192********
INFO [84e85df9] Finished in 0.024 seconds with exit status 0 (successful).
INFO Missing Docker on 192.. Installing…
INFO [eb976864] Running /usr/bin/env curl -fsSL https://get.docker.com | sh on 192.1
*
Releasing the deploy lock...
Finished all in 0.6 seconds
ERROR (SSHKit::Command::Failed): Exception while executing on host 192******: curl exit status: 1
curl stdout: # Executing docker install script, commit: c2de0811708b6d9015ed1a2c80f02c9b70c8ce7b

ERROR: Unsupported operating system 'macOS'
Please get Docker Desktop from https://www.docker.com/products/docker-desktop
curl stderr: Nothing written


I have installed docker desktop manually and docker -v responds with version but still seeing this issue.
ENV- Mac mini M2

@dhh
Copy link
Member

dhh commented Sep 16, 2023

Kamal was not designed for deployment on macOS. Only from macOS.

@dhh dhh closed this as completed Sep 16, 2023
saramic added a commit to failure-driven/rails-metal-cloud-metal that referenced this issue Oct 29, 2023
seems like Kamal needs docker and it is not made to deploy to a MacOS

  basecamp/kamal#432 (comment)
@filipesilva
Copy link

filipesilva commented Nov 28, 2024

This seems related to https://github.com/capistrano/sshkit?tab=readme-ov-file#the-command-map, how the SSH session won't have the same $PATH as an interactive session. In my mac, docker is added to $PATH under /usr/local/bin/docker.

Perhaps supporting the command_map or default_env in deploy.yml's sshkit section could help, but even then there might be other issues.

sshkit:
  default_env:
    path: "/usr/local/bin:$PATH"

I see how this wouldn't make much sense since this isn't really a supported case. Just leaving my attempts here in case someone else is trying it.

I debugged using kamal setup -v, which gave me a lot more logging. I tried to make it work by adding the default_env to this file:

SSHKit.config.command_map[:docker] = "docker" # No need to use /usr/bin/env, just clogs up the logs

I found the locally installed kamal in my rbenv gems at /Users/my-user/.rbenv/versions/3.3.6/lib/ruby/gems/3.3.0/gems/kamal-2.3.0/lib/kamal/commander.rb:

      SSHKit.config.default_env = { path: "/usr/local/bin:$PATH" } # added this
      SSHKit.config.command_map[:docker] = "docker" # No need to use /usr/bin/env, just clogs up the logs

This allowed docker to run, and also docker-credential-desktop which is later called, but still had login errors:

  ERROR (SSHKit::Command::Failed): Exception while executing on host xxx: docker exit status: 1
docker stdout: Nothing written
docker stderr: WARNING! Using --password via the CLI is insecure. Use --password-stdin.
Error saving credentials: error storing credentials - err: exit status 1, out: `error storing credentials - err: exit status 1, out: `User interaction is not allowed.``

Later after manually login in docker in that machine it changed to

  ERROR (SSHKit::Command::Failed): Exception while executing on host xxx: docker exit status: 1
docker stdout: Nothing written
docker stderr: WARNING! Using --password via the CLI is insecure. Use --password-stdin.
Error saving credentials: error storing credentials - err: exit status 1, out: `error getting credentials - err: exit status 1, out: `keychain cannot be accessed because the current session does not allow user interaction. The keychain may be locked; unlock it by running "security -v unlock-keychain ~/Library/Keychains/login.keychain-db" and try again``

At this point I googled around these errors and tried to remove the "credsStore": "desktop" line in ~/.docker/config.json on the Mac server. This is probably a bad idea. But it got me as far as building the image.

Then I started getting an error

 DEBUG [3139986b] Command: ( export PATH="/usr/local/bin:$PATH" ; /usr/bin/env mkdir -p .kamal && echo [2024-11-28T00:10:48Z] [xxx] Pulled image with version efc669703b2fcd85e2e0b465b7f2cc2de42ddf51 >> .kamal/blog-audit.log )
 DEBUG [3139986b] 	zsh:1: no matches found: [2024-11-28T00:10:48Z]
  Finished all in 8.8 seconds
Releasing the deploy lock...
 DEBUG [73ab7531] Running /usr/bin/env rm .kamal/lock-blog/details && rm -r .kamal/lock-blog on xxx
 DEBUG [73ab7531] Command: ( export PATH="/usr/local/bin:$PATH" ; /usr/bin/env rm .kamal/lock-blog/details && rm -r .kamal/lock-blog )
 DEBUG [73ab7531] Finished in 0.134 seconds with exit status 0 (successful).
  Finished all in 10.1 seconds
  ERROR (SSHKit::Command::Failed): Exception while executing on host xxx: mkdir exit status: 1
mkdir stdout: Nothing written
mkdir stderr: zsh:1: no matches found: [2024-11-28T00:10:48Z]

That turned out to be because zsh uses brackets for globs. I ran chsh -s /bin/bash on the server to change the default shell to bash and that got me over that hump. Afterwards I got the familiar docker platform issues:

  ERROR (SSHKit::Command::Failed): Exception while executing on host xxx: docker exit status: 1
docker stdout: Nothing written
docker stderr: Error response from daemon: no matching manifest for linux/arm64/v8 in the manifest list entries: no match for platform in manifest: not found

Which can also be sorted by a default_env entry

SSHKit.config.default_env = { path: "/usr/local/bin:$PATH", docker_default_platform: "linux/amd64" }

But then leads to further madness as Mac cp is not the same as GNU:

 DEBUG [7dd859f7] Command: ( export PATH="/usr/local/bin:$PATH" DOCKER_DEFAULT_PLATFORM="linux/amd64" ; /usr/bin/env mkdir -p .kamal/apps/blog/assets/volumes/web-efc669703b2fcd85e2e0b465b7f2cc2de42ddf51 ; cp -rnT .kamal/apps/blog/assets/extracted/web-efc669703b2fcd85e2e0b465b7f2cc2de42ddf51 .kamal/apps/blog/assets/volumes/web-efc669703b2fcd85e2e0b465b7f2cc2de42ddf51 )
 DEBUG [7dd859f7] 	cp: illegal option -- T
usage: cp [-R [-H | -L | -P]] [-fi | -n] [-aclpSsvXx] source_file target_file
       cp [-R [-H | -L | -P]] [-fi | -n] [-aclpSsvXx] source_file ... target_directory
  Finished all in 38.3 seconds
Releasing the deploy lock...
 DEBUG [54712c85] Running /usr/bin/env rm .kamal/lock-blog/details && rm -r .kamal/lock-blog on xxx
 DEBUG [54712c85] Command: ( export PATH="/usr/local/bin:$PATH" DOCKER_DEFAULT_PLATFORM="linux/amd64" ; /usr/bin/env rm .kamal/lock-blog/details && rm -r .kamal/lock-blog )
 DEBUG [54712c85] Finished in 0.822 seconds with exit status 0 (successful).
  Finished all in 40.8 seconds
  ERROR (SSHKit::Command::Failed): Exception while executing on host xxx: mkdir exit status: 64
mkdir stdout: Nothing written
mkdir stderr: cp: illegal option -- T
usage: cp [-R [-H | -L | -P]] [-fi | -n] [-aclpSsvXx] source_file target_file
       cp [-R [-H | -L | -P]] [-fi | -n] [-aclpSsvXx] source_file ... target_directory

brew install coreutils will install GNU cp as gcp, by default at /opt/homebrew/bin/gcp, so you can delve deeper into madness by copying it over as cp to a folder (e.g. /Users/my-user/coreutils-kamal/cp) and then add it to the path

SSHKit.config.default_env = { path: "/usr/local/bin:/Users/my-user/coreutils-kamal:$PATH", docker_default_platform: "linux/amd64" }

At this point kamal setup will finish successfully. As a slight aside I was using Cloudflare tunnel, and had to turn off ssl in deploy.yml's proxy section.

So in sum I had to:

  • hack Kamal a bit to support SSHKit.config.default_env
  • remove "credsStore": "desktop" from server docker config
  • set server shell to bash
  • add /usr/local/bin/ and gnu cp to path

@dhh would you accept a PR that adds default_env to the sshkit options? I don't think it'd go against any official lack of support, and looks generally useful for sshkit.

@HLFH
Copy link
Contributor

HLFH commented Dec 4, 2024

@filipesilva Anything that puts us closer to supporting "Kamal deploy to macOS" would be great either as a PR or as a soft fork.

filipesilva added a commit to filipesilva/kamal that referenced this issue Dec 9, 2024
Enables deploy to MacOS hosts.

Will still need further configuration though:
- `default_env` needs to be set to a PATH that contains docker and coreutils `cp`
- desktop docker config needs to have no `credsStore`
- shell needs to be changed to `bash`

All this can be done by the user though, whereas passing on `default_env` to SSHKit needed to happen on Kamal.

cc @dhh, @HLFH

See basecamp#432 (comment) for details.
filipesilva added a commit to filipesilva/kamal that referenced this issue Dec 9, 2024
Enables deploy to MacOS hosts.

Will still need further configuration though:
- `default_env` needs to be set to a PATH that contains docker and coreutils `cp`
- desktop docker config needs to have no `credsStore`
- shell needs to be changed to `bash`

All this can be done by the user though, whereas passing on `default_env` to SSHKit needed to happen on Kamal.

cc @dhh, @HLFH

See basecamp#432 (comment) for details.
@HLFH
Copy link
Contributor

HLFH commented Dec 11, 2024

@filipesilva I have fixed the zsh issue in this PR: #1281. You can probably keep zsh?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants