Search code examples
ddev

Use drush-patchfile in DDEV environment


In Drupal 7 I use

drush-patchfile

to automatically implements patches when installing/updating module via drush. But in DDEV I don't know how to extend existing drush with drush-patchfile

As you can see on https://bitbucket.org/davereid/drush-patchfile section Installation, I need to clone the repository into

~/.drush

directory and that will append it to existing drush.

On another project without DDEV, I've already done that with creating new docker image file

FROM wodby/drupal-php:7.1

USER root
RUN mkdir -p /home/www-data/.drush && chown -R www-data:www-data /home/www-data/;
RUN cd /home/www-data/.drush && git clone https://bitbucket.org/davereid/drush-patchfile.git \
  && echo "<?php \$options['patch-file'] = '/home/www-data/patches/patches.make';" \
  > /home/www-data/.drush/drushrc.php;
USER wodby

But I'm not sure how to do that in DDEV container.

Do I need to create a new service based on drud/ddev-webserver or something else? I've read documentation but not sure in what direction to go.


Solution

  • Based on @rfay comment, here solution that works for me (and with little modification can works for other projects).

    1. I've cloned repo outside of docker container; for example, I've cloned into

      $PROJECT_ROOT/docker/drush-patchfile

    2. Create custom drushrc.php in the $PROJECT_ROOT/.esenca/patches folder (you can choose different folder)
    <?php
    # Location to the patch.make file. This should be location within docker container
    $options['patch-file'] = '/var/www/html/.esenca/patches/patches.make';
    
    1. Add following hooks into $PROJECT_ROOT/.ddev/config.yaml
    hooks:
      post-start:
        # Copy drush-patchfile directory into /home/.drush
        - exec: "ln -s -t /home/.drush/ /var/www/html/docker/drush-patchfile"
        # Copy custom drushrc file.
        - exec: "ln -s -t /home/.drush/ /var/www/html/.esenca/patches/drushrc.php"
    
    

    Final project structure should looks like

    .
    ├── .ddev
    │   ├── config.yaml
    │   ├── docker-compose.yaml
    │   ├── .gitignore
    │   └── import-db
    ├── docker
    │   ├── drush-patchfile
    │   │   ├── composer.json
    │   │   ├── patchfile.drush.inc
    │   │   ├── README.md
    │   │   └── src
    ├── .esenca
    │   └── patches
    │       ├── drushrc.php
    │       └── patches.make
    ├── public_html
    │   ├── authorize.php
    │   ├── CHANGELOG.txt
    │   ├── COPYRIGHT.txt
    │   ├── cron.php
    │   ├── includes
    │   ├── index.html
    │   ├── index.php
    │   ├── INSTALL.mysql.txt
    │   ├── INSTALL.pgsql.txt
    │   ├── install.php
    │   ├── INSTALL.sqlite.txt
    │   ├── INSTALL.txt
    │   ├── LICENSE.txt
    │   ├── MAINTAINERS.txt
    │   ├── misc
    │   ├── modules
    │   ├── profiles
    │   ├── README.txt
    │   ├── robots.txt
    │   ├── scripts
    │   ├── sites
    │   │   ├── all
    │   │   ├── default
    │   │   ├── example.sites.php
    │   │   └── README.txt
    │   ├── themes
    │   ├── Under-Construction.gif
    │   ├── update.php
    │   ├── UPGRADE.txt
    │   ├── web.config
    │   └── xmlrpc.php
    └── README.md
    
    

    At the end start ddev envronment

    ddev start
    

    and now you can use drush-patchfile commands within web docker container.