3

I want to configure an automatic deployment of my Symfony website directly from git to my ovh server (Performance offer - with SSH access).

I followed these ovh instructions : https://docs.ovh.com/fr/fr/web/hosting/24-days/day07/

  1. installed composer in $HOME/bin
  2. created a distant git repository $HOME/depot_git_beta with git init --bare
  3. created a post-receive file at $HOME/depot_git_beta/hooks

    #!/bin/bash
    
    # Hook post-receive
    
    # Force source bash profile to update PATH
    source ~/.bash_profile
    source ~/.bashrc
    
    GIT_REPO=$HOME/depot_git_beta
    DEPLOY_DIR=$HOME/beta
    
    # Go to deploy directory to load ovhconfig
    cd $DEPLOY_DIR
    ovhConfig
    cd -
    
    while read prevsha1 newsha1 ref
    do
        if [[ $ref =~ .*/develop$ ]];
        then
            echo "Deploying develop branch to beta..."
            git --work-tree=$DEPLOY_DIR --git-dir=$GIT_REPO checkout -f
            cd $DEPLOY_DIR
    
            # Install vendors
            composer install --no-dev --no-interaction
            echo "Vendors updated!"
    
            # Update database
            php bin/console doctrine:schema:update --force
            echo "Database for beta environment updated!"
    
            # Clear cache
            php bin/console cache:clear --env=dev
            php bin/console cache:clear --env=prod
            echo "Cache cleared!"
    
        else
            echo "Ref: $ref isn't develop. Nothing to do on beta"
        fi
    done
    
  4. add the distant repository

    git remote add ovh VOTRE_IDENTIFIANT@ftp.clusterXXX.hosting.ovh.net:depot_git_beta
    
  5. but when I do git push ovh develop it does seems to work, git bash tells it's up to date, but nothing seems to have happened in ovh server.

Any idea what went wrong or where I should look first ?

Melody
  • 74
  • 10
  • 1
    If git tells its up to date, then any server side hooks won't be executed, can you add a new commit, and push that? Any output of your git hook should show up at the client side when you push – Ferrybig Aug 31 '17 at 07:29
  • Use `git commit --allow-empty -m 'push to execute post-receive'` to trigger the post-receive hook. See https://stackoverflow.com/a/28703197/6162120 – piarston Aug 31 '17 at 08:33
  • Thank you for helping me. Nothing is working unfortunately. To be clear, here is what I did : 1/ tap in git bash : `$ git push ovh develop` and it executed this: `Counting objects: 15254, done. Delta compression using up to 4 threads. Compressing objects: 100% (11927/11927), done. Writing objects: 100% (15254/15254), 66.97 MiB | 631.00 KiB/s, done. Total 15254 (delta 6552), reused 10256 (delta 2703) To ftp.clusterXXX.hosting.ovh.net:depot_git_beta * [new branch] develop -> develop` – Melody Aug 31 '17 at 09:01
  • And 2/ I did the `git commit --allow-empty -m 'push to execute post-receive'` and nothing is happening, not even the folder is created – Melody Aug 31 '17 at 09:04
  • Are you sure that `$HOME/depot_git_beta/hooks/post-receive` is executable? – piarston Aug 31 '17 at 09:12
  • yes : -rwxr-xr-x+ – Melody Aug 31 '17 at 09:16
  • Replace the first line by `#!/bin/bash -x` to turn on echo. And make sure the directory DEPLOY_DIR exists on the server – piarston Aug 31 '17 at 09:36
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/153341/discussion-between-piarston-and-melody). – piarston Aug 31 '17 at 09:39

1 Answers1

1

The problem was essentially that as I was not deploying the master branch, I had to precise it in this line:

$ git --work-tree=... --git-dir=... checkout -f develop

See this very helpful answer!

(And thank you piarson for helping me to find the solution!)

Melody
  • 74
  • 10