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