Deploy a Symfony website with Git on OVH shared server

1.1k views Asked by At

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 [email protected]: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 ?

1

There are 1 answers

0
Melody On BEST ANSWER

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!)