Coder Social home page Coder Social logo

Docker mode not working? about captainhook HOT 9 CLOSED

aruku avatar aruku commented on August 30, 2024
Docker mode not working?

from captainhook.

Comments (9)

sebastianfeldmann avatar sebastianfeldmann commented on August 30, 2024 1

Legacy naming party ;)

from captainhook.

sebastianfeldmann avatar sebastianfeldmann commented on August 30, 2024

What's the error message you get?

Check for example .git/hooks/pre-push if the path the Cap'n generated are correct.

from captainhook.

aruku avatar aruku commented on August 30, 2024

Sorry, I just realized I didn't add that. In the host, where the IDE is, I get the following error:
.git/hooks/pre-commit: 7: bin/captainhook: not found
That is the right path for inside the container.

from captainhook.

sebastianfeldmann avatar sebastianfeldmann commented on August 30, 2024

So, make sure your hook scripts contain the actual docker command.

cat .git/hooks/pre-push

should look like this

#!/bin/sh

# installed by CaptainHook 5.22.1

# read original hook stdIn to pass it in as --input option
input=$(cat)

if sh -c ": >/dev/tty" >/dev/null 2>/dev/null; then
        exec < /dev/tty
fi

docker exec -i my-container-name ./bin/captainhook --bootstrap=vendor/autoload.php --input="$input" hook:pre-push "$@"

If your hook scripts do not actually contain the docker command, its because your configuration is broken.
Try to configure the run settings like this.

{
    "config": {
        "verbosity": "verbose",
        "ansi-colors": true,
        "includes": [],
        "run-mode": "docker",
        "run-exec": "docker exec my-container-name",
        "run-cmd": "bin/captainhook",
        "bootstrap": "vendor/autoload.php"
    },
    ...
}

from captainhook.

aruku avatar aruku commented on August 30, 2024

I was using 5.21.2, which by default wouldn't overwrite the hooks, so I wasn't seeing the proper changes if I didn't uninstall the hooks beforehand. 🤦
The problem now is that if composer install is ran in the container, as our bootstrapping does, the hooks are configured without the Docker command and won't work in the host. Can hook-installer deal with this use case too somehow?

from captainhook.

sebastianfeldmann avatar sebastianfeldmann commented on August 30, 2024

If you want to execute the same hooks from outside and inside the container sadly not.

It is important that the configuration you use to install must have the correct run-mode configuration otherwise the default version will be installed, and that is not what you want.

from captainhook.

aruku avatar aruku commented on August 30, 2024

I can live without being able to commit directly in the container, but the real problem will be CI: the pipeline doesn't use our containers.
If you or anybody else has any suggestions about what to do in this scenario, I'd appreciate it.

EDIT: Maybe read an environment variable during installation to tell it what config to use?
That way, the CI pipeline could use one value and my computer a different one?

PD: what is the shell mode? It still uses PHP, right?

from captainhook.

sebastianfeldmann avatar sebastianfeldmann commented on August 30, 2024

There are multiple ways to make sure you do not execute hooks in CI

  • Do not install the hooks
  • Set environment variables like CI or CAPTAINHOOK_SKIP_HOOKS to 1

The shell mode writes shell scripts to you hook directory. This shell script calls the PHP directly.
The docker mode writes similar shell scripts, the difference being that docker is called instead of PHP.

from captainhook.

aruku avatar aruku commented on August 30, 2024

Ahhh, good. I found another env variable this morning but not that one. Are all of them listed somewhere? I can't find them.

One last question: what is the difference between the shell and local modes? They seem to output the same hook.

Thank you for all your help!

from captainhook.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.