|
| 1 | +#!/usr/bin/env bash |
| 2 | +set -e |
| 3 | + |
| 4 | +# |
| 5 | +# This script will bootstrap the application for local development use. All the mucking about below around |
| 6 | +# permissions and file ownerships are due to the fact we're running composer, bower etc through docker to avoid |
| 7 | +# requiring from the contributors any dependencies (beyond docker and docker-compose) to be installed on their |
| 8 | +# host system. |
| 9 | +# |
| 10 | + |
| 11 | +bold=$(tput bold) |
| 12 | +normal=$(tput sgr0) |
| 13 | +FIX_OWNERSHIP="sudo chown `id -u`:`id -g` . -Rf" |
| 14 | +PHP_IN_CONTAINER="docker-compose exec php-fpm php " |
| 15 | + |
| 16 | +echo -e "\n${bold} ## Preparing phpdocker.io for local dev ## \n${normal}" |
| 17 | +echo -e "\n In order to fix up symfony cache permissions for both container and host, we'll need to sudo a few commands.\n" |
| 18 | + |
| 19 | +PARAMETERS='app/config/parameters.yml' |
| 20 | +if [[ ! -f ${PARAMETERS} ]]; then |
| 21 | + echo -e "${bold}parameters.yml file not found, creating...${normal}\n" |
| 22 | + cp ${PARAMETERS}.dist ${PARAMETERS} |
| 23 | +else |
| 24 | + echo -e "${bold}parameters.yml file present, leaving alone.${normal}\n" |
| 25 | +fi |
| 26 | + |
| 27 | +# Cleanup |
| 28 | +${FIX_OWNERSHIP} |
| 29 | + |
| 30 | +sudo rm -Rf web/bundles web/css web/js |
| 31 | +sudo rm -Rf var/* -Rf |
| 32 | +rm src/AppBundle/Resources/public/vendor/* -Rf |
| 33 | + |
| 34 | +# Install static assets through bower |
| 35 | +if hash bower 2>/dev/null; then |
| 36 | + bower install |
| 37 | +else |
| 38 | + echo -e "\n${bold}Bower not found, running through docker run (much slower)...${normal}\n" |
| 39 | + |
| 40 | + docker run \ |
| 41 | + --rm \ |
| 42 | + -it \ |
| 43 | + -v "`pwd`:/workdir" \ |
| 44 | + -w /workdir \ |
| 45 | + node:alpine \ |
| 46 | + sh -c "apk update; apk add git; npm i -g bower; bower install --allow-root" |
| 47 | + |
| 48 | + ${FIX_OWNERSHIP} |
| 49 | +fi |
| 50 | + |
| 51 | +# Start up environment and run symfony console within container to ensure DB has the schema loaded up |
| 52 | +docker-compose up -d |
| 53 | + |
| 54 | +# Install composer deps |
| 55 | +composer -o install |
| 56 | + |
| 57 | +# Install assets |
| 58 | +mkdir -p web/bundles web/css web/js |
| 59 | +${PHP_IN_CONTAINER} bin/console assets:install --symlink --relative |
| 60 | + |
| 61 | +# Recreate dev cache |
| 62 | +${PHP_IN_CONTAINER} bin/console cache:warmup |
| 63 | + |
| 64 | +# Load up DB schema |
| 65 | +${PHP_IN_CONTAINER} bin/console doctrine:schema:update --force |
| 66 | + |
| 67 | +# Ensure both container and host can write into the var/ folder |
| 68 | +${FIX_OWNERSHIP} |
| 69 | +sudo chmod 777 var/* -Rf |
| 70 | + |
| 71 | + |
| 72 | + |
| 73 | +# Done! |
| 74 | +echo -e "\n${bold} ## Application is now set up ${normal} for localdev, and the environment is up; head off to ${bold}>>> http://localhost:10000 <<< ## \n${normal}" |
| 75 | + |
0 commit comments