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

local execute - fails to read config file #212

Closed
n6g7 opened this issue Nov 26, 2018 · 18 comments
Closed

local execute - fails to read config file #212

n6g7 opened this issue Nov 26, 2018 · 18 comments

Comments

@n6g7
Copy link

n6g7 commented Nov 26, 2018

Context

I'm working on a CircleCI config generator (amongst other things) so I want to test that:

  • the generated config is valid (circleci config validate)
  • the generated tests pass (circleci local execute --job myjob)

From within CircleCI, so essentially I'm running those CircleCI commands in CircleCI. Very meta but it sounds like it should work.
First command (config validation) works fine.

Problem

I get the following error when running circleci local execute --job myjob (within a CircleCI job):

$ circleci local execute --job myjob
Docker image digest: sha256:0ae15d9b8329446dd5d241b1d654774871caa89c1cc47d513063c23037aae917
Error: failed to start event processor: failed to compute task config: failed to read config file: open circle.yml: no such file or directory

It's confusing because I'm using .circleci/config.yml and not using circle.yml.
The same command runs fine locally.

Running version 0.1.4211+14dfd68

What I tried

  • Using the --config argument ❌
  • Moving the generated code outside of the generator repo (to avoid git conflicts or even multiple circle ci config files in parent directories) ❌
  • Running chmod 777 .circleci/config.yml

Here's the smallest generator config file I've been able to reproduce teh bug with: https://gist.github.com/n6g7/f11008ee351b3dfd9c56f6c23b5ce7d6, I don't think the generated config file matters but can share it too if necessary.

Any idea where this could be coming from?

@dnephin
Copy link
Contributor

dnephin commented Nov 26, 2018

It's confusing because I'm using .circleci/config.yml and not using circle.yml

The error message is a bit misleading, but it is checking for .circleci/config.yml first and falling back to circle.yml if it doesn't find it.

Maybe try adding some ls -a or tree -a to the commands to check the directory myTestProject contains the files you expect? This error is coming from the entrypoint so very little is happening before this error. I'm not seeing any way for this to fail unless the file isn't there.

From your config example generate_project doesn't seem to accept a path, but the other jobs are using a working_directory, so I'm not sure if the make target creates that directory or not.

@n6g7
Copy link
Author

n6g7 commented Nov 26, 2018

Thanks for the quick reply!

The generated project does contain the files I expect (I've been ssh'ed in there for a while + I just added a ls -a . && ls -a .circleci and it looks good). Regarding the generate_project command, I did simplify it to remove unnecessary noise but there was a path argument and this part seems to work fine.
So I don't think it's a generation problem.

I can link to the failing build on CircleCI if that helps.

@n6g7
Copy link
Author

n6g7 commented Nov 26, 2018

  • /home/circleci/project-generator/myTestProject/.circleci/config.yml is properly generated (I can cat it)
  • circleci local execute --job myjob --config /home/circleci/project-generator/myTestProject/.circleci/config.yml still fails with:
    $ circleci local execute --job backend --config /home/circleci/project-generator/myTestProject/.circleci/config.yml
    Docker image digest: sha256:0ae15d9b8329446dd5d241b1d654774871caa89c1cc47d513063c23037aae917
    Error: failed to start event processor: failed to compute task config: failed to read config file: open /home/circleci/project-generator/myTestProject/.circleci/config.yml: no such file or directory

I can only see two explanations:

  • it's a permission error (eg. the CircleCI spaws a child process with a different user that can't read the file)
  • or there's an error handling problem somewhere in the cli or one of its dependencies which makes it look like a "no such file or directory" error when it's actually somethign else (I think this happens in build.go but I'm a go noob so not entirely sure...)

@dnephin
Copy link
Contributor

dnephin commented Nov 26, 2018

Oh, I just reread your post and I realize I missed the obvious. This won't work because local execute uses bind mount volumes and a docker engine provided by setup_remote_docker. setup_remote_docker does not work with bind mount volumes. The engine is running on a VM host which doesn't have access to the container filesystem where the job is running.

@n6g7
Copy link
Author

n6g7 commented Nov 26, 2018

Aaaaah, ok so I guess I'll have to find something else then. :(

Just for curiosity's sake, does that explain the error I'm seeing? It sounds like the error happens before the CLI even tries to run a docker command, right?

@matfax
Copy link
Contributor

matfax commented Nov 26, 2018

@n6g7 The error message is misleading; in the current version, it's always shown for various kinds of reasons.

@dnephin I'm also trying to get the build working circumventing the new cli and directly calling the picard cli from a Docker container. However, I'm confused that there is no docker on the image and a Docker config and environment variables don't seem to be respected. Then again, the image seems to need the docker socket. Is this cli closed source?

@dnephin
Copy link
Contributor

dnephin commented Nov 27, 2018

does that explain the error I'm seeing

Yes it does, the file system that it's looking at does not have that file because it's a bind mount to the VM host that does not have any files at that path.

It sounds like the error happens before the CLI even tries to run a docker command

There are two programs. circleci-cli runs circleci-agent in a container. local execute is implemented in circleci-agent, so it runs in the container.

Is this cli closed source?

circleci-agent is closed source at this time.

@anishkny
Copy link

I am facing a similar issue trying to run a generated config yml using circleci local execute in CircleCI.

In my test, I generate a processed.yml (running on CircleCI) and then execute:

circleci local execute --config /home/circleci/project/test/tmp.H4nOfY/processed.yml

But I get an error:

Downloading latest CircleCI build agent...
Docker image digest: sha256:...^@^@Error: failed to start event processor: failed to compute task config: failed to read config file: open /home/circleci/project/test/tmp.H4nOfY/processed.yml: no such file or directory
Exited with code 1

Is there a workaround for this?

@eric-hu
Copy link
Contributor

eric-hu commented Jan 15, 2019

@anishkny A workaround for running a CircleCI config generated inside of a CircleCI job is to commit that config and push it to Github/Bitbucket to trigger a new build. This is far from ideal, so we are considering ways to execute a new config without a commit and push.

@marcomorain
Copy link
Contributor

Closing due to inactivity. Please re-open if this is something you are still working on.

@jgonzalezd
Copy link

I'm running into the same issue, it doesn't even work for the demo repo.

circleci-demo-go$ circleci local execute --job build
Docker image digest: sha256:2e3d8ff7707b34b815fc6174ae5f6fcd8384f7a166a219bad29ac5ffc139f475
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

@fabOnReact
Copy link

fabOnReact commented May 7, 2020

@jgonzalezd

experiencing this issue after installing circleci with snap as by instructions and trying to run the hello world example.

➜  circleci-demo-go git:(master) circleci local execute --job build
Docker image digest: sha256:02289762fd0a295b971e4bc6bdb2ea4326a66748cae89352b5404c4ca286aaf9
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

this could be connected with limitations of snap packages to the $HOME directory, as it is trying to write/read a files save in the root /tmp/ while circleci can only run in /usr/home/<user-name>

SOLUTION TO FIX THE ISSUE

Remove snap packages (docker and snap)

sudo snap remove circleci docker

I used the command from the quick installation instructions without sudo and saved the bin file in my /home/<username>/Downloads folder

curl -fLSs https://raw.githubusercontent.com/CircleCI-Public/circleci-cli/master/install.sh | DESTDIR=/home/fabrizio/Downloads bash

then I moved the binary sudo mv /home/fabrizio/circleci /usr/local/bin, /usr/local/bin is in my path so I have access within the $HOME as normal user.

Installing docker as by askubuntu instructions (options 2), adding myself to the docker group and now the command works without problems

circleci was failing because snap installation can not write or read /tmp
It was fun playing with Ubuntu the entire day...

@fsproru
Copy link

fsproru commented May 15, 2020

Oh, I just reread your post and I realize I missed the obvious. This won't work because local execute uses bind mount volumes and a docker engine provided by setup_remote_docker. setup_remote_docker does not work with bind mount volumes. The engine is running on a VM host which doesn't have access to the container filesystem where the job is running.

@dnephin thanks for a thorough answer. It makes sense that circleci-agent runs inside a container. I'm running circleci local execute inside a docker container with mounted /var/run/docker.sock into the container from the host. Getting the same error. Is there a way for circleci-agent to have the file mounted so we can run circleci local execute inside a container?

@59023g
Copy link

59023g commented Aug 4, 2020

For MacOS, this worked: #391 (comment)
Looks like was regression

@zmunro
Copy link

zmunro commented Mar 8, 2021

@fabriziobertoglio1987 I can't run the quick installation command without sudo. When I try to run it I get this error:

$ curl -fLSs https://raw.githubusercontent.com/CircleCI-Public/circleci-cli/master/install.sh | DESTDIR=/home/zach/Downloads bash
Starting installation.
Installing CircleCI CLI v0.1.15085
Installing to /home/zach/Downloads
An error occured installing the tool.
The contents of the directory /tmp/tmp.1O5TPuzqUN have been left in place to help to debug the issue.

@fabOnReact
Copy link

@zmunro run those steps one by one in your terminal, you will be able to read and troubleshoot the error.

@nakarimi
Copy link

nakarimi commented Oct 4, 2021

@fabriziobertoglio1987 Thanks, I just run the script and its working now.

@visitsb
Copy link

visitsb commented Mar 28, 2022

Trying to get CircleCI working locally circleci local execute.
This works (and is simpler IMO 👍 )

  1. Run Docker in Docker with git tag (so CircleCI CLI can use git command within the container)
    • /usr/bin/docker run --rm --privileged --tty --interactive --volume /tmp:/tmp:rw --volume /var/run/docker.sock:/var/run/docker.sock:ro --user root --name circleci docker:git /bin/sh
    • Notice flags --privileged, volume for docker.sock and a rw mount of local /tmp.
    • Running container as --user=root
  2. Once inside the container, install bash, curl followed by CircleCI CLI.
    • /sbin/apk update
    • /sbin/apk add bash curl
    • /usr/bin/curl -fLSs https://circle.ci/cli | /bin/bash
  3. For a simple hello world example using CircleCI CLI (within the container, of course)
    • Create a foo_ci project (like this)
    • Create a .circleci/config.yml (like this)
    • Run a CircleCI job locally (like this). Have fun!
Downloading latest CircleCI build agent...
Docker image digest: sha256:f19e1f3d0aadb3dedfeb147b8e603fbbe7a9afba924b0db0c43f74753002c96b
====>> Spin up environment
Build-agent version  ()
System information:
 Server Version: 20.10.11
 Storage Driver: overlay2
  Backing Filesystem: extfs
 Cgroup Driver: cgroupfs
 Cgroup Version: 1
 Kernel Version: 4.19.232-1.ph3-esx
 Operating System: VMware Photon OS/Linux
 OSType: linux
 Architecture: x86_64

Starting container cimg/ruby:3.0-node
Warning: No authentication provided, using CircleCI credentials for pulls from Docker Hub.
  image is cached as cimg/ruby:3.0-node, but refreshing...
3.0-node: Pulling from cimg/ruby
Digest: sha256:22ef54404f4676b4f329fc7e0537d32b016e2120bdabb47c191f184d5a4aa56f
Status: Image is up to date for cimg/ruby:3.0-node
cimg/ruby:3.0-node:
  using image cimg/ruby@sha256:22ef54404f4676b4f329fc7e0537d32b016e2120bdabb47c191f184d5a4aa56f
  pull stats: Image was already available so the image was not pulled
  time to create container: 437ms
Creating Docker containers in parallel
Time to upload agent and config: 1.112579856s
Time to start containers: 1.090775188s
====>> Preparing environment variables
Using build environment variables:
  BASH_ENV=/tmp/.bash_env-localbuild-1648434504
  CI=true
  CIRCLECI=true
  CIRCLE_BRANCH=
  CIRCLE_BUILD_NUM=
  CIRCLE_JOB=build
  CIRCLE_NODE_INDEX=0
  CIRCLE_NODE_TOTAL=1
  CIRCLE_REPOSITORY_URL=
  CIRCLE_SHA1=
  CIRCLE_SHELL_ENV=/tmp/.bash_env-localbuild-1648434504
  CIRCLE_WORKING_DIRECTORY=~/project


The redacted variables listed above will be masked in run step output.====>> Checkout code
Making checkout directory "/home/circleci/project"
Copying files from "/tmp/_circleci_local_build_repo" to "/home/circleci/project"
====>> echo "Hello World"
  #!/bin/bash -eo pipefail
echo "Hello World"
Hello World
Success!

Works for below errors-

  1. circleci Error: failed to start event processor: failed to compute task config: failed to read config file: (👍 Step 1)
  2. cp: cannot stat '/tmp/_circleci_local_build_repo/.git': No such file or directory (👍 Try step 3 on a hello world project)

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