|
1 | 1 | # Drupal Dockerizer |
2 | 2 |
|
3 | | -Dockerized Drupal. |
| 3 | +## Requirements |
| 4 | + |
| 5 | +- Python >= 3.5 |
| 6 | +- Docker |
| 7 | +- Docker Compose |
| 8 | +- Ansible >= 2.8 |
| 9 | +- Git |
| 10 | + |
| 11 | +## Quickstart |
| 12 | + |
| 13 | +### Prepare project structure |
| 14 | + |
| 15 | +- `db`: create this directory and download database dump here if exists. |
| 16 | +- `code`: clone your project files into this directory. |
| 17 | +- `drupal-dockerizer`: clone drupal-dockerizer project in this directory. |
| 18 | +- `files`: create the directory and pull Drupal assets here |
| 19 | + |
| 20 | +### Prepare your config for Drupal Dockerizer |
| 21 | + |
| 22 | +```bash |
| 23 | +cd drupal-dockerizer |
| 24 | +cp default.config.yml config.yml |
| 25 | +``` |
| 26 | + |
| 27 | +### Start new local environment |
| 28 | + |
| 29 | +```bash |
| 30 | +cd drupal-dockerizer |
| 31 | +sudo ansible-playbook -vvv main.yml --connection=local --extra-vars=init_project=true |
| 32 | +``` |
| 33 | + |
| 34 | +### Start local environment for existing project |
| 35 | + |
| 36 | +```bash |
| 37 | +cd drupal-dockerizer |
| 38 | +sudo ansible-playbook -vvv main.yml --connection=local |
| 39 | +sudo ansible-playbook -vvv run-drush-commands.yml --connection=local |
| 40 | +``` |
| 41 | + |
| 42 | +### Import database from dump |
| 43 | + |
| 44 | +```bash |
| 45 | +cd drupal-dockerizer |
| 46 | +sudo ansible-playbook -vvv db.yml --connection=local |
| 47 | +``` |
| 48 | + |
| 49 | +### Xdebug setup |
| 50 | + |
| 51 | +For advanced network setup set in `config.yml` variable `xdebug_enviroment` like this |
| 52 | + |
| 53 | +```bash |
| 54 | +remote_enable=1 remote_connect_back=1 remote_port=9008 remote_host=192.168.{network_id}.1 show_error_trace=0 show_local_vars=1 remote_autostart=1 show_exception_trace=0 idekey=VSCODE |
| 55 | +``` |
| 56 | + |
| 57 | +For work Xdebug with advanced networking in vscode add to your launcher.json file in project next lines: |
| 58 | + |
| 59 | +```json |
| 60 | + { |
| 61 | + "name": "XDebug Docker", |
| 62 | + "type": "php", |
| 63 | + "request": "launch", |
| 64 | + "hostname" : "192.168.{network_id}.1", |
| 65 | + "port": 9008, |
| 66 | + "pathMappings": { |
| 67 | + "/var/www": "${workspaceRoot}/<path_to_drupal_project>" |
| 68 | + }, |
| 69 | + "xdebugSettings": { |
| 70 | + "show_hidden": 1, |
| 71 | + "max_data": -1, |
| 72 | + "max_depth": 2, |
| 73 | + "max_children": 100, |
| 74 | + } |
| 75 | + }, |
| 76 | +``` |
| 77 | + |
| 78 | +#### For MacOs the next config should be used |
| 79 | + |
| 80 | +Make sure your `config.yml` contains the next config: |
| 81 | + |
| 82 | +```bash |
| 83 | +# Enviroment variable for php xdebug extensions |
| 84 | +xdebug_enviroment: remote_enable=1 remote_connect_back=0 remote_port=9000 remote_host=10.254.254.254 show_error_trace=0 show_local_vars=1 remote_autostart=1 show_exception_trace=0 idekey=VSCODE |
| 85 | +``` |
| 86 | + |
| 87 | +Make sure you've created Host address alias on MacOS: |
| 88 | + |
| 89 | +```bash |
| 90 | +sudo ifconfig lo0 alias 10.254.254.254 |
| 91 | +``` |
| 92 | + |
| 93 | +Your `launch.json` should look like the next config: |
| 94 | + |
| 95 | +```json |
| 96 | + { |
| 97 | + "name": "XDebug Docker", |
| 98 | + "type": "php", |
| 99 | + "request": "launch", |
| 100 | + "port": 9000, |
| 101 | + "pathMappings": { |
| 102 | + "/var/www": "${workspaceRoot}/<path_to_drupal_project>" |
| 103 | + }, |
| 104 | + "xdebugSettings": { |
| 105 | + "show_hidden": 1, |
| 106 | + "max_data": -1, |
| 107 | + "max_depth": 2, |
| 108 | + "max_children": 100, |
| 109 | + } |
| 110 | + |
| 111 | +``` |
| 112 | + |
| 113 | +How to use debugger with Drush commands? |
| 114 | + |
| 115 | +1. Get the name of web server container using command: `docker ps | grep webserver` |
| 116 | +2. SSH into the container by name. Example: `docker exec -it yourproject-php72-develop bash` |
| 117 | +3. Set your breakpoint and run Drush command as usual |
| 118 | + |
| 119 | +### Advanced Networking |
| 120 | + |
| 121 | +You can use an advanced docker network to be able to conveniently host multiple Drupal projects on one computer. |
| 122 | + |
| 123 | +Set in config.yml `advanced_networking: true`. |
| 124 | + |
| 125 | +You can change the ip address of the project using the variable `network_id` in `config.yml` file |
| 126 | + |
| 127 | +You can change doamin name by variable `domain_name` in `config.yml` file |
| 128 | + |
| 129 | +#### Advanced Networking Limitation |
| 130 | + |
| 131 | +The advanced network only works on a machine with a Linux distribution. |
| 132 | + |
| 133 | +#### Advanced Networking project structure |
| 134 | + |
| 135 | +- `Adminer` placed on domain name and on 8080 port. |
| 136 | +- Solr 4 placed on domain name and on 8983 port and /solr path. `http://drupal.devel:8983/solr` for examle. |
| 137 | +- Data Base placed on 192.168.<<network_id>>.13 and on 3306 port. You can connect to DB by vscode [extension](https://marketplace.visualstudio.com/items?itemName=formulahendry.vscode-mysql) or from `Adminer` |
| 138 | + |
| 139 | +### Drush usage |
| 140 | + |
| 141 | +Run in terminal: `docker exec my-project-php74 drush <drush-command>` for run drush command. |
| 142 | +If you change compose project name or php version in config replace `my-project-php74` to `<compose_project_name>-<phpversion>`. |
| 143 | + |
| 144 | +Use the next command in order to ran multiple Drush commands. |
| 145 | + |
| 146 | +```bash |
| 147 | +sudo ansible-playbook -vvv run-drush-commands.yml --connection=local |
| 148 | +```` |
| 149 | + |
| 150 | +Change `drush_commands` variable in your `config.yml` file like this: |
| 151 | + |
| 152 | +```yaml |
| 153 | +drush_commands: |
| 154 | + - 'updb' |
| 155 | + - '-v sapi-r' |
| 156 | + - '-v sapi-i' |
| 157 | + - ... |
| 158 | +``` |
| 159 | + |
| 160 | +## FAQ |
| 161 | + |
| 162 | +### How to reset everything and start from scratch? |
| 163 | + |
| 164 | +```bash |
| 165 | +cd <project>/docker |
| 166 | +sudo ansible-playbook -vvv reset.yml --connection=local |
| 167 | +``` |
| 168 | + |
| 169 | +### How to clear Docker cache? |
| 170 | + |
| 171 | +```bash |
| 172 | +docker system prune -a |
| 173 | +``` |
| 174 | + |
| 175 | +### How to enhance MacOS performance? |
| 176 | + |
| 177 | +- make sure your `config.yml` contains `docker_cached_volume: true` |
| 178 | +- make sure you add more resources to Docker via Preferences -> Recources |
| 179 | +- make sure you set `debug` to `false` in Docker Engine preferences |
0 commit comments