CI/CD (git hooks)
Reference: github.com/noelboss/3fe13927025b89757f8fb12e9066f2fa
Add a bare repository on the production server
bare means no .git directory
git init --bare ~/project_name.git
Setup initial post-receive hook
touch ~/project_name.git/git_hooks/post-receive
chmod +x ~/project_name.git/git_hooks/post-receive
#!/bin/bash
MAGENTO_DIR="<path_to_openmage_dir>" #no explanation
GIT_DIR="~/project_name.git" #bare repo path we created
BRANCH="master" #this is the branch that should be allowed to be pushed to production
while read oldrev newrev ref; do
# only checking out the master (or whatever branch you would like to deploy)
if [ "$ref" = "refs/heads/$BRANCH" ]; then
##################
## maintenance ON
cd "${MAGENTO_DIR}"
n98-magerun sys:maintenance --on
##################
## git copy
echo "Deploying master branch to production..."
git --work-tree=$MAGENTO_DIR --git-dir=$GIT_DIR checkout -f master
echo "Running update"
test -e $MAGENTO_DIR/actions/update.sh && /bin/bash $MAGENTO_DIR/actions/update.sh
##################
## maintenance OFF
cd "${MAGENTO_DIR}"
n98-magerun sys:maintenance --off
echo "UPDATE COMPLETE!!"
cp -a $MAGENTO_DIR/git_hooks/. $GIT_DIR/hooks/
chmod +x $GIT_DIR/hooks/post-receive
else
echo "Ref $ref received. Doing nothing: only the ${BRANCH} branch may be deployed on this server."
fi
done
Add remote repo
#on project's root (local)
git remote add production <ssh_host_or_user@password>:<path_to_git_bare_repo>
You can push with:
git push production master