Last active
December 2, 2019 14:00
-
-
Save evaisse/345fdd06889f3b22ffc2eec35f36081f to your computer and use it in GitHub Desktop.
OVH create site & deploy via GIT
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# Simple script create a site associated with a | |
if [ -z "$1" ] | |
then | |
echo "No argument supplied, you should do 'create-site.sh my.foo.com" | |
exit 1 | |
fi | |
SITENAME=$1 | |
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" | |
SITE="$DIR/$SITENAME" | |
mkdir -p $SITE/{git,var} | |
cd $SITE/git | |
git init --bare | |
cd $SITE/git/hooks | |
ln -s $DIR/git-hooks/post-receive | |
# instruction | |
echo "you can now clone the bare/empty repo : " | |
echo | |
echo " git clone 'username@ftp.clusterXXX.hosting.ovh.net:$SITENAME/git' '$SITENAME'" | |
echo | |
echo 'or add remote : ' | |
echo | |
echo " git remote add origin 'username@ftp.clusterXXX.hosting.ovh.net:$SITENAME/git'" | |
echo |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -eu | |
# Hook post-receive | |
# @see https://docs.ovh.com/fr/hosting/24-days/day07/ | |
# | |
# @see https://medium.com/@stadja/comment-déployer-sur-un-serveur-distant-en-une-commande-git-pas-à-pas-bdcf5aaf172d | |
# Force source bash profile to update PATH | |
# source ~/.bash_profile | |
# source ~/.bashrc | |
DIR=$(pwd) | |
GIT_REPO="$DIR" | |
RELEASES_DIR=$(realpath "$DIR/..") | |
echo | |
echo "deploying in $RELEASES_DIR" | |
echo | |
PHP=/usr/local/php7.2/bin/php | |
echo | |
echo "using $PHP" | |
echo | |
# Go to deploy directory to load ovhconfig | |
# cd $RELEASES_DIR | |
# ovhConfig | |
mkdir -p $RELEASES_DIR/var | |
while read prevsha1 newsha1 ref | |
do | |
COMMIT="$newsha1" | |
if [[ $ref =~ .*/master$ ]]; | |
then | |
BRANCH="master" | |
elif [[ $ref =~ .*/staging$ ]]; | |
then | |
BRANCH="staging" | |
else | |
echo "no branch to deploy in $ref" | |
fi | |
done | |
if [ -z "$BRANCH" ]; | |
then | |
echo "nothing to do on this branch" | |
exit | |
fi | |
echo | |
echo "deploy using branch $BRANCH on commit $COMMIT" | |
mkdir -p "$RELEASES_DIR/$BRANCH" | |
CHECKOUT_PATH="$RELEASES_DIR/$BRANCH" | |
git --work-tree="$CHECKOUT_PATH" --git-dir=$GIT_REPO checkout -f $BRANCH | |
echo "$BRANCH $COMMIT" > $CHECKOUT_PATH/LAST_COMMIT | |
cd $CHECKOUT_PATH | |
echo "move into $CHECKOUT_PATH and build" | |
if [ -f "composer.json" ]; then | |
INSTALL_CMD="$PHP ./../../composer.phar install -d $CHECKOUT_PATH --no-dev --optimize-autoloader" | |
echo | |
echo $INSTALL_CMD | |
echo | |
ERRORCODE=`$INSTALL_CMD` | |
fi | |
echo | |
echo "deployed." | |
exit | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment