OblikStudio / kirby-git

Kirby plugin for updating content in the panel via Git
MIT License
84 stars 6 forks source link

How can I use kirby-git in bare repositories on a live server? #35

Closed samyouel closed 1 year ago

samyouel commented 1 year ago

Hey!

I've setup Kirby Git in my Project. Now my Deployment Platform only allows me, to have the repo on the server as core.bare = true. That way, the .git folder is in a different path, not accessible from the served path for the files available on public. Makes sense obviously.

Now sadly, this way, the Kirby-Git Plugin doesn't seem to work, is there a workaround or a better solution to get this up and running?

I always get this error when I try to implement the status pane: fatal: this operation must be run in a work tree.

Additionally, I get this Error, when I open the "Git" Tab in the Panel: fatal: ambiguous argument 'origin/live..live': unknown revision or path not in the working tree. Use '--' to separate paths from revisions, like this: 'git <command> [<revision>...] -- [<file>...]'

Anything I can do? That would be amazing! Thanks for your work.

Sam

hdodov commented 1 year ago

I believe it doesn't make sense to use this plugin at all.

A bare git repository means that this repository does not actually manage files on the operating system. It can be used for merely pushing commits to it from one machine and pulling them on another, for example.

The goal of this plugin is to help you manage changes you make on your website. Without a git work tree, there is no website and no changes to manage.

What development platform are you using and what are you trying to accomplish more concretely?

samyouel commented 1 year ago

I'm hosting my repo with a Plesk Panel. Plesk offers a Git extension which is able to pull a remote repo and then it initialises it as a bare repo, outsourcing the .git folder to another location on the server than the publicly available root folder.

The cool thing with that is obviously, that I can make use of the auto-deploy features of the plugin, whenever there is a push to the repo, the page gets updated.

But now I'm still not able to actually make proper use of the panel in Kirby, since changes on live are obviously not reflected in a dev environment, which leads to merge conflicts or files being overwritten. That is why I thought, your plugin could be the solution for my use case?

hdodov commented 1 year ago

I think the problem is that Plesk offers this Git extension as a one-way solution for deployment. In other words, you can make changes to Git and Plesk will deploy them to the live server, but it can't retrieve changes from the server and upload them to Git.

It appears that the intention of Plesk is to have the server be read-only, i.e. you make your changes in Git and it deploys them, not vice versa. Hence, it clones the site as a bare repo, because a bare repo is not meant to have a mutable work tree. That's how I understood it, at least.


But do you need Plesk at all? Couldn't you just SSH into your server, clone your repo as a non-bare repo, and use the Git plugin as usual? That setup would be a one-time thing. From then on, you just push/pull changes via Kirby's admin panel.

samyouel commented 1 year ago

Yes, that's true. The Git Extension from Plesk is probably not really compatible with that setup.

What was important for me, was that the .git folder was not publicly accessible from the public directory on the server. I've achieved that now by cloning the repo on the server and setting the worktree path of the git repo to the public folder in the config file by adding the worktree config. core.worktree = ...

The only issue now still is, that I have to login to the panel and pull the new changes from the 'main' branch, when I want to do a deploy. That can be quite frustrating, the auto-deploy options of Plesk were quite handy when it comes to that. Is there something similar possible in Kirby Git?

Thanks so much!

hdodov commented 1 year ago

I guess you could create a cron job on the live server that periodically pulls in the changes.

Alternatively, you could add your server as a remote locally and push directly to it. Something like this:

git remote add live-server http://123.4.567.890

Then, you'd be able to push to your server like so:

git push live-server master

This way, you don't have to push to e.g. GitHub, and then from GitHub to your server — you push directly to your server.

Having to pull in changes manually can be annoying indeed, but it's simple and just works, so that's why we're doing it this way in our projects.

samyouel commented 1 year ago

Thanks so much for your input! In case someone else has the same issue, I've done it this way now.

while read oldrev newrev refname do

Get the name of the branch that was pushed

branch=$(git rev-parse --symbolic --abbrev-ref $refname)

If the branch that was pushed is not the currently checked-out branch

if [ "$branch" != "$(git rev-parse --symbolic --abbrev-ref HEAD)" ] && [ "$branch" = "main" ]; then

Update the checked-out branch to the latest commit

git merge $branch --ff-only
git push origin live
    # in my case I use that to sync to another Bitbucket repo as a backup remote
# git push origin main

fi done



- I'm still free to make changes live and commit them with the Git Plugin, but I don't have to login to the panel anymore to get new dev changes from the local repo to live.

Thanks!