1

I need to run the script on my server, when calling git push from the local repository to the git gogs repository

#!/bin/sh
git pull origin test

source env/bin/activate
pip install --upgrade pip
pip install -r requirements.txt

python manage.py migrate
python manage.py collectstatic --noinput

sudo systemctl restart gunicorn.service
sudo systemctl restart celery-worker.service
sudo systemctl restart celery-beat.service

Subtracted on the Internet - that you need to use git Hooks. Figured out how to edit hooks.

Question - how can I run a file from a server via SSH from git Hooks ???

ssh user@my.server

This does not work!

I. Simonov
  • 21
  • 2

1 Answers1

0

You should not need ssh, considering the server-side hook will already execute on the (Git Gogs) server.

Make sure to put your script as an executable post-receive file, in one of your Gogs repositories bare repos.

And in that hook, do:

#!/bin/bash
echo "pull from non-bare repo"
unset GIT_DIR
cd /path/to/checkedout/repo
git --work-tree=. --git-dir=.git pull --no-rebase origin test
... rest of your script

Make sure that /path/to/checkedout/repo is a clone of one of your Gogs repo.

VonC
  • 1,042,979
  • 435
  • 3,649
  • 4,283
  • The hook should run when the git push origin test from the local computer to the gogs repository. Then, on the remote server, the data from the same gogs repository should be updated and the migration should start. I think you are talking about if I had to do the migration and execute the script in the gogs repository server – I. Simonov Apr 14 '19 at 20:59
  • @I.Simonov So... a pre-push hook, then: https://stackoverflow.com/a/14672883/6309 – VonC Apr 14 '19 at 21:22