generated from ddev/ddev-addon-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add commands, update install.yaml, docker-compose, README.
- Loading branch information
Jack
authored and
Jack
committed
Jul 6, 2023
1 parent
c2a56a0
commit 845d5da
Showing
8 changed files
with
184 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,51 +1,27 @@ | ||
[![tests](https://github.com/ddev/ddev-addon-template/actions/workflows/tests.yml/badge.svg)](https://github.com/ddev/ddev-addon-template/actions/workflows/tests.yml) ![project is maintained](https://img.shields.io/maintenance/yes/2024.svg) | ||
[![tests](https://github.com/ddev/drupal-rfs-custom-commands/actions/workflows/tests.yml/badge.svg)](https://github.com/ddev/drupal-rfs-custom-commands/actions/workflows/tests.yml) ![project is maintained](https://img.shields.io/maintenance/yes/2024.svg) | ||
|
||
# ddev-addon-template <!-- omit in toc --> | ||
# drupal-rfs-custom-commands <!-- omit in toc --> | ||
|
||
* [What is ddev-addon-template?](#what-is-ddev-addon-template) | ||
* [What is drupal-rfs-custom-commands?](#what-is-drupal-rfs-custom-commands) | ||
* [Components of the repository](#components-of-the-repository) | ||
* [Getting started](#getting-started) | ||
|
||
## What is ddev-addon-template? | ||
## What is drupal-rfs-custom-commands? | ||
|
||
This repository is a template for providing [DDEV](https://ddev.readthedocs.io) add-ons and services. | ||
The addon 'drupal-rfs-custom-commands' was developed to offer DDEV command shortcuts for common actions working with Drupal sites, like enabling/disabling Twig debugging or caching. | ||
|
||
In DDEV addons can be installed from the command line using the `ddev get` command, for example, `ddev get ddev/ddev-addon-template` or `ddev get ddev/ddev-drupal9-solr`. | ||
|
||
A repository like this one is the way to get started. You can create a new repo from this one by clicking the template button in the top right corner of the page. | ||
|
||
![template button](images/template-button.png) | ||
In DDEV addons can be installed from the command line using the `ddev get` command, for example, `ddev get ddev/drupal-rfs-custom-commands` or `ddev get ddev/ddev-drupal9-solr`. | ||
|
||
## Components of the repository | ||
|
||
* The fundamental contents of the add-on service or other component. For example, in this template there is a [docker-compose.addon-template.yaml](docker-compose.addon-template.yaml) file. | ||
* A web command [ctoggle](commands/web/ctoggle) that will enable or disable caching. | ||
* A web command [tdebug](commands/web/tdebug) that will enable or disable Twig debugging. | ||
* A web command [make](commands/web/make) that... | ||
* A host command [x](commands/host/x) that... | ||
* A [docker-compose.drupal-rfs-custom-commands.yaml](docker-compose.drupal-rfs-custom-commands.yaml) file. | ||
* An [install.yaml](install.yaml) file that describes how to install the service or other component. | ||
* A test suite in [test.bats](tests/test.bats) that makes sure the service continues to work as expected. | ||
* [Github actions setup](.github/workflows/tests.yml) so that the tests run automatically when you push to the repository. | ||
|
||
## Getting started | ||
|
||
1. Choose a good descriptive name for your add-on. It should probably start with "ddev-" and include the basic service or functionality. If it's particular to a specific CMS, perhaps `ddev-<CMS>-servicename`. | ||
2. Create the new template repository by using the template button. | ||
3. Globally replace "addon-template" with the name of your add-on. | ||
4. Add the files that need to be added to a ddev project to the repository. For example, you might remove `docker-compose.addon-template.yaml` with the `docker-compose.*.yaml` for your recipe. | ||
5. Update the install.yaml to give the necessary instructions for installing the add-on. | ||
|
||
* The fundamental line is the `project_files` directive, a list of files to be copied from this repo into the project `.ddev` directory. | ||
* You can optionally add files to the `global_files` directive as well, which will cause files to be placed in the global `.ddev` directory, `~/.ddev`. | ||
* Finally, `pre_install_commands` and `post_install_commands` are supported. These can use the host-side environment variables documented [in ddev docs](https://ddev.readthedocs.io/en/stable/users/extend/custom-commands/#environment-variables-provided). | ||
|
||
6. Update `tests/test.bats` to provide a reasonable test for your repository. Tests are triggered either by manually executing `bats ./tests/test.bat`, automatically on every push to the repository, or periodically each night. Please make sure to attend to test failures when they happen. Others will be depending on you. `bats` is a simple testing framework that just uses `bash`. To run a Bats test locally, you have to [install bats-core](https://bats-core.readthedocs.io/en/stable/installation.html) first. Then you download your add-on, and finally run `bats ./tests/test.bats` within the root of the uncompressed directory. To learn more about Bats see the [documentation](https://bats-core.readthedocs.io/en/stable/). | ||
7. When everything is working, including the tests, you can push the repository to GitHub. | ||
8. Create a release on GitHub. | ||
9. Test manually with `ddev get <owner/repo>`. | ||
10. You can test PRs with `ddev get https://github.com/<user>/<repo>/tarball/<branch>` | ||
11. Update the README.md to describe the add-on, how to use it, and how to contribute. If there are any manual actions that have to be taken, please explain them. If it requires special configuration of the using project, please explain how to do those. Examples in [ddev/ddev-drupal9-solr](https://github.com/ddev/ddev-drupal9-solr), [ddev/ddev-memcached](github.com/ddev/ddev-memcached), and [ddev/ddev-beanstalkd](https://github.com/ddev/ddev-beanstalkd). | ||
12. Add a good short description to your repo, and add the label "ddev-get". It will immediately be added to the list provided by `ddev get --list --all`. | ||
13. When it has matured you will hopefully want to have it become an "official" maintained add-on. Open an issue in the [ddev queue](https://github.com/ddev/ddev/issues) for that. | ||
|
||
Note that more advanced techniques are discussed in [DDEV docs](https://ddev.readthedocs.io/en/latest/users/extend/additional-services/#additional-service-configurations-and-add-ons-for-ddev). | ||
|
||
**Contributed and maintained by [@CONTRIBUTOR](https://github.com/CONTRIBUTOR) based on the original [ddev-contrib recipe](https://github.com/ddev/ddev-contrib/tree/master/docker-compose-services/RECIPE) by [@CONTRIBUTOR](https://github.com/CONTRIBUTOR)** | ||
|
||
**Originally Contributed by [somebody](https://github.com/somebody) in <https://github.com/ddev/ddev-contrib/> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#!/bin/bash | ||
|
||
## #ddev generated | ||
|
||
newPath=${PWD/$DDEV_APPROOT/\/var\/www\/html} | ||
ddev exec -d $newPath $@ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
#!/bin/bash | ||
|
||
## #ddev generated | ||
|
||
## Description: Enable or disable caching | ||
## Usage: ctoggle on|off|enable|disable|true|false | ||
## Example: ddev ctoggle (default is "on")\nddev ctoggle off\nddev ctoggle on <site> - for multisite, specify the folder | ||
## ProjectTypes: drupal8,drupal9,drupal10,drupal | ||
|
||
# define configuration | ||
local_settings="settings.personal.php" | ||
site=${2:-"default"} | ||
token="#caching#" | ||
|
||
# DDEV will always start you in /var/www/html in container commands. | ||
cd "web/sites" || exit 3 | ||
|
||
# Enables caching by adding a container yaml that points to a service | ||
# that has caching on. If the line is already there, avoids adding | ||
# it twice. | ||
disable_caching() { | ||
cd "$site" || exit 1 | ||
# Create the personal settings file if it doesn't exist. | ||
if [ ! -f $local_settings ]; then | ||
printf "<?php\n" > $local_settings | ||
fi | ||
|
||
if grep -qi "$token" $local_settings; then | ||
echo "Caching was already off."; | ||
else | ||
echo "\$config['system.performance']['css']['preprocess'] = FALSE; $token" >> $local_settings | ||
echo "\$config['system.performance']['js']['preprocess'] = FALSE; $token" >> $local_settings | ||
echo "\$settings['cache']['bins']['render'] = 'cache.backend.null'; $token" >> $local_settings | ||
echo "\$settings['cache']['bins']['page'] = 'cache.backend.null'; $token" >> $local_settings | ||
echo "\$settings['cache']['bins']['dynamic_page_cache'] = 'cache.backend.null'; $token" >> $local_settings | ||
echo -e "\e[32mCaching disabled.\e[0m" | ||
cd "/var/www/html/$DDEV_DOCROOT" || exit 5 | ||
if [ "$site" != "default" ]; then | ||
drush "@$site.local" cr | ||
else | ||
drush cr | ||
fi | ||
fi | ||
} | ||
|
||
# Disables caching by removing the line that points to the container | ||
# yaml. It does this by searching for a token that's appended as a comment. | ||
enable_caching() { | ||
cd "$site" || exit 1 | ||
# Create the personal settings file if it doesn't exist. | ||
if [ ! -f $local_settings ]; then | ||
printf "<?php\n" > $local_settings | ||
fi | ||
|
||
# Remove the line that contains the token if you are turning off. | ||
sed -i -e "/$token/d" $local_settings || exit 4 | ||
echo -e "\e[32mCaching enabled.\e[0m" | ||
cd "/var/www/html/$DDEV_DOCROOT" || exit 5 | ||
if [ "$site" != "default" ]; then | ||
drush "@$site.local" cr | ||
else | ||
drush cr | ||
fi | ||
} | ||
|
||
# Assume that they want the 'default' site folder if they have not specified. | ||
if [ $# -eq 0 ] ; then | ||
enable_caching "$site" | ||
exit | ||
fi | ||
|
||
case $1 in | ||
on|true|enable) | ||
enable_caching "$site" | ||
;; | ||
off|false|disable) | ||
disable_caching "$site" | ||
;; | ||
*) | ||
echo "Please enter a valid argument." | ||
esac |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#!/bin/bash | ||
|
||
## #ddev generated | ||
|
||
if [[ -f /var/www/html/Makefile ]] | ||
then | ||
cd /var/www/html && make $@ | ||
else | ||
cd /var/www/html/$DDEV_DOCROOT && make $@ | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
#!/bin/bash | ||
|
||
## Description: Enable or disable Twig debugging | ||
## Usage: tdebug on|off|enable|disable|true|false | ||
## Example: "ddev tdebug" (default is "on"), "ddev tdebug off", "ddev tdebug on" | ||
|
||
cd $DDEV_APPROOT/web/sites | ||
settings="twigdebug.development.services.yml" | ||
local_settings="settings.local.php" | ||
touch twigdebug.development.services.yml | ||
printf "twig.config:\n debug: true\n" > twigdebug.development.services.yml | ||
|
||
edit_settings_on() { | ||
if [ -f $local_settings ]; then | ||
echo "\$settings['container_yamls'][] = DRUPAL_ROOT . '/sites/twigdebug.development.services.yml'; #twigdebug#" > $local_settings | ||
fi | ||
} | ||
|
||
edit_settings_off() { | ||
if [ -f $local_settings ]; then | ||
sed -i -e "/#twigdebug#/d" $local_settings | ||
fi | ||
} | ||
|
||
enable_tdebug() { | ||
cd $DDEV_APPROOT/web/sites/default | ||
if [ -f $local_settings ]; then | ||
edit_settings_on | ||
else | ||
cd .. | ||
cat example.settings.local.php > settings.local.php | ||
edit_settings_on | ||
mv settings.local.php default | ||
fi | ||
echo "Twig debugging enabled." | ||
} | ||
|
||
disable_tdebug() { | ||
cd $DDEV_APPROOT/web/sites/default | ||
if [ -f $local_settings ]; then | ||
edit_settings_off | ||
else | ||
echo "No local settings file found." | ||
fi | ||
echo "Twig debugging disabled." | ||
} | ||
|
||
if [ $# -eq 0 ] ; then | ||
enable_tdebug | ||
exit | ||
fi | ||
|
||
case $1 in | ||
on|true|enable) | ||
enable_tdebug | ||
;; | ||
off|false|disable) | ||
disable_tdebug | ||
;; | ||
*) | ||
echo "Please enter a valid argument." | ||
|
||
esac |
6 changes: 3 additions & 3 deletions
6
docker-compose.addon-template.yaml → ...r-compose.drupal-rfs-custom-commands.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters