CircleCI-Public / circleci-cli

Use CircleCI from the command line
https://circleci-public.github.io/circleci-cli/
MIT License
411 stars 232 forks source link

Failed to read config file: read /tmp/local_build_config.yml: is a directory #716

Closed samahatw closed 11 months ago

samahatw commented 2 years ago

Meta:

CircleCI CLI Version: 0.1.18678+c3ad28b (homebrew)

Operating System: macOS Monterey 12.3.1

CircleCI CLI Diagnostic:

---
CircleCI CLI Diagnostics
---
Debugger mode: false
Config found: /Users/samaha/.circleci/cli.yml
API host: https://circleci.com
API endpoint: graphql-unstable
OK, got a token.
Trying an introspection query on API...
Ok.
Hello, Tiago Samaha.

Current behavior:

I'm trying to run the simplest example (foo_ci). I got an error when I try to execute locally, circleci local execute.

➜  foo_ci circleci local execute
Fetching latest build environment...
Docker image digest: sha256:2eb349056027b89d707b11304da7a77692338e15367d2be8f03cee6e4a83a69e
Error: failed to start event processor: failed to compute task config: failed to read config file: read /tmp/local_build_config.yml: is a directory

Expected behavior:

Run the pipeline locally.

When did this begin / Was this previously working?:

It never worked.

Additional Information:

Macbook Pro M1 (arm64). Using colima to run docker engine.

➜  foo_ci docker version
Client: Docker Engine - Community
 Version:           20.10.16
 API version:       1.41
 Go version:        go1.18.2
 Git commit:        aa7e414fdc
 Built:             Wed May 11 16:22:17 2022
 OS/Arch:           darwin/arm64
 Context:           colima
 Experimental:      true

Server:
 Engine:
  Version:          20.10.11
  API version:      1.41 (minimum version 1.12)
  Go version:       go1.16.15
  Git commit:       847da184ad5048b27f5bdf9d53d070f731b43180
  Built:            Wed Apr 13 23:41:08 2022
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          v1.5.8
  GitCommit:        1e5ef943eb76627a6d3b6de8cd1ef6537f393a71
 runc:
  Version:          1.0.0-rc95
  GitCommit:        b9ee9c6314599f1b4a7f497e1f1f856fe433d3b7
 docker-init:
  Version:          0.19.0
  GitCommit:
jeremyruffet commented 2 years ago

Same here on ubuntu 22.04 using snap installation.

r4v5 commented 2 years ago

I'm also seeing this on an M1 MBP, with Rancher Desktop:

❯ circleci local execute
Fetching latest build environment...
Docker image digest: sha256:c3be9fb94fdf377e6a8d508fc0b833bb18a99a36a2d7d89a8e39c7701838f701
WARNING: The requested image's platform (linux/amd64) does not match the detected host platform (linux/arm64/v8) and no specific platform was requested
Error: failed to start event processor: failed to compute task config: failed to read config file: read /tmp/local_build_config.yml: is a directory

I'm not sure if this is related to the container being linux/amd64 and the host being M1, or if it's a different problem entirely.

$ docker version
Client:
 Version:           20.10.17-rd
 API version:       1.41
 Go version:        go1.17.11
 Git commit:        c2e4e01
 Built:             Fri Jul 22 18:32:57 2022
 OS/Arch:           darwin/arm64
 Context:           default
 Experimental:      true

Server:
 Engine:
  Version:          20.10.16
  API version:      1.41 (minimum version 1.12)
  Go version:       go1.18.4
  Git commit:       f756502055d2e36a84f2068e6620bea5ecf09058
  Built:            Thu Jul 21 18:43:18 2022
  OS/Arch:          linux/arm64
  Experimental:     false
 containerd:
  Version:          v1.6.6
  GitCommit:        10c12954828e7c7c9b6e0ea9b0c02b01407d3ae1
 runc:
  Version:          1.1.2
  GitCommit:        a916309fff0f838eb94e928713dbc3c0d0ac7aa4
 docker-init:
  Version:          0.19.0
  GitCommit:

$ circleci version
0.1.20500+e042377 (homebrew)
eric-hemasystems commented 2 years ago

Same here. Using M1 MBP also. Using colima for container runtime.

% circleci local execute                     
Fetching latest build environment...
Docker image digest: sha256:8c7e8c77261c5c6227c1ee27f95f902bd046d42c8c849039d8144942ba6c12e7
WARNING: The requested image's platform (linux/amd64) does not match the detected host platform (linux/arm64/v8) and no specific platform was requested
Error: failed to start event processor: failed to compute task config: failed to read config file: read /tmp/local_build_config.yml: is a directory
% circleci version
0.1.22675+19bba9e (homebrew)
% docker version
Client: Docker Engine - Community
 Version:           20.10.21
 API version:       1.41
 Go version:        go1.19.3
 Git commit:        baeda1f82a
 Built:             Tue Oct 25 17:53:02 2022
 OS/Arch:           darwin/arm64
 Context:           colima
 Experimental:      true

Server:
 Engine:
  Version:          20.10.18
  API version:      1.41 (minimum version 1.12)
  Go version:       go1.18.6
  Git commit:       e42327a6d3c55ceda3bd5475be7aae6036d02db3
  Built:            Sun Sep 11 07:10:00 2022
  OS/Arch:          linux/arm64
  Experimental:     false
 containerd:
  Version:          v1.6.8
  GitCommit:        9cd3357b7fd7218e4aec3eae239db1f68a5a6ec6
 runc:
  Version:          1.1.4
  GitCommit:        5fd4c4d144137e991c4acebb2146ab1483a97925
 docker-init:
  Version:          0.19.0
  GitCommit:        
% colima version
colima version 0.4.6
git commit: 10377f3a20c2b0f7196ad5944264b69f048a3d40

runtime: docker
arch: aarch64
client: v20.10.21
server: v20.10.18
bhamail commented 1 year ago

Also unable to launch local circleci build using Rancher on MacOS with same error. This is a bigger problem now due to recent licensing to Docker Desktop (which prohibit use in corporate environment unless enterprise license is purchased). Any solutions?

smarquez1 commented 1 year ago

Related colima issue: https://github.com/abiosoft/colima/issues/571

sverch commented 1 year ago

I think I at least know what's happening. Installed using snap on Ubuntu 22.04.

TLDR

Docker sometimes can't mount files from /tmp, which at least seems to be the case for installs using snap, and the confusing failure mode is that it just creates a directory instead of failing.

Ubuntu 22.04 Workaround

Do not install docker and circleci using snap. Use one of the other installation methods. That solved the problem for me.

Debugging Details

First, [here's the code](https://github.com/CircleCI-Public/circleci-cli/blob/develop/local/local.go#L276) that references that path. It seems like this is a volume being mounted in the docker container that's running the command. Running with the `--debug` flag, I can see the docker command that is being run. Running that directly reproduces the issue: ``` $ docker run --interactive --tty --rm --volume /var/run/docker.sock:/var/run/docker.sock --volume /tmp/214569133_circleci_config.yml:/tmp/local_build_config.yml --volume /home/sverch/git/circleci-cli:/home/sverch/git/circleci-cli --volume /home/sverch/.circleci:/root/.circleci --workdir /home/sverch/git/circleci-cli circleci/picard@sha256:fd5e6588227dc32c8b858582845cf3848e47da0caa340663dd9d12449c3cdbb7 circleci build --config /tmp/local_build_config.yml --job foo foo Error: failed to start event processor: failed to compute task config: failed to read config file: read /tmp/local_build_config.yml: is a directory ``` From [this post](https://stackoverflow.com/a/42260979): > If you experience a directory being created in place of the file you are trying to mount, you have probably failed to supply a valid and absolute path. This is a common mistake with a silent and confusing failure mode. Going with the theory that something is wrong with that path, I moved the config file to the current directory: ``` $ docker run --interactive --tty --rm --volume /var/run/docker.sock:/var/run/docker.sock --volume $PWD/config.yml:/tmp/local_build_config.yml --volume /home/sverch/git/circleci-cli:/home/sverch/git/circleci-cli --volume /home/sverch/.circleci:/root/.circleci --workdir /home/sverch/git/circleci-cli circleci/picard@sha256:fd5e6588227dc32c8b858582845cf3848e47da0caa340663dd9d12449c3cdbb7 circleci build --config /tmp/local_build_config.yml --job foo foo ====>> Spin up environment ... etc. ``` So in that case, it works! Given all this, my theory is that there's some issue with docker mounting volumes from `/tmp`. Sure enough, [this post](https://stackoverflow.com/a/65267561) says exactly that: > The /tmp filesystem simply isn't accessible to the docker engine when it's running within the snap isolation. You can [install docker directly on Ubuntu from the upstream Docker repositories](https://docs.docker.com/engine/install/ubuntu/) for a more traditional behavior.
abdelDriowya commented 1 year ago

Hi @samahatw do you still have this issue ?

jcroucher commented 1 year ago

I am M1 mac

circleci local execute build Fetching latest build environment...

Error: failed to start event processor: failed to compute task config: failed to read config file: read /tmp/local_build_config.yml: is a directory

circleci version 0.1.26837+b104265 (homebrew)

loderunner commented 1 year ago

Thanks everyone for reporting this issue and contributing in the comments!

The underlying problem comes from Lima not accepting /tmp as a mount for its VMs, as it considers it a "system path" similar to /etc or /usr.. Any container distribution using Lima will face this issue, including colima and Rancher Desktop.

We're currently at work on this, and we seem to have found a solution in #967. We're still working on adding some tests and checks to make sure this is reliable and future-proof, and we'll release it as soon as we can.

loderunner commented 11 months ago

Version 0.1.29560 just released.

It contains a fix for this issue. Define circleci's temporary directory:

This should fix the issue for colima, Rancher Desktop and other Lima-based container distributions.

earonesty commented 1 month ago

Version 0.1.29560 just released.

this is not fixed for wsl2, but using --temp-dir worked around it thanks!