【问题标题】:Use drush-patchfile in DDEV environment在 DDEV 环境中使用 drush-patchfile
【发布时间】:2019-06-10 18:47:52
【问题描述】:

在 Drupal 7 中我使用

drush 补丁文件

在通过 drush 安装/更新模块时自动实施补丁。但在 DDEV 中,我不知道如何使用 drush-patchfile 扩展现有的 drush

正如您在https://bitbucket.org/davereid/drush-patchfile 安装部分看到的,我需要将存储库克隆到

~/.drush

目录并将其附加到现有的 drush。

在另一个没有 DDEV 的项目上,我已经通过创建新的 docker 映像文件完成了这项工作

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

但我不确定如何在 DDEV 容器中执行此操作。

我是否需要基于 drud/ddev-webserver 或其他东西创建新服务? 我已经阅读了documentation,但不确定该往哪个方向发展。

【问题讨论】:

    标签: ddev


    【解决方案1】:

    根据@rfay 评论,这里的解决方案适合我(只需稍加修改即可适用于其他项目)。

    1. 我已经在 docker 容器外克隆了repo;例如,我已经克隆到

      $PROJECT_ROOT/docker/drush-patchfile

    2. $PROJECT_ROOT/.esenca/patches文件夹中创建自定义drushrc.php(可以选择不同的文件夹)
    <?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. 将以下挂钩添加到 $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"
    
    

    最终的项目结构应该是这样的

    .
    ├── .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
    
    

    最后启动 ddev 环境

    ddev start
    

    现在您可以在 web docker 容器中使用drush-patchfile 命令。

    【讨论】:

      【解决方案2】:

      你可以ddev ssh 然后sudo chown -R $(id -u) ~/.drush/ 然后在那个目录中做任何你想做的事情(~/.drush 是 /home/.drush)。

      当您开始操作并希望每次启动都重复执行此操作时,您可以使用启动后挂钩对您需要的指令进行编码:https://ddev.readthedocs.io/en/latest/users/extending-commands/

      请跟进您使用的确切配方,因为它可能对其他人有所帮助。谢谢!

      【讨论】:

      • 感谢@rfay 的建议。我在答案中添加了详细说明。我没有在启动后挂钩中克隆 repo(每次项目启动时克隆 repo 会消耗大量时间),而是在挂钩中创建符号链接。它不是那么灵活的解决方案,但速度更快。
      猜你喜欢
      • 2018-12-14
      • 1970-01-01
      • 2018-10-21
      • 1970-01-01
      • 2019-09-28
      • 1970-01-01
      • 2018-11-12
      • 2018-12-06
      • 2021-09-10
      相关资源
      最近更新 更多