Skip to content

Commit c35fe66

Browse files
authored
Merge pull request #436 from wunderio/feature/QAG-31
QAG-31: (feat) Move config from basic profile to config/sync
2 parents a846cab + 88180ab commit c35fe66

File tree

210 files changed

+1041
-244
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

210 files changed

+1041
-244
lines changed

.ddev/config.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ web_environment:
2424
- EXEC_GRUMPHP_COMMAND=ddev php
2525
- HASH_SALT=notsosecurehash
2626
- ELASTICSEARCH_HOST=elasticsearch
27+
- VARNISH_ADMIN_HOST=varnish
28+
- VARNISH_ADMIN_PORT=80
2729

2830
corepack_enable: false
2931
hooks:

.ddev/varnish/default.vcl

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@
22
vcl 4.1;
33
import std;
44

5+
# Define an ACL for trusted purge clients
6+
acl purge {
7+
"127.0.0.1";
8+
"::1";
9+
"web";
10+
}
11+
512
backend default {
613
.host = "web";
714
.port = "80";
@@ -26,6 +33,57 @@ sub vcl_recv {
2633
if (std.port(server.ip) == 8025) {
2734
return (synth(750));
2835
}
36+
37+
# Handle PURGE requests for Drupal's varnish_purger module
38+
if (req.method == "PURGE") {
39+
# Allow PURGE requests from trusted clients only
40+
if (!client.ip ~ purge) {
41+
return (synth(403, "Access denied."));
42+
}
43+
44+
# Purge by Cache-Tags header
45+
if (req.http.Cache-Tags) {
46+
ban("obj.http.Cache-Tags ~ " + req.http.Cache-Tags);
47+
return (synth(200, "Purge executed."));
48+
}
49+
50+
# For URL-based purging
51+
return (hash);
52+
}
53+
54+
# Handle BAN requests for Drupal's cache tags
55+
if (req.method == "BAN") {
56+
# Allow BAN requests from trusted clients only
57+
if (!client.ip ~ purge) {
58+
return (synth(403, "Access denied."));
59+
}
60+
61+
# Ban by Cache-Tags header (sent by Drupal's varnish_purger module)
62+
if (req.http.Cache-Tags) {
63+
ban("obj.http.Cache-Tags ~ " + req.http.Cache-Tags);
64+
return (synth(200, "Ban added."));
65+
}
66+
67+
return (synth(403, "Invalid ban request"));
68+
}
69+
}
70+
71+
sub vcl_hit {
72+
if (req.method == "PURGE") {
73+
# We found the object in cache, now invalidate it
74+
set req.http.X-Purge-URL = req.url;
75+
set req.http.X-Purge-Host = req.http.host;
76+
return (synth(200, "Purged " + req.url));
77+
}
78+
}
79+
80+
sub vcl_miss {
81+
if (req.method == "PURGE") {
82+
# Object not in cache, but we still respond with a success
83+
set req.http.X-Purge-URL = req.url;
84+
set req.http.X-Purge-Host = req.http.host;
85+
return (synth(200, "Purged " + req.url + " (not in cache)"));
86+
}
2987
}
3088

3189
sub vcl_synth {
@@ -36,3 +94,10 @@ sub vcl_synth {
3694
return (deliver);
3795
}
3896
}
97+
98+
# Store the Cache-Tags header from backend responses
99+
sub vcl_backend_response {
100+
if (beresp.http.Cache-Tags) {
101+
set beresp.http.Cache-Tags = beresp.http.Cache-Tags;
102+
}
103+
}

README.md

Lines changed: 112 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ This project is a tailored fork of the popular [drupal-composer template](https:
55
## Getting started
66

77
1. **Create a new project repository**
8-
Click "[Use this template](https://github.com/wunderio/drupal-project/generate)" to generate a new project:
8+
Click "[Use this template](https://github.com/wunderio/drupal-project/generate)" to generate a new project:
99
- Select the correct owner.
1010
- Name the project as `client-COUNTRYCODE-CLIENT-PROJECT`.
1111
- Set the repository to private (unless the project is public).
@@ -77,20 +77,22 @@ This project supports two local development environments: DDEV (preferred) and L
7777
2. Ensure Docker is running on your system
7878
3. Start the environment and set up your project:
7979

80-
```bash
81-
# Start the DDEV environment
82-
ddev start
80+
```bash
81+
# Start the DDEV environment
82+
ddev start
8383

84-
# Authenticate SSH for database syncing
85-
ddev auth ssh
84+
# Authenticate SSH for database syncing
85+
ddev auth ssh
8686

87-
# Synchronize local database with a remote environment
88-
# See `scripts/syncdb.sh` for options
89-
ddev syncdb
87+
# Synchronize local database with a remote environment
88+
# See `scripts/syncdb.sh` for options
89+
ddev syncdb
9090

91-
# Get a one-time login link for admin access
92-
ddev drush uli
93-
```
91+
# Get a one-time login link for admin access
92+
drush uli
93+
```
94+
95+
Note: All commands in the DDEV section should be run within the DDEV environment using `ddev` prefix (e.g., `ddev drush uli`), or by using `ddev ssh` to access the container shell first.
9496

9597
#### DDEV services and access points
9698

@@ -141,9 +143,9 @@ For a complete list of all available services, URLs, and ports, use:
141143
1. Install [Lando](https://github.com/lando/lando/releases)
142144
2. Start the environment:
143145

144-
```bash
145-
lando start
146-
```
146+
```bash
147+
lando start
148+
```
147149

148150
#### Lando common commands
149151

@@ -194,44 +196,106 @@ This project uses [Cursor](https://docs.cursor.com/) as the recommended AI-power
194196

195197
### Varnish and Purge configuration
196198

197-
1. **Enable Varnish:**
198-
- Uncomment the Varnish configuration in `.lando.yml` under `services → varnish` and `proxy → varnish`.
199-
- Run `lando rebuild -y`.
199+
This section describes how to set up Varnish caching and Purge functionality in your local development environment.
200+
201+
Note: Drush commands in this section should be run with the appropriate environment prefix (`ddev` or `lando`).
202+
203+
#### Configuration Overview
204+
205+
The project includes ready-to-use Varnish configuration:
206+
207+
1. **Configuration Import (Recommended)**
208+
- For existing projects, simply import the configuration from `config/sync`:
209+
210+
```bash
211+
drush cim -y
212+
```
213+
214+
- This applies all Purge and Varnish settings, including processors and purgers
215+
216+
2. **Manual Configuration (for new sites)**
217+
- If config/sync is not available, follow these steps:
218+
219+
a. **Install required modules**:
220+
221+
```bash
222+
drush en purge purge_drush purge_processor_lateruntime purge_queuer_coretags purge_tokens purge_ui varnish_purger varnish_purge_tags -y
223+
```
224+
225+
b. **Configure Varnish Purger**:
226+
- Set a value for **Browser and proxy cache maximum age** in `admin/config/development/performance`
227+
- Navigate to `/admin/config/development/performance/purge`
228+
- Click **Add purger** and select **Varnish Purger**:
229+
- **Name:** "Varnish Purger"
230+
- **Type:** "Tags"
231+
- **Request method:** "BAN" (important: use BAN instead of PURGE for compatibility with Silta)
232+
- **Headers:** `Cache-Tags`: `[invalidation:expression]`
233+
- Save the configuration
200234

201-
2. **Basic installation profile configuration:**
202-
- Install the `basic` profile: `lando drush si basic -y`.
203-
- This sets up Purge and Varnish Purge out of the box.
235+
c. **Configure processors**:
236+
- Go to `/admin/config/development/performance/purge/processors`
237+
- Ensure these processors are enabled:
238+
- `drush_purge_invalidate` (for manual invalidation via Drush)
239+
- `lateruntime` (for batching invalidations)
240+
- `purge_ui_block_processor` (for admin UI functionality)
204241

205-
3. **Configuration for installed sites:**
206-
- Enable the required modules:
242+
d. **Export the configuration**:
207243

208-
```bash
209-
lando drush en purge purge_drush purge_processor_lateruntime purge_queuer_coretags purge_tokens purge_ui varnish_purger varnish_purge_tags -y
210-
```
244+
```bash
245+
drush cex -y
246+
```
211247

212-
- Set a value for **Browser and proxy cache maximum age** in `admin/config/development/performance`.
213-
- Navigate to `/admin/config/development/performance/purge`, click **Add purger**, and select **Varnish Purger**:
214-
- **Name:** "Varnish Purger"
215-
- **Headers:** `Cache-Tags`: `[invalidation:expression]`
216-
- Save the configuration.
217-
- Export the configuration:
248+
e. **Update settings.php**:
249+
- Find the purger ID in `varnish_purger.settings.<PURGER_ID>.yml`
250+
- Update `web/sites/default/settings.php` with the correct purger ID:
218251

219-
```bash
220-
lando drush cex -y
221-
```
252+
```php
253+
if (getenv('VARNISH_ADMIN_HOST')) {
254+
$config['varnish_purger.settings.<PURGER_ID>']['hostname'] = trim(getenv('VARNISH_ADMIN_HOST'));
255+
$config['varnish_purger.settings.<PURGER_ID>']['port'] = getenv('VARNISH_ADMIN_PORT') ? trim(getenv('VARNISH_ADMIN_PORT')) : '80';
256+
}
257+
```
258+
259+
#### Environment-Specific Setup
260+
261+
##### DDEV (Recommended)
262+
263+
1. **Varnish Configuration**: DDEV comes pre-configured with Varnish in `.ddev` folder.
264+
265+
2. **Testing Configuration**:
266+
267+
```bash
268+
ddev drush cr
269+
ddev exec curl -X BAN -H "Cache-Tags: config:system.performance" http://varnish
270+
```
271+
272+
If working correctly, you should receive a "200 Ban added" response
273+
274+
3. **Viewing Varnish logs**:
275+
276+
```bash
277+
ddev exec -s varnish varnishlog -i BAN -i Cache
278+
```
279+
280+
##### Lando
281+
282+
1. **Enable Varnish**:
283+
- Varnish configuration is already enabled in `.lando.yml` & `.lando/varnish.vcl`.
284+
285+
2. **Testing Configuration**:
286+
287+
```bash
288+
lando drush cr
289+
lando ssh -c "curl -X BAN -H 'Cache-Tags: config:system.performance' http://varnish"
290+
```
222291
223-
- Find the purger ID in the exported `varnish_purger.settings.<PURGER_ID>.yml` file.
224-
- Update `web/sites/default/settings.php`:
225-
- Replace all occurrences of `varnish_purger.settings.<OLD_ID>` with the new purger ID.
226-
- Clear the cache:
292+
### Important Notes
227293
228-
```bash
229-
lando drush cr
230-
```
294+
- **BAN vs PURGE Method:** Always use the "BAN" method in the Varnish purger configuration instead of "PURGE". The Silta Varnish configuration is set up to handle BAN requests but may reject PURGE requests with "405 Method Not Allowed" errors.
231295
232-
Varnish should now be configured to handle caching and purging when content is updated.
296+
- **Processors:** The default Purge setup uses the `purge_processor_lateruntime` module, which empties the purge queue during page requests. This works well for most sites needing immediate cache clearing. Ensure all required processors are enabled.
233297
234-
**Note:** The default Purge setup uses the `purge_processor_lateruntime` module, which empties the purge queue during page requests. This works well for most sites needing immediate cache clearing.
298+
- **Cache Tags:** The Varnish configuration is set up to handle cache tag invalidation with the `Cache-Tags` header.
235299
</details>
236300
237301
<details>
@@ -243,11 +307,11 @@ The [PHPUnit](https://phpunit.de/) test framework is predefined in this project.
243307
244308
#### Testing examples
245309
246-
Use `lando phpunit` to run PHPUnit commands:
310+
Note: Run these commands with the appropriate environment prefix (`ddev phpunit` or `lando phpunit`).
247311
248-
- Run one test class: `lando phpunit path/to/your/class/file.php`
249-
- List groups: `lando phpunit --list-groups`
250-
- Run all tests in a particular group: `lando phpunit --group Groupname`
312+
- Run one test class: `phpunit path/to/your/class/file.php`
313+
- List groups: `phpunit --list-groups`
314+
- Run all tests in a particular group: `phpunit --group Groupname`
251315
</details>
252316
253317
### Secrets handling
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
_core:
2+
default_config_hash: jvTSppzcgH5wnzBhX5xnAExcp2I1CzkQ_aky65XNfYI
3+
menu_depth: 4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
_core:
2+
default_config_hash: WgdZsrd_5w9jlmcHV4R9dD2tG9OZEkYo4I_O8h7Gq8Q
13
max_bundle_number: 20
24
hoverintent_functionality: true
35
show_local_tasks: false
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
_core:
2+
default_config_hash: 0G5pZBcxbg8ONYzNLd1RJIsvuFFewm9htnS4I-ABKJ8
3+
max_age: 86400
4+
cron_interval: 21600
5+
limit: 10
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
_core:
2+
default_config_hash: fUksROt4FfkAU9BV4hV2XvhTBSS2nTNrZS4U7S-tKrs
3+
interval: 10800
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
1+
uuid: 651e07ca-4570-40dd-8a7b-672eda40beba
12
langcode: en
23
status: true
34
dependencies:
45
module:
56
- system
67
theme:
78
- claro
9+
_core:
10+
default_config_hash: NjcxOBrPOiK5-38t56DwFBDVY4yer7YSlbRWXFuHe7A
811
id: claro_breadcrumbs
912
theme: claro
1013
region: breadcrumb
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
1+
uuid: 1bea4578-118d-46ed-b612-d0fee5088884
12
langcode: en
23
status: true
34
dependencies:
45
module:
56
- system
67
theme:
78
- claro
9+
_core:
10+
default_config_hash: a0Yyx1GeyKarZ4T_yXQBR_ZFKnXiFLtxAb6gWLd8nr0
811
id: claro_content
912
theme: claro
1013
region: content
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
1+
uuid: 46be1d31-9fa7-449e-8414-c0610565f720
12
langcode: en
23
status: true
34
dependencies:
45
module:
56
- help
67
theme:
78
- claro
9+
_core:
10+
default_config_hash: jccFSSVqV0WCDb6NtML1VWAWTtDbZ-zn5YgTRMgMrIM
811
id: claro_help
912
theme: claro
1013
region: help

0 commit comments

Comments
 (0)