Auto-deploy from Github, workaround with cronjob and bash

cPanel & WHM Version
11.88.0.12

Marasi

Registered
Jul 11, 2020
2
2
3
Brazil
cPanel Access Level
Reseller Owner
Hi,

I have figured how to implement an auto-deploy from Github.

First we cloned the Github repo into Cpanel dir

Second an Cronjob run a file "deploy.sh" every minute to update /public_html by copying local repo files into public.

It works, but it have some issues...

Deploy.sh code snippet:

Bash:
(cd ${REPO_DIR} && git pull | grep 'Already up to date.') > /dev/null 2>&1
if [[ ${?} == 0 ]]; then

  # Verifica se a pasta de destino já contem uma instalação válida
  if [[ -f ${DEPLOY_DIR}/index.php ]]; then
    output "Up to date"
    exit 0
  fi
fi
I had my Cpanel updated, so the code doesn't work as used to. Now it run and update everything always when cron runs.

I used to use this line to verify when to run and update /public_html

Code:
git pull | grep 'Already up to date.'
And now it is bypassing.

Any ideas?


Thanks!
 
  • Like
Reactions: cesarlopes

cPanelLauren

Product Owner
Staff member
Nov 14, 2017
13,297
1,259
313
Houston
To my knowledge, there is nothing involved with this that would be affected by a cPanel updated. When you say it is bypassing what is the output it gives? What is the output of the following:

Code:
git version
which git
git status
Furthermore, where are you defining REPO_DIR and DEPLOY_DIR variables? What happens when you run a git pull directly from the repo?
 

Marasi

Registered
Jul 11, 2020
2
2
3
Brazil
cPanel Access Level
Reseller Owner
I have found the solution,

The output from:

Code:
git pull | grep 'Already up to date.'
When I run from Bash returns 'Already up to date.'.
But when I run by CRON the output is 'Already up-to-date.'. (See the hyphens).

Wy is that? I have no idea.


So, that's it.

I have change my code to:
Code:
git pull | grep 'Already up[ -]to[ -]date.'
And now it is working like it should.
 
  • Like
Reactions: cPanelLauren