Skip to content

Commit d6e22e2

Browse files
committed
To help up contributors, script up dev-env bootstrap in a manner that does not require any local dependencies beyond docker and docker-compose
1 parent 2db7436 commit d6e22e2

File tree

2 files changed

+87
-6
lines changed

2 files changed

+87
-6
lines changed

README.md

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,18 @@ Running the project
2424

2525
Project is given with a [PHPDocker.io](http://phpdocker.io) generated environment.
2626

27+
I would recommend you install in your host php cli 7.1+, bower and composer and run the usual steps manually, but it's not necessary - the [`./prepare-dev.sh`](prepare-dev.sh) script will set up the app (bower install, composer install, etc) through docker and docker-compose commands.
28+
2729
* Clone
28-
* Copy `app/config/parameters.yml.dist` into `app/config/parameters.yml`
29-
* `composer install`
30-
* `bower install`
31-
* `php bin/console assets:install --symlink --relative`
32-
* cd into the project folder and run`docker-compose up -d`. More specific information on [phpdocker/README.md](phpdocker/README.md).
33-
* You can then head off to the `/generator` route; you'll need to run `bin/console doctrine:schema:create` within the PHP container (or use the `console` script at the root of the project) to avoid SQL errors on the homepage
30+
* Run [`./prepare-dev.sh`](prepare-dev.sh) - this will:
31+
* populate default dev config
32+
* composer and bower install
33+
* clean up caches
34+
* ensure web assets are available
35+
* load up the database schema (this is just for the CMS side of the website, it has no bearing over the generator)
36+
* start up the environment
37+
* You can then head off to the [/generator](http://localhost:10000/generator) route.
38+
39+
This is an initial fail-safe set up and not always you need to run it, after it's done once you'll just need to do a good old `docker-compose up -d`. More specific information on [phpdocker/README.md](phpdocker/README.md).
3440

3541
**Note:** you'll notice a `console` script at the root of the project. It does some voodoo to run `bin/console` within the container.

prepare-dev.sh

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
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

Comments
 (0)