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

Use relative path with docker docker-compose runner #81

Closed
AlexeyMatskevich opened this issue Oct 15, 2019 · 5 comments · Fixed by #82
Closed

Use relative path with docker docker-compose runner #81

AlexeyMatskevich opened this issue Oct 15, 2019 · 5 comments · Fixed by #82

Comments

@AlexeyMatskevich
Copy link
Contributor

I have Dockerfile

FROM $some_user/$some_project:1.0.1

WORKDIR /app

RUN ...

and my project pwd is /home/$user/Projects/project
i try to run post-checkout hook from example with docker runner.
I get result

Lefthook v0.6.3
RUNNING HOOKS GROUP: post-checkout

  EXECUTE > 01-bundle-checkinstall

  EXECUTE > 02-db-migrate
Starting project_redis_1    ... done
Starting project_postgres_1 ... done
Traceback (most recent call last):
ruby: No such file or directory -- /home/$user/Projects/project/.lefthook/post-checkout/02-db-migrate (LoadError)

Is it possible to transfer the relative path to the runner instead of absolute?

I tried to create images with copy host pwd

FROM $some_user/$some_project:1.0.1

ARG APP_DIR
WORKDIR APP_DIR

RUN ...

docker build --build-arg APP_DIR=$(pwd)... it helped me, but this is a bad hack.
Hard-Coded path in container also not an option.

Thank you for your attention.

@Arkweid
Copy link
Collaborator

Arkweid commented Oct 15, 2019

Hello @AlexeyMatskevich
If you try to run something inside a docker follow this chapter:
https://github.com/Arkweid/lefthook/blob/master/docs/full_guide.md#referencing-commands-from-lefthookyml
Is it helps?

Is it possible to transfer the relative path to the runner instead of absolute?

We suppose runner it's a simple program and does't require a path at all. Can you show your config files?

@AlexeyMatskevich
Copy link
Contributor Author

AlexeyMatskevich commented Oct 15, 2019

Hi @Arkweid thanks, for answer.
I tried to use examples from the documentation before I opened the ticket, I appreciate your time.
Nonetheless, I have questions on examples:
Should I sure use lefthook-local.yml for define docker runner?
Can I use docker-compose?
My config lefthook.yml and lefthook-local.yml
I pushed current code with using example from your link, but I use docker-compose, my result:

Lefthook v0.6.3
RUNNING HOOKS GROUP: post-checkout

  EXECUTE > 01-bundle-checkinstall

  EXECUTE > 02-db-migrate
Starting ohmuritel_postgres_1 ... done
Starting ohmuritel_redis_1    ... done
bash: /home/alexey/RubymineProjects/ohmuritel/.lefthook/post-checkout/02-db-migrate: No such file or directory

  EXECUTE > 03-crystalball-update
(SKIP BY BROKEN PIPE)

SUMMARY: (done in 1.11 seconds)
✔️  01-bundle-checkinstall
🥊  02-db-migrate

@Arkweid
Copy link
Collaborator

Arkweid commented Oct 16, 2019

Can I use docker-compose?

I never used docker-compouse in such way 😅
When I working with project I have already running docker-compose. So my lefthook just run some command inside already working container.

Should I sure use lefthook-local.yml for define docker runner?

We have lefthook-local.yml just only for override settings from lefthook.yml, because teammates may not using docker and follow a "native" development.

@AlexeyMatskevich
Copy link
Contributor Author

Thanks for the clarifications.
I tried different ways to launch a hook in a container with compose. If I use the command for runner docker-compose run --rm <container_id_or_name> ruby in lefthook.yml file ore docker-compose run --rm <container_id_or_name> {cmd} version in lefthook-local.yml then i have problem with absolute path to script file.
I mount the folder with the code in the container and the absolute paths to the script are different.
As far as I understand, the lefthook passes the path to the file for runner and the remaining arguments.
And the program cannot find the script in the container with the path from the host machine.
When I create a container with the same project path as on the host machine, everything works fine. Therefore, I thought that the problem is passing the absolute path to the script for runner instead of relative.
I also tried the exec option with containers already running through docker-compose.

@Arkweid
Copy link
Collaborator

Arkweid commented Oct 17, 2019

I have a lack of time these days, but if you interesting you can try to make PR for that relative/absolute path problem. Especially now is the Hacktoberfest!
This one accept the runner path:
https://github.com/Arkweid/lefthook/blob/master/cmd/run.go#L203 which seems to interpreted as an absolute path. You can change it for example on something like this:
https://golang.org/pkg/os/exec/#LookPath

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

Successfully merging a pull request may close this issue.

2 participants