Skip to content

Instantly share code, notes, and snippets.

@sadiqsalau
Last active May 7, 2024 09:10
Show Gist options
  • Save sadiqsalau/f78abc8770f2d4b518839c0c6fb73663 to your computer and use it in GitHub Desktop.
Save sadiqsalau/f78abc8770f2d4b518839c0c6fb73663 to your computer and use it in GitHub Desktop.
Laravel Cpanel Deploy
---
deployment:
tasks:
# If .deploy.conf doesn't exist, create it from .deploy.example.conf
- |
if [ ! -f .deploy.conf ]
then
cp .deploy.example.conf .deploy.conf
exit
else
source .deploy.conf
fi
# Set variables
- export DEPLOY_LOG="$DEPLOY_PATH/.deploy.log"
- export DEPLOY_LIST="$DEPLOY_PATH/.deployed-files.txt"
# Create deployment path if it doesn't exist
- if [ ! -d "$DEPLOY_PATH" ]; then mkdir -p "$DEPLOY_PATH"; fi
# Start deployment
- echo "=== Deployment started" > "$DEPLOY_LOG"
# Remove old files and empty directories
- |
if [ -f "$DEPLOY_LIST" ]
then
echo "=== Removing old files" >> "$DEPLOY_LOG"
tac "$DEPLOY_LIST" | while read file; do
if [ -d "$DEPLOY_PATH/$file" ] && [ ! "$(ls -A "$DEPLOY_PATH/$file")" ]
then
echo "Removing empty directory: $file" >> "$DEPLOY_LOG"
rmdir "$DEPLOY_PATH/$file"
elif [ -f "$DEPLOY_PATH/$file" ]
then
echo "Removing file: $file" >> "$DEPLOY_LOG"
rm "$DEPLOY_PATH/$file"
fi
done
fi
# Copy new files
- |
echo "=== Copying new files" >> "$DEPLOY_LOG"
find -mindepth 1 \
! -path "*/.git*" \
! -name ".cpanel.yml" \
! -name ".deploy.conf" \
! -name ".deploy.example.conf" \
-exec echo "{}" >> "$DEPLOY_LOG" \;\
-exec cp -RTpu "{}" "$DEPLOY_PATH/{}" \;\
-fprint "$DEPLOY_LIST""
# Switch working directory
- cd $DEPLOY_PATH
# Setup composer
- php -v &>> "$DEPLOY_LOG"
- if [ ! -f composer.phar ]; then wget -O - https://getcomposer.org/installer | php &>> "$DEPLOY_LOG"; fi
- php composer.phar install --no-interaction --ignore-platform-reqs --no-dev &>> "$DEPLOY_LOG"
# Link storage
- php artisan storage:link &>> "$DEPLOY_LOG"
# Setup dotenv and run migrations
- |
if [ ! -f .env ]
then
cp .env.example .env
php artisan key:generate &>> "$DEPLOY_LOG"
else
if [[ "$RUN_MIGRATIONS" == "true" ]]; then php artisan migrate &>> "$DEPLOY_LOG"; fi
fi
export DEPLOY_PATH=~/public_html
export RUN_MIGRATIONS=false
# Cpanel deploy
.deploy.conf
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment