Skip to content

Instantly share code, notes, and snippets.

@sadiqsalau
Last active April 26, 2023 04:43
Show Gist options
  • Save sadiqsalau/c1b0f0e4b15e40274b64854c6c557e24 to your computer and use it in GitHub Desktop.
Save sadiqsalau/c1b0f0e4b15e40274b64854c6c557e24 to your computer and use it in GitHub Desktop.
React Cpanel Deploy script
---
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"
export DEPLOY_PATH=~/public_html
# Cpanel deploy
.deploy.conf
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment