Created
September 19, 2025 17:28
-
-
Save viccherubini/b5159929a21701702434099058208d3b to your computer and use it in GitHub Desktop.
Build script for Symfony project
This file contains hidden or 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
#!/bin/bash | |
DBDUMP=${1:-$1} | |
DBHOST="localhost" | |
DBUSER="database_user" | |
DBNAME="database_name" | |
DBADMIN="$USER" | |
function main { | |
# Delete cached files | |
rm -rf ./var/cache/* | |
rm -rf ./var/tailwind/* | |
drop_database $DBHOST $DBADMIN $DBNAME | |
drop_database $DBHOST $DBADMIN "${DBNAME}_test" | |
echo | |
create_database_user $DBHOST $DBADMIN $DBUSER | |
echo | |
create_database $DBHOST $DBADMIN $DBUSER $DBNAME | |
create_database $DBHOST $DBADMIN $DBUSER "${DBNAME}_test" | |
echo | |
install_vendors | |
echo | |
if test -f "$DBDUMP"; then | |
import_database $DBDUMP $DBHOST $DBUSER $DBNAME | |
echo | |
fi | |
migrate_database $DBNAME "dev" | |
migrate_database "${DBNAME}_test" "test" | |
echo | |
if [ ! -f "$DBDUMP" ]; then | |
load_fixtures $DBNAME "dev" | |
echo | |
fi | |
warmup_cache "dev" | |
warmup_cache "test" | |
echo | |
build_assets "dev" | |
# Delete log files | |
rm -rf ./var/log/* | |
} | |
function print_command_action { | |
echo "[${FUNCNAME[1]}] $1" | |
} | |
function print_command_error { | |
if [[ ("$?" != "0") && (-n "$1") ]]; then | |
echo "[${FUNCNAME[1]}] $1" | |
fi | |
} | |
function run_command { | |
echo -n "[${FUNCNAME[1]}] $1 ... " | |
eval "$2" &> /dev/null | |
if [ "$?" != 0 ]; then | |
echo "FAILURE" | |
echo "$2" | |
exit 1 | |
fi | |
echo "SUCCESS" | |
} | |
function drop_database { | |
run_command "Dropping '$3' database" "dropdb --if-exists --host='$1' --username='$2' '$3'" | |
} | |
function create_database_user { | |
run_command "Dropping '$3' database user" "dropuser --if-exists --host='$1' --username='$2' '$3'" | |
run_command "Creating '$3' database user" "createuser --host='$1' --username='$2' --createdb --createrole --inherit --login --superuser --no-password '$3'" | |
} | |
function create_database { | |
run_command "Creating '$3' database" "createdb --host='$1' --username='$3' --encoding='UTF-8' --owner='$3' '$4'" | |
} | |
function install_vendors { | |
run_command "Installing JavaScript vendors" "npm install --no-save --no-audit --no-fund" | |
run_command "Installing PHP vendors" "composer install --no-ansi --no-interaction --no-progress --no-scripts" | |
} | |
function import_database { | |
run_command "Importing '$1' to '$4'" "psql --host='$2' --username='$3' '$4' < '$1'" | |
} | |
function migrate_database { | |
run_command "Migrating '$1' database" "php ./vendor/bin/phinx migrate --silent --no-interaction --environment='$2'" | |
} | |
function load_fixtures { | |
run_command "Loading '$1' fixtures" "php ./bin/console doctrine:fixtures:load --no-interaction --env='$2'" | |
} | |
function warmup_cache { | |
run_command "Clearing '$1' cache" "php ./bin/console cache:clear --no-interaction --env='$1'" | |
run_command "Warming '$1' cache" "php ./bin/console cache:warmup --no-interaction --env='$1'" | |
} | |
function build_assets { | |
run_command "Building '$1' assets" "php ./bin/console tailwind:build --no-interaction --env='$1' && php ./bin/console assets:install public --no-interaction --env='$1'" | |
} | |
main |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment