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

werf issue in your automation commit hook #1

Open
shurup opened this issue Jul 10, 2023 · 2 comments
Open

werf issue in your automation commit hook #1

shurup opened this issue Jul 10, 2023 · 2 comments

Comments

@shurup
Copy link

shurup commented Jul 10, 2023

Hi there!

I am from the team behind werf. First of all, I'd like to thank you very much for making this Killercoda tutorial! ❤️ We are really impressed with your effort and its outcome. We are incredibly grateful for the profound and skilful work done here. We also hope a wider DevOps community will benefit from it.

Another reason I reached you is the only small thing in the tutorial that puzzled us a bit. In the last step, you mention the werf/werf#3284 issue as a show-stopper for your post-commit hook automation. However, we have no understanding of why this might happen. Executing werf converge in the Giit hook is no different from typing it in your terminal, where such an issue shouldn't usually happen. Can you please elaborate on it so we can find a fix or a better solution?

@cetceeve
Copy link
Owner

Hey,
thank you so much for the praise and the kind message.😁
Also, thank you for your efforts to write such detailed shoutouts both on GitHub and LinkedIn, we really appreciate it!

Now, regarding the post-commit hook. I have received the following error when I tried to execute werf converge from the post-commit hook both locally and on killercoda.

unable to switch work tree /root/.werf/local_cache/git_worktrees/9/local/07fcf0f5632a9e4cf2b82d40948865ebe819c57bda23149d04e42a2540efbfd4/worktree to commit 657525175c4bedd3b6856a4cf71678e91a8049e1: git checkout command failed: error running command "/usr/lib/git-core/git -c core.autocrlf=false -c gc.auto=0 checkout --force --detach 657525175c4bedd3b6856a4cf71678e91a8049e1"
Bellow I have attached the full error terminal output with more details.

Honestly, I could never really make sense of this error message, but I believed it was related to werf/werf#3284. Now that you mentioned running werf converge from a git hook should be no different to running it from the terminal, it's even more mysterious.

When creating the tutorial both @JonathanArns and I liked the idea of the post-commit hook so much, that we decided to keep it in the tutorial nonetheless. Not at least as inspiration for a GitHub Actions workflow, for example.

More generally, the idea of this last chapter ("Automation") was to demonstrate how you would link your git commits directly to your deployments to really facilitate the GitOps approach. I recon most teams would use a GitHub Actions workflow or similar for this, but I don't really see a neat way to include that in the tutorial. Also, the documentation about integration with ci cd systems does a great job explaining it and already provides example code (linked in the tutorial). Recently, I found the werf converge --follow option which is probably perfectly fine for most people during development (we should include it in the tutorial).

If you have ideas for the last chapter on Automation or the tutorial in general, please let me know and I'll be happy to include them!


Full terminal output from killercoda:

controlplane $ git checkout master
Switched to branch 'master'
controlplane $ echo '#!/bin/bash
> 
> ENVIRONMENT="development"
> 
> # Set environment to production if we are on the master branch
> BRANCH="$(git branch --show-current)"
> if [[ "$BRANCH" == "master" ]]; then
>   ENVIRONMENT="production"
> fi
> 
> # Call werf converge 
> werf converge --repo localhost:5000/demo-app --env "$ENVIRONMENT"
> ' > /root/demo-app/.git/hooks/post-commit
controlplane $ chmod +x /root/demo-app/.git/hooks/post-commit
controlplane $ git add .
controlplane $ git commit -m "test post commit hook"
Version: v1.2.235
Using werf config render file: /tmp/werf-config-render-3595999247

┌ ⛵ image demoapp
└ ⛵ image demoapp (0.01 seconds) FAILED

Running time 0.08 seconds
Error: phase build before image demoapp stages handler failed: unable to create build context archive: unable to get or create archive: error creating archive for commit "657525175c4bedd3b6856a4cf71678e91a8049e1": cannot prepare work tree in cache /root/.werf/local_cache/git_worktrees/9/local/07fcf0f5632a9e4cf2b82d40948865ebe819c57bda23149d04e42a2540efbfd4 for commit 657525175c4bedd3b6856a4cf71678e91a8049e1: unable to switch work tree /root/.werf/local_cache/git_worktrees/9/local/07fcf0f5632a9e4cf2b82d40948865ebe819c57bda23149d04e42a2540efbfd4/worktree to commit 657525175c4bedd3b6856a4cf71678e91a8049e1: git checkout command failed: error running command "/usr/lib/git-core/git -c core.autocrlf=false -c gc.auto=0 checkout --force --detach 657525175c4bedd3b6856a4cf71678e91a8049e1": exit status 128
Stdout:

Stderr:
fatal: Unable to create '/root/.werf/local_cache/git_worktrees/9/local/07fcf0f5632a9e4cf2b82d40948865ebe819c57bda23149d04e42a2540efbfd4/worktree/.git/index.lock': Not a directory
[master 6575251] test post commit hook
 1 file changed, 1 insertion(+), 1 deletion(-)

@alexey-igrychev
Copy link

Hey there!

I really liked your approach with post-commit for simulating CI work. And overall, the guides turned out to be excellent! ❤️

I was able to reproduce the issue, and unfortunately, the current working mechanism doesn't allow executing git hooks with werf because when the hook is executed, the Git directory is locked (.git/index.lock), and werf cannot perform the necessary operations in the service Git worktree.

Please take a look at our configurator, which includes comprehensive instructions for configuring and running werf both locally and in a CI system.

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

3 participants