Skip to content

Commit 82d0617

Browse files
authored
Merge pull request #10 from jet-dev-team/develop
Initial open release!
2 parents b5de0f4 + 2cf0efe commit 82d0617

23 files changed

Lines changed: 2704 additions & 1 deletion

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
config.yml

README.md

Lines changed: 177 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,179 @@
11
# Drupal Dockerizer
22

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

ansible.cfg

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
[defaults]
2+
roles_path = ./roles
3+
nocows = 1
4+
retry_files_enabled = False
5+
inventory = inventory
6+
7+
[ssh_connection]
8+
pipelining = True
9+
control_path = /tmp/ansible-ssh-%%h-%%p-%%r

db.yml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
---
2+
3+
- hosts: server
4+
become: yes
5+
6+
vars_files:
7+
- default.config.yml
8+
9+
pre_tasks:
10+
- name: Include config override file, if it exists.
11+
include_vars: "{{ item }}"
12+
with_fileglob:
13+
- config.yml
14+
15+
roles: []
16+
17+
tasks:
18+
19+
- name: Remove database.
20+
ignore_errors: yes
21+
when: database == "mysql"
22+
shell: |
23+
docker exec -i {{ compose_project_name }}-database sh -c 'exec mysql -uroot -p{{ mysql_root_password }} -e "DROP DATABASE {{ mysql_database }}"'
24+
25+
- name: Create new database.
26+
when: database == "mysql"
27+
shell: |
28+
docker exec -i {{ compose_project_name }}-database sh -c 'exec mysql -uroot -p{{ mysql_root_password }} -e "CREATE DATABASE {{ mysql_database }} CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci"'
29+
30+
- name: Import database.
31+
when: database == "mysql"
32+
shell: |
33+
docker exec -i {{ compose_project_name }}-database sh -c 'exec mysql -uroot -p{{ mysql_root_password }} {{ mysql_database }}' < {{ db_dump_path }}

default.config.yml

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
---
2+
3+
compose_project_name: my-project
4+
docker_runtime_dir: my-project
5+
docker_cached_volume: true
6+
7+
host_machine_user: myusername
8+
9+
# Absolute Path to Drupal dir (`vendor` forlder should be there).
10+
drupal_root_dir: /var/data/drupal
11+
# Name of "web" folder inside `drupal_root_dir`.
12+
drupal_web_root: web
13+
# Absolute Path to Drupal files dir.
14+
drupal_files_dir: /var/data/drupal_files
15+
drupal_hash_salt: demo_site
16+
17+
apache_port: 80
18+
apache_port_ssl: 443
19+
20+
# Look at available options here: https://github.com/jet-dev-team/docker-compose-lamp/tree/drupal/bin
21+
phpversion: php74
22+
23+
# Enviroment variable for php xdebug extensions
24+
xdebug_enviroment: remote_enable=1 remote_connect_back=1 remote_port=9008 remote_host=192.168.105.1 show_error_trace=0 show_local_vars=1 remote_autostart=1 show_exception_trace=0 idekey=VSCODE
25+
26+
# Setup additional networking.
27+
advanced_networking: false
28+
network_id: 105
29+
domain_name: drupal.devel
30+
31+
init_project: false
32+
composer_project: drupal/recommended-project
33+
comoser_extras:
34+
- drush/drush
35+
- drupal/admin_toolbar
36+
37+
drush_install: true
38+
# Availible options: 8, 9, 10
39+
drush_version: 10
40+
41+
# Drush commands to run (will be run by `run-drush-commands.yml` playbook or if init_project is true).
42+
drush_commands:
43+
- 'cc drush'
44+
- 'site:install minimal --account-pass=admin --site-name="Drupal Dockerizer"'
45+
- 'theme:enable bartik claro'
46+
- 'en datetime toolbar rest jsonapi views views_ui ban automated_cron action admin_toolbar'
47+
- 'config-set system.theme default bartik'
48+
- 'config-set system.theme admin claro'
49+
- 'cron'
50+
51+
solr: false
52+
solr_core_name: drupal
53+
54+
# Tom make `memcache` working `memcache` module should be enabled: `en memcache`.
55+
memcache: false
56+
57+
# Path to Drupal DB dump (will be imported by `db.yml` playbook).
58+
db_dump_path: /var/data/db/db.sql
59+
60+
database: mysql
61+
mysql_root_password: root
62+
mysql_user: docker
63+
mysql_password: docker
64+
mysql_database: docker
65+
66+
install_adminer: false
67+
adminer_port: 8080
68+
69+
custom_drupal_settings: |
70+
if (file_exists($app_root . '/' . $site_path . '/settings.local.php')) {
71+
include $app_root . '/' . $site_path . '/settings.local.php';
72+
}

inventory

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
[server]
2+
127.0.0.1 ansible_python_interpreter=/usr/bin/python3
3+
4+
# Comment the default localhost line above, and uncomment the line below
5+
# (replacing the IP with your Pi's IP address) if running the playbook from a
6+
# separate workstation.
7+
#10.0.100.20 ansible_user=server ansible_python_interpreter=/usr/bin/python3

main.yml

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
---
2+
3+
- hosts: server
4+
5+
vars_files:
6+
- default.config.yml
7+
8+
pre_tasks:
9+
- name: Include config override file, if it exists.
10+
include_vars: "{{ item }}"
11+
with_fileglob:
12+
- config.yml
13+
14+
roles: []
15+
16+
tasks:
17+
- name: include project setup tasks.
18+
when: init_project
19+
include: tasks/project-setup.yml
20+
21+
- name: Include lamp setup tasks
22+
include: tasks/lamp-setup.yml
23+
24+
- name: Include solr setup tasks.
25+
when: solr
26+
include: tasks/solr-setup.yml
27+
28+
- name: Include Advanced Networking setup tasks
29+
when: advanced_networking
30+
include: tasks/advanced-networking-setup.yml
31+
32+
- name: Include Drush setup tasks
33+
when: drush_install
34+
include: tasks/drush-setup.yml
35+
36+
- name: Include Settings setup tasks
37+
include: tasks/settings-setup.yml
38+
39+
- name: Include Docker up tasks
40+
include: tasks/docker-up.yml
41+
42+
- name: Wait docker containers (MySQL) to up.
43+
pause:
44+
seconds: 30
45+
46+
- name: Setup drupal task
47+
when: drush_install and init_project
48+
include: tasks/drush-command.yml
49+
50+
- name: Include Memcache setup tasks
51+
when: memcache
52+
include: tasks/memcache-setup.yml

requirements.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
---

0 commit comments

Comments
 (0)