Skip to content
Snippets Groups Projects
Commit 1a5359af authored by jurgenhaas's avatar jurgenhaas
Browse files

Prepare release v3.0.0

parent 2b3105da
No related branches found
No related tags found
No related merge requests found
# Docker for Drupal Development
This is a composer plugin which prepares your local development environment for Docker using the framework from [Docker4Drupal](https://github.com/wodby/docker4drupal) by [Wodby](https://wodby.com).
This composer plugin prepares your local development environment for Docker using the framework from [Docker4Drupal](https://github.com/wodby/docker4drupal) by [Wodby](https://wodby.com).
## Requirements
Your development workstation needs to be prepared once, so that Docker and its components are available for all of your future projects. The instructions here have been tested on Ubuntu 16.04:
- [Install Docker Engine](https://docs.docker.com/engine/installation)
```bash
sudo apt-get install docker-engine
```
- [Install Docker Compose](https://docs.docker.com/compose/install/)
```bash
sudo pip install docker-compose
```
- [Install Git Extras](https://github.com/tj/git-extras/blob/master/Installation.md)
```bash
sudo apt-get install git-extras
```
- Name the group and add your user to it
```bash
sudo groupadd -r -g 82 www-docker
sudo usermod -a -G www-docker $(id -un)
sudo usermod -a -G docker $(id -un)
# logout and re-login again to make these changes effective
```
This plugin is best used inside of [L3D](https://gitlab.lakedrops.com/docker/l3d) where no further requirements need to be met.
## Installation in your Drupal project
This is a composer plugin. It can be used both in composer based Drupal installations and also vanilla Drupal without composer.
If you're using the latest version of the [D8 Project Template](https://gitlab.lakedrops.com/lakedrops/d8-project), this docker4drupal plugin will be installed automatically as a dependency of the [Composer Plugin for Drupal 8 Project Template](https://gitlab.lakedrops.com/lakedrops/d8-project-scaffold).
If you're using the latest version of either [D8 Project Template](https://gitlab.lakedrops.com/composer/project/drupal-8) or [D9 Project Template](https://gitlab.lakedrops.com/composer/project/drupal-9), this docker4drupal plugin will be installed automatically as a dependency of the [Drupal Development Environment](https://gitlab.lakedrops.com/composer/drupal-development-environment).
In all other cases, simply install it by typing
......@@ -51,21 +24,16 @@ This will install and configure all required files so that you can launch your D
- Create and configure **settings.docker.php** in your settings directory
- Modify your **settings.php** to load **settings.docker.php** if available
- Create Drush settings, aliases and shell-aliases in a `drush` subdirectory of the current directory
- Configure and (re)start a single Docker [Traefik](https://docs.traefik.io) service in the `~/.traefik` directory which serves as a proxy for any number of parallel running Docker4Drupal projects
- Configure and (re)start a single Docker [Traefik](https://docs.traefik.io) service in the `~/.traefik` directory which serves as a proxy for any number of parallel running Docker4Drupal projects. This service is provided by the [LakeDrops Traefik Library](https://gitlab.lakedrops.com/composer/library/docker-traefik).
- Add those new files to **.gitignore** as you usually don't want them to be committed
### Installation in a vanilla Drupal project
Before you get started you should create (or add to an existing) composer.json like this:
Before you get started you should create (or add to an existing) `.lakedrops.yml` in your projects root like this:
```json
{
"extra": {
"docker4drupal": {
"webroot": "relative/path/to/drupal/core"
}
}
}
```yaml
docker4drupal:
webroot: relative/path/to/drupal/core
```
After that you can call
......@@ -78,17 +46,35 @@ and everything will be configured for you.
## Usage
All the commands need to be called from the root of your main Drupal project.
### Updating Docker-Compose configuration
```bash
# With Ahoy
ahoy update
# Directly
composer lakedrops:docker4drupal
```
### Starting the Docker containers
```bash
cd /path/of/project/root
# With Ahoy
ahoy up
# Directly
docker-compose up -d
```
### Stopping the Docker containers
```bash
cd /path/of/project/root
# With Ahoy
ahoy stop
# Directly
docker-compose stop
```
......@@ -160,7 +146,7 @@ Typical issues that may cause trouble in this context are:
### Using Drush
This plugin configures Drush with several settings, aliases and shell-aliases that make your developer life much easier. You can either enter the PHP container and execute Drush there or you can call every Drush command from your host:
This plugin configures Drush with several settings, aliases and shell-aliases that make your developer life much easier. You can either enter the PHP container and execute Drush there, or you can call every Drush command from your host. When you're using the L3D framework, simply call `drush` in your L3D container and everything else happens magically in the background.
```bash
# Entering PHP Container
......@@ -175,7 +161,7 @@ docker-compose exec php drush site-aliases
Even better, you can create shell aliases (see below) for your host's shell which will make that even easier:
```bash
cdrush site-aliases
drush site-aliases
```
If you have configured SSH access to your live site (see above) then you can easily pull the database and/or the files from your live site into your development environment easily:
......@@ -197,145 +183,116 @@ What else can be done with the Docker environment is best described in the [Dock
## Customization
To overwrite the default settings for the Docker environment, add the relevant parts from this array to your composer.json file in the root of your project:
```json
{
"extra": {
"docker4drupal": {
"projectname": "[NAME OF CURRENT DIRECTORY]",
"live": {
"root": "",
"uri": "",
"host": "",
"user": ""
},
"drush": {
"sql": {
"tables": {
"structure": ["cache", "cache_*", "history", "search_*", "sessions", "watchdog"],
"skip": ["migration_*"]
}
}
},
"drupal": {
"version": 8
},
"php": {
"version": "7.2",
"xdebug": 1
},
"webserver": {
"type": "apache"
},
"varnish": {
"enable": 0
},
"redis": {
"version": "4.0"
},
"dbbrowser": {
"type": "pma"
},
"solr": {
"enable": 0,
"version": "6.6"
},
"node": {
"enable": 0,
"key": "",
"path": ""
},
"memcached": {
"enable": 0
},
"rsyslog": {
"enable": 0
},
"athenapdf": {
"enable": 0,
"key": ""
},
"blackfire": {
"enable": 0,
"id": "",
"token": ""
},
"webgrind": {
"enable": 0
},
"wkhtmltox": {
"enable": 0
}
}
}
}
To overwrite the default settings for the Docker environment, add the relevant parts from this array to your `.lakedrops.yml` file in the root of your project:
```yaml
docker4drupal:
projectname: [NAME OF CURRENT DIRECTORY]
ci_home: /home/gitlab-runner
docker0:
ip: [IP OF YOUR DOCKER HOST]
live:
root: ''
uri: ''
host: ''
user: ''
drush:
sql:
tables:
structure:
- cache
- cache_*
- history
- search_*
- sessions
- watchdog
skip:
- migration_*
drupal:
version: 8
php:
version: '7.2'
xdebug: 1
webserver:
type: apache
varnish:
enable: 0
redis:
version: '4.0'
dbbrowser:
type: pma
solr:
enable: 0
version: '6.6'
node:
enable: 0
key: ''
path: ''
memcached:
enable: 0
rsyslog:
enable: 0
athenapdf:
enable: 0
key: ''
blackfire:
enable: 0
id: ''
token: ''
webgrind:
enable: 0
wkhtmltox:
enable: 0
```
Other supported values for the PHP version are `5.3`, `5.6`, `7.0` and `7.1`.
Other supported value for the webserver type is `nginx`.
Supported versions for `nginx`: `1.15`, `1.14`, `1.13`.
Other supported value for the Redis version is `3.2`.
Other supported value for the dbbrowser type is `adminer`. In that case you should also add a version element with either `4.6`, `4.3` or `4.2`.
Once you've changed those values, run `ahoy update` (or `composer lakedrops:docker4drupal`) and the environment will be re-configured. The next time you start your Docker environment those new values will be used.
### Adding new Docker services or enhancing existing ones
You can add more details to you `.lakedrops.yml` configuration to create additional Docker services or enhance existing ones:
```yaml
docker4drupal:
docker-compose.yml:
services:
php:
environment:
MY_VAR: value
mariadbd6:
image: wodby/mariadb:10.1
environment:
MYSQL_ROOT_PASSWORD: password
MYSQL_DATABASE: drupal
MYSQL_USER: drupal
MYSQL_PASSWORD: drupal
mycustomservice:
image: mydomain/myimage
```
Other supported values for the Solr version are `6.5`, `6.4`, `6.3`, `5.5` and `5.4`.
This will add another environment variable to the php container, define a second mariadb container named `mariadbd6` which may be used e.g. for a migration from a separate database and also a custom service with your own image and configuration.
Once you've changed those values, run `composer update` and the environment will be re-configured. The next time you start your Docker environment those new values will be used.
Please remember to update docker compose with `ahoy update` and then recreate your containers with `ahoy up` after changing these settings.
### Individually updating docker4drupal
### More configuration tweaks
You can add this to your composer.json:
#### Customizing the apache config
```json
{
"scripts": {
"d4d": "LakeDrops\\Docker4Drupal\\Plugin::config"
}
}
```yaml
docker4drupal:
webserver:
overwriteconfig: 1
```
That allows you to simply call the following command to only update docker4drupal settings:
With this setting you get the apache container to include the file `./apache/vhost.conf` relative to your project root when loading up.
```bash
composer d4d
```
Note, that docker4drupal configuration **does overwrite** existing setting files when you run this script.
Therefore, you can add custom content to the settings files by adding another key to the `extra/docker4drupal` section with the file name as the key and additional settings underneath. Example:
```json
{
"extra": {
"docker4drupal": {
"docker-compose.yml": {
"services": {
"php": {
"environment": {
"MY_VAR": "value"
}
},
"mariadbd6": {
"image": "wodby/mariadb:10.1",
"environment": {
"MYSQL_ROOT_PASSWORD": "password",
"MYSQL_DATABASE": "drupal",
"MYSQL_USER": "drupal",
"MYSQL_PASSWORD": "drupal"
}
}
}
}
}
}
}
```
#### Adding more domain names to be routed to your apache container
This will add another environment variable to the php container and define a second mariadb container named `mariadbd6` which may be used e.g. for a migration from a separate database.
```yaml
docker4drupal:
extradomains:
- domain1.example.com
- domain2.example.com
```
## Tipps & Tricks
......@@ -349,34 +306,6 @@ There is some debate whether such subdomains are legitimate or not and Chrome/Go
This plugin configures the Docker containers such that any number of them can be launched in parallel. And as each of them get individual project names which will then be part of the domain name(s), you can use them all at the same time. To make this possible, a separat Docker service container will be created and launched, which operates as a proxy to route your local traffic to the always correct docker container with the correct development website.
### Defining shell aliases on your host
When you're using `docker-compose` a lot, you'll get tired quickly by typing such long commands over and over again. To simplify your shel life here even more, we recommend to define a number of shell aliases. How to do that depends on the shell you're using. For the famous Fish shell we would write the following lines in a file called `/etc/fish/conf.d/docker-compose.fish`:
```text
alias c "docker-compose"
alias cb "docker-compose build"
alias cup "docker-compose up -d"
alias cr "docker-compose run --service-ports --rm"
alias crl "docker-compose run --service-ports --rm local"
alias crd "docker-compose run --service-ports --rm develop"
alias crt "docker-compose run --rm test"
alias crp "docker-compose run --rm provision"
alias crci "docker-compose run --rm ci"
alias crwt "docker-compose run --rm watchtest"
alias cps "docker-compose ps"
alias clogs "docker-compose logs"
alias cstop "docker-compose stop"
alias cstart "docker-compose start"
alias cshell "docker-compose exec --user root php sh"
alias cdrush "docker-compose exec --user root php drush"
alias cdrush-pull "cdrush-pull-sql; and cdrush-pull-files"
alias cdrush-pull-sql "cdrush sql:sync --create-db @default.live @default.dev; and cdrush @default.dev cr; and cdrush @default.dev dev on"
alias cdrush-pull-files "cdrush rsync @default.live:%files/ @default.dev:%files -- --chown=www-data:www-data --safe-links --max-size=20M"
```
Do that once, it will pay back in a magnitude.
### Working with wkhtmltox
When using the Drupal module `print` then go to `admin/config/user-interface/print/pdf/wkhtmltopdf` and remove the options `--footer-font-size 7 --footer-right '[page]'` because they don't work in the unpatched QT version.
......
......@@ -27,7 +27,7 @@
"ext-json": "*",
"php": ">=7.2",
"composer-plugin-api": "^1||^2",
"lakedrops/composer-json-utils": "^1.7||dev-master",
"lakedrops/composer-json-utils": "^2.0||dev-master",
"lakedrops/docker-traefik": "^1.3||dev-master"
},
"require-dev": {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment