diff --git a/.ddev/addon-metadata/varnish/manifest.yaml b/.ddev/addon-metadata/varnish/manifest.yaml new file mode 100644 index 0000000..88d88e7 --- /dev/null +++ b/.ddev/addon-metadata/varnish/manifest.yaml @@ -0,0 +1,19 @@ +name: varnish +repository: ddev/ddev-varnish +version: v0.2.3 +install_date: "2024-08-13T15:59:06+03:00" +project_files: + - docker-compose.varnish.yaml + - varnish + - commands/varnish +global_files: [] +removal_actions: + - | + #ddev-nodisplay + if [ -f docker-compose.varnish_extras.yaml ]; then + if grep -q '#ddev-generated' docker-compose.varnish_extras.yaml; then + rm -f docker-compose.varnish_extras.yaml + else + echo "Unwilling to remove '$DDEV_APPROOT/.ddev/docker-compose.varnish_extras.yaml' because it does not have #ddev-generated in it; you can manually delete it if it is safe to delete." + fi + fi diff --git a/.ddev/commands/varnish/varnishadm b/.ddev/commands/varnish/varnishadm new file mode 100755 index 0000000..ff195b3 --- /dev/null +++ b/.ddev/commands/varnish/varnishadm @@ -0,0 +1,12 @@ +#!/bin/bash + +## #ddev-generated +## Description: Control a running Varnish instance +## Usage: varnishadm [flags] [args] +## Example: "ddev varnishadm" + +# This example runs inside the varnish container. +# Note that this requires that /mnt/ddev_config be mounted +# into the varnish container. + +varnishadm "$@" diff --git a/.ddev/commands/varnish/varnishd b/.ddev/commands/varnish/varnishd new file mode 100755 index 0000000..a934247 --- /dev/null +++ b/.ddev/commands/varnish/varnishd @@ -0,0 +1,14 @@ +#!/bin/bash + +## #ddev-generated +## Description: Varnish-cli +## Usage: varnishd [flags] [args] +## Example: "ddev varnishd -d" for CLI in foreground. +## Example: "ddev varnishd -T" to connect with varnishadm or telnet. +## Example: "ddev varnishd -M" to connect back to a listening service pushing the CLI to that service. + +# This example runs inside the varnish container. +# Note that this requires that /mnt/ddev_config be mounted +# into the varnish container. + +varnishd "$@" diff --git a/.ddev/commands/varnish/varnishhist b/.ddev/commands/varnish/varnishhist new file mode 100755 index 0000000..77216c7 --- /dev/null +++ b/.ddev/commands/varnish/varnishhist @@ -0,0 +1,12 @@ +#!/bin/bash + +## #ddev-generated +## Description: Display Varnish request histogram +## Usage: varnishhist [flags] [args] +## Example: "ddev varnishhist" + +# This example runs inside the varnish container. +# Note that this requires that /mnt/ddev_config be mounted +# into the varnish container. + +varnishhist "$@" diff --git a/.ddev/commands/varnish/varnishlog b/.ddev/commands/varnish/varnishlog new file mode 100755 index 0000000..c107f50 --- /dev/null +++ b/.ddev/commands/varnish/varnishlog @@ -0,0 +1,12 @@ +#!/bin/bash + +## #ddev-generated +## Description: Display Varnish logs +## Usage: varnishlog [flags] [args] +## Example: "ddev varnishlog" + +# This example runs inside the varnish container. +# Note that this requires that /mnt/ddev_config be mounted +# into the varnish container. + +varnishlog "$@" diff --git a/.ddev/commands/varnish/varnishncsa b/.ddev/commands/varnish/varnishncsa new file mode 100755 index 0000000..499da9d --- /dev/null +++ b/.ddev/commands/varnish/varnishncsa @@ -0,0 +1,12 @@ +#!/bin/bash + +## #ddev-generated +## Description: Display Varnish logs in Apache / NCSA combined log format +## Usage: varnishncsa [flags] [args] +## Example: "ddev varnishncsa" + +# This example runs inside the varnish container. +# Note that this requires that /mnt/ddev_config be mounted +# into the varnish container. + +varnishncsa "$@" diff --git a/.ddev/commands/varnish/varnishstat b/.ddev/commands/varnish/varnishstat new file mode 100755 index 0000000..f28733e --- /dev/null +++ b/.ddev/commands/varnish/varnishstat @@ -0,0 +1,12 @@ +#!/bin/bash + +## #ddev-generated +## Description: Display Varnish Cache statistics +## Usage: varnishstat [flags] [args] +## Example: "ddev varnishstat" + +# This example runs inside the varnish container. +# Note that this requires that /mnt/ddev_config be mounted +# into the varnish container. + +varnishstat "$@" diff --git a/.ddev/commands/varnish/varnishtest b/.ddev/commands/varnish/varnishtest new file mode 100755 index 0000000..2600b0d --- /dev/null +++ b/.ddev/commands/varnish/varnishtest @@ -0,0 +1,12 @@ +#!/bin/bash + +## #ddev-generated +## Description: Test program for Varnish +## Usage: varnishtest [flags] [args] +## Example: "ddev varnishtest" + +# This example runs inside the varnish container. +# Note that this requires that /mnt/ddev_config be mounted +# into the varnish container. + +varnishtest "$@" diff --git a/.ddev/commands/varnish/varnishtop b/.ddev/commands/varnish/varnishtop new file mode 100755 index 0000000..e83d5e7 --- /dev/null +++ b/.ddev/commands/varnish/varnishtop @@ -0,0 +1,12 @@ +#!/bin/bash + +## #ddev-generated +## Description: Display Varnish log entry ranking +## Usage: varnishtop [flags] [args] +## Example: "ddev varnishtop" + +# This example runs inside the varnish container. +# Note that this requires that /mnt/ddev_config be mounted +# into the varnish container. + +varnishtop "$@" diff --git a/.ddev/docker-compose.varnish.yaml b/.ddev/docker-compose.varnish.yaml new file mode 100644 index 0000000..7ecfe7f --- /dev/null +++ b/.ddev/docker-compose.varnish.yaml @@ -0,0 +1,31 @@ +#ddev-generated +services: + varnish: + container_name: ddev-${DDEV_SITENAME}-varnish + image: varnish:6.0 + # These labels ensure this service is discoverable by ddev. + labels: + com.ddev.site-name: ${DDEV_SITENAME} + com.ddev.approot: $DDEV_APPROOT + environment: + # This defines the host name the service should be accessible from. This + # will be sitename.ddev.site. + # This is the first half of the trick that puts varnish "in front of" the + # web container, just by switching the names. + - VIRTUAL_HOST=$DDEV_HOSTNAME + # This defines the ports the service should be accessible from at + # sitename.ddev.site. + - HTTPS_EXPOSE=443:80,8026:8025 + - HTTP_EXPOSE=80:80,8025:8025 + volumes: + # This exposes a mount to the host system `.ddev/varnish` directory where + # your default.vcl should be. + - "./varnish:/etc/varnish" + - ".:/mnt/ddev_config" + depends_on: + - web + # Add mailhog support + expose: + - "8025" + entrypoint: + /usr/local/bin/docker-varnish-entrypoint -a 0.0.0.0:8025 \ No newline at end of file diff --git a/.ddev/docker-compose.varnish_extras.yaml b/.ddev/docker-compose.varnish_extras.yaml new file mode 100644 index 0000000..fc6857d --- /dev/null +++ b/.ddev/docker-compose.varnish_extras.yaml @@ -0,0 +1,7 @@ +#ddev-generated +# This is the second half of the trick that puts varnish "in front of" the web +# container, just by switching the names. +services: + web: + environment: + - VIRTUAL_HOST=novarnish.drupal-project.ddev.site diff --git a/.ddev/varnish/default.vcl b/.ddev/varnish/default.vcl new file mode 100644 index 0000000..24d5a59 --- /dev/null +++ b/.ddev/varnish/default.vcl @@ -0,0 +1,38 @@ +# For a more advanced example see https://github.com/mattiasgeniar/varnish-6.0-configuration-templates +vcl 4.1; +import std; + +backend default { + .host = "web"; + .port = "80"; +} + +# @see: https://github.com/wunderio/charts/blob/master/drupal/templates/varnish-configmap-vcl.yaml +# The routine when we deliver the HTTP request to the user +# Last chance to modify headers that are sent to the client. +sub vcl_deliver { + # Called before a cached object is delivered to the client. + + # Add debug header to see if it's a HIT/MISS and the number of hits, disable when not needed. + if (obj.hits > 0) { + set resp.http.X-W-Cache = "HIT"; + set resp.http.X-W-Cache-Hits = obj.hits; + } else { + set resp.http.X-W-Cache = "MISS"; + } +} + +sub vcl_recv { + if (std.port(server.ip) == 8025) { + return (synth(750)); + } +} + +sub vcl_synth { + if (resp.status == 750) { + set resp.status = 301; + set resp.http.location = req.http.X-Forwarded-Proto + "://novarnish." + req.http.Host + req.url; + set resp.reason = "Moved"; + return (deliver); + } +}