diff --git a/composer.lock b/composer.lock index cc5c6ea8..9cd2c43f 100644 --- a/composer.lock +++ b/composer.lock @@ -3724,16 +3724,16 @@ }, { "name": "drupal/hdbt", - "version": "6.4.13", + "version": "6.4.14", "source": { "type": "git", "url": "https://github.com/City-of-Helsinki/drupal-hdbt.git", - "reference": "c76de24931e368362b1991f0c4f75c37786234cb" + "reference": "d33cb4edcb2c7574a5dc3b08fc24426137542197" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/City-of-Helsinki/drupal-hdbt/zipball/c76de24931e368362b1991f0c4f75c37786234cb", - "reference": "c76de24931e368362b1991f0c4f75c37786234cb", + "url": "https://api.github.com/repos/City-of-Helsinki/drupal-hdbt/zipball/d33cb4edcb2c7574a5dc3b08fc24426137542197", + "reference": "d33cb4edcb2c7574a5dc3b08fc24426137542197", "shasum": "" }, "require": { @@ -3751,10 +3751,10 @@ "Drupal" ], "support": { - "source": "https://github.com/City-of-Helsinki/drupal-hdbt/tree/6.4.13", + "source": "https://github.com/City-of-Helsinki/drupal-hdbt/tree/6.4.14", "issues": "https://github.com/City-of-Helsinki/drupal-hdbt/issues" }, - "time": "2024-02-22T08:40:40+00:00" + "time": "2024-02-26T14:05:44+00:00" }, { "name": "drupal/hdbt_admin", @@ -4142,16 +4142,16 @@ }, { "name": "drupal/helfi_proxy", - "version": "3.2.1", + "version": "3.2.2", "source": { "type": "git", "url": "https://github.com/City-of-Helsinki/drupal-module-helfi-proxy.git", - "reference": "1ecaece7ca13117f3170b0fa5cf363e316b1dcf3" + "reference": "20dda60b28e43508d06fd08e4bfa705538f483bf" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/City-of-Helsinki/drupal-module-helfi-proxy/zipball/1ecaece7ca13117f3170b0fa5cf363e316b1dcf3", - "reference": "1ecaece7ca13117f3170b0fa5cf363e316b1dcf3", + "url": "https://api.github.com/repos/City-of-Helsinki/drupal-module-helfi-proxy/zipball/20dda60b28e43508d06fd08e4bfa705538f483bf", + "reference": "20dda60b28e43508d06fd08e4bfa705538f483bf", "shasum": "" }, "require": { @@ -4187,10 +4187,10 @@ ], "description": "Provides various fixes so we can serve multiple Drupal instances in one domain.", "support": { - "source": "https://github.com/City-of-Helsinki/drupal-module-helfi-proxy/tree/3.2.1", + "source": "https://github.com/City-of-Helsinki/drupal-module-helfi-proxy/tree/3.2.2", "issues": "https://github.com/City-of-Helsinki/drupal-module-helfi-proxy/issues" }, - "time": "2024-01-08T07:35:45+00:00" + "time": "2024-02-23T10:27:26+00:00" }, { "name": "drupal/helfi_tpr", @@ -6441,24 +6441,24 @@ }, { "name": "drupal/twig_tweak", - "version": "3.2.1", + "version": "3.3.0", "source": { "type": "git", "url": "https://git.drupalcode.org/project/twig_tweak.git", - "reference": "3.2.1" + "reference": "3.3.0" }, "dist": { "type": "zip", - "url": "https://ftp.drupal.org/files/projects/twig_tweak-3.2.1.zip", - "reference": "3.2.1", - "shasum": "89fc08b60f494a7d786251b6c2c493c536218222" + "url": "https://ftp.drupal.org/files/projects/twig_tweak-3.3.0.zip", + "reference": "3.3.0", + "shasum": "a029ab1775b62f08e573e5ad1ab27bc833e7f5b9" }, "require": { "drupal/core": "^9.3 || ^10.0", "ext-json": "*", "php": ">=7.3", "symfony/polyfill-php80": "^1.17", - "twig/twig": "^2.12 || ^3.3.8" + "twig/twig": "^2.15.3 || ^3.4.3" }, "suggest": { "symfony/var-dumper": "Better dump() function for debugging Twig variables" @@ -6466,8 +6466,8 @@ "type": "drupal-module", "extra": { "drupal": { - "version": "3.2.1", - "datestamp": "1677404306", + "version": "3.3.0", + "datestamp": "1708670116", "security-coverage": { "status": "covered", "message": "Covered by Drupal's security advisory policy" @@ -15992,21 +15992,21 @@ }, { "name": "phpdocumentor/type-resolver", - "version": "1.8.1", + "version": "1.8.2", "source": { "type": "git", "url": "https://github.com/phpDocumentor/TypeResolver.git", - "reference": "bc3dc91a5e9b14aa06d1d9e90647c5c5a2cc5353" + "reference": "153ae662783729388a584b4361f2545e4d841e3c" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpDocumentor/TypeResolver/zipball/bc3dc91a5e9b14aa06d1d9e90647c5c5a2cc5353", - "reference": "bc3dc91a5e9b14aa06d1d9e90647c5c5a2cc5353", + "url": "https://api.github.com/repos/phpDocumentor/TypeResolver/zipball/153ae662783729388a584b4361f2545e4d841e3c", + "reference": "153ae662783729388a584b4361f2545e4d841e3c", "shasum": "" }, "require": { "doctrine/deprecations": "^1.0", - "php": "^7.4 || ^8.0", + "php": "^7.3 || ^8.0", "phpdocumentor/reflection-common": "^2.0", "phpstan/phpdoc-parser": "^1.13" }, @@ -16044,9 +16044,9 @@ "description": "A PSR-5 based resolver of Class names, Types and Structural Element Names", "support": { "issues": "https://github.com/phpDocumentor/TypeResolver/issues", - "source": "https://github.com/phpDocumentor/TypeResolver/tree/1.8.1" + "source": "https://github.com/phpDocumentor/TypeResolver/tree/1.8.2" }, - "time": "2024-01-18T19:15:27+00:00" + "time": "2024-02-23T11:10:43+00:00" }, { "name": "phpspec/prophecy", @@ -16215,16 +16215,16 @@ }, { "name": "phpstan/phpdoc-parser", - "version": "1.25.0", + "version": "1.26.0", "source": { "type": "git", "url": "https://github.com/phpstan/phpdoc-parser.git", - "reference": "bd84b629c8de41aa2ae82c067c955e06f1b00240" + "reference": "231e3186624c03d7e7c890ec662b81e6b0405227" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpstan/phpdoc-parser/zipball/bd84b629c8de41aa2ae82c067c955e06f1b00240", - "reference": "bd84b629c8de41aa2ae82c067c955e06f1b00240", + "url": "https://api.github.com/repos/phpstan/phpdoc-parser/zipball/231e3186624c03d7e7c890ec662b81e6b0405227", + "reference": "231e3186624c03d7e7c890ec662b81e6b0405227", "shasum": "" }, "require": { @@ -16256,9 +16256,9 @@ "description": "PHPDoc parser with support for nullable, intersection and generic types", "support": { "issues": "https://github.com/phpstan/phpdoc-parser/issues", - "source": "https://github.com/phpstan/phpdoc-parser/tree/1.25.0" + "source": "https://github.com/phpstan/phpdoc-parser/tree/1.26.0" }, - "time": "2024-01-04T17:06:16+00:00" + "time": "2024-02-23T16:05:55+00:00" }, { "name": "phpstan/phpstan", diff --git a/conf/cmi/purge.logger_channels.yml b/conf/cmi/purge.logger_channels.yml index cc39a601..d2acba46 100644 --- a/conf/cmi/purge.logger_channels.yml +++ b/conf/cmi/purge.logger_channels.yml @@ -27,3 +27,9 @@ channels: - 0 - 2 - 3 + - + id: purger_varnish_assets + grants: + - 0 + - 2 + - 3 diff --git a/conf/cmi/purge.plugins.yml b/conf/cmi/purge.plugins.yml index bf7c8663..a7f8641f 100644 --- a/conf/cmi/purge.plugins.yml +++ b/conf/cmi/purge.plugins.yml @@ -7,6 +7,10 @@ purgers: instance_id: varnish_purge_all plugin_id: varnish order_index: 3 + - + instance_id: assets + plugin_id: varnish + order_index: 4 processors: - plugin_id: drush_purge_queue_work diff --git a/conf/cmi/varnish_purger.settings.assets.yml b/conf/cmi/varnish_purger.settings.assets.yml new file mode 100644 index 00000000..341450dc --- /dev/null +++ b/conf/cmi/varnish_purger.settings.assets.yml @@ -0,0 +1,30 @@ +uuid: 159f14b3-2fac-40e9-ab35-879b124b0748 +langcode: en +status: true +dependencies: { } +_core: + default_config_hash: W2iqfgCjeJZBrD986D1BhZ_gCyDeusZz5ahWyiDDLsM +id: assets +name: Assets +invalidationtype: regex +hostname: localhost +port: 6081 +path: '/[invalidation:expression]' +request_method: BAN +scheme: http +verify: '1' +headers: + - + field: X-VC-Purge-Method + value: regex + - + field: Host + value: localhost +body: null +body_content_type: null +runtime_measurement: true +timeout: 1.0 +connect_timeout: 1.0 +cooldown_time: 0.0 +max_requests: 100 +http_errors: true diff --git a/docker-compose.yml b/docker-compose.yml index a543bc2e..14960c7f 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -77,6 +77,7 @@ services: image: druidfi/varnish:6-drupal environment: VARNISH_BACKEND_HOST: "${COMPOSE_PROJECT_NAME}-app" + VARNISH_CACHE_STATIC_FILES: "1" depends_on: - app networks: diff --git a/public/sites/default/settings.php b/public/sites/default/settings.php index f33385ac..9006eeff 100755 --- a/public/sites/default/settings.php +++ b/public/sites/default/settings.php @@ -151,20 +151,6 @@ function drupal_get_env(string|array $variables) : mixed { } -if ($varnish_host = getenv('DRUPAL_VARNISH_HOST')) { - $config['varnish_purger.settings.default']['hostname'] = $varnish_host; - $config['varnish_purger.settings.varnish_purge_all']['hostname'] = $varnish_host; - - if (!isset($config['system.performance']['cache']['page']['max_age'])) { - $config['system.performance']['cache']['page']['max_age'] = 86400; - } -} - -if ($varnish_port = getenv('DRUPAL_VARNISH_PORT')) { - $config['varnish_purger.settings.default']['port'] = $varnish_port; - $config['varnish_purger.settings.varnish_purge_all']['port'] = $varnish_port; -} - if ($navigation_authentication_key = getenv('DRUPAL_NAVIGATION_API_KEY')) { $config['helfi_navigation.api']['key'] = $navigation_authentication_key; } @@ -182,34 +168,66 @@ function drupal_get_env(string|array $variables) : mixed { $config['helfi_api_base.environment_resolver.settings']['environment_name'] = getenv('APP_ENV'); $config['helfi_api_base.environment_resolver.settings']['project_name'] = getenv('PROJECT_NAME'); -// settings.php doesn't know about existing configuration yet so we can't -// just append new headers to an already existing headers array here. -// If you have configured any extra headers in your purge settings -// you must add them in your all.settings.php as well. -// @todo Replace this with config override service? -$config['varnish_purger.settings.default']['headers'] = [ - [ - 'field' => 'Cache-Tags', - 'value' => '[invalidation:expression]', - ], -]; +if ($varnish_host = getenv('DRUPAL_VARNISH_HOST')) { + // Cache everything for 1 year by default. + $config['system.performance']['cache']['page']['max_age'] = 31536000; -$config['varnish_purger.settings.varnish_purge_all']['headers'] = [ - [ - 'field' => 'X-VC-Purge-Method', - 'value' => 'regex', - ], -]; + $varnish_backend = parse_url($drush_options_uri, PHP_URL_HOST); -if ($varnish_purge_key = getenv('VARNISH_PURGE_KEY')) { - $config['varnish_purger.settings.default']['headers'][] = [ - 'field' => 'X-VC-Purge-Key', - 'value' => $varnish_purge_key, - ]; - $config['varnish_purger.settings.varnish_purge_all']['headers'][] = [ - 'field' => 'X-VC-Purge-Key', - 'value' => $varnish_purge_key, + if (getenv('APP_ENV') === 'local') { + // Varnish backend is something like varnish-helfi-kymp.docker.so on + // local env. + $varnish_backend = 'varnish-' . $varnish_backend; + } + + // settings.php doesn't know about existing configuration yet so we can't + // just append new headers to an already existing headers array here. + // If you have configured any extra headers in your purge settings + // you must add them in your all.settings.php as well. + // @todo Replace this with config override service? + $varnishConfiguration = [ + 'default' => [ + [ + 'field' => 'Cache-Tags', + 'value' => '[invalidation:expression]', + ], + ], + 'assets' => [ + [ + 'field' => 'X-VC-Purge-Method', + 'value' => 'regex', + ], + [ + 'field' => 'Host', + 'value' => $varnish_backend, + ], + ], + 'varnish_purge_all' => [ + [ + 'field' => 'X-VC-Purge-Method', + 'value' => 'regex', + ], + ], ]; + + foreach ($varnishConfiguration as $name => $headers) { + $config['varnish_purger.settings.' . $name]['hostname'] = $varnish_host; + + if ($varnish_port = getenv('DRUPAL_VARNISH_PORT')) { + $config['varnish_purger.settings.' . $name]['port'] = $varnish_port; + } + + foreach ($headers as $header) { + $config['varnish_purger.settings.' . $name]['headers'][] = $header; + } + + if ($varnish_purge_key = getenv('VARNISH_PURGE_KEY')) { + $config['varnish_purger.settings.' . $name]['headers'][] = [ + 'field' => 'X-VC-Purge-Key', + 'value' => $varnish_purge_key, + ]; + } + } } if ($stage_file_proxy_origin = getenv('STAGE_FILE_PROXY_ORIGIN')) {