Last active
April 26, 2023 04:45
-
-
Save sadiqsalau/e1b8c416503c40769c0ecd10cdd1f345 to your computer and use it in GitHub Desktop.
Laravel API 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 paths if it doesn't exist | |
- if [ ! -d "$DEPLOY_PATH" ]; then mkdir -p "$DEPLOY_PATH"; fi | |
- if [ ! -d "$(dirname $PUBLIC_PATH)" ]; then mkdir -p "$(dirname $PUBLIC_PATH)"; fi | |
- if [ ! -d "$(dirname $STORAGE_PATH)" ]; then mkdir -p "$(dirname $STORAGE_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" | |
# Link directories | |
- ln -fsn "$DEPLOY_PATH/public" $PUBLIC_PATH | |
- ln -fsn "$DEPLOY_PATH/storage/app/public" $STORAGE_PATH | |
# 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" | |
# 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 |
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=~/websites/example.com/api | |
export PUBLIC_PATH=~/public_html/api | |
export STORAGE_PATH=~/public_html/storage | |
export RUN_MIGRATIONS=false |
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