Metadata-Version: 2.4
Name: ocyan.plugin.varnish
Version: 0.3.0
Summary: fragment caching with ESI
Home-page: https://git.mandelblog.com/mandel-plugins/ocyan.plugin.varnish
Author: Mandel
Author-email: info@mandelblog.com
Classifier: License :: Other/Proprietary License
Classifier: Framework :: Ocyan
Classifier: Environment :: Plugins
Requires-Python: >=3.6
Description-Content-Type: text/plain
Requires-Dist: ocyan.core<2,>=1.2.13
Requires-Dist: ocyan.plugin.wagtail<3,>=2.0.6
Requires-Dist: Django<6,>=5
Requires-Dist: django-oscar<5,>=4.1
Requires-Dist: requests<3,>=2.31
Requires-Dist: uwsgidecorators-fallback<1,>=0.0.5
Provides-Extra: test
Requires-Dist: ocyan.plugin.testing; extra == "test"
Requires-Dist: wheel<1,>=0.45; extra == "test"
Requires-Dist: empty_testproject; extra == "test"
Requires-Dist: pylint-django<3,>=2.6; extra == "test"
Requires-Dist: ruff<1,>=0.8; extra == "test"
Requires-Dist: vdt.versionplugin.wheel; extra == "test"
Requires-Dist: coverage<8,>=7; extra == "test"
Provides-Extra: cookie
Requires-Dist: ocyan.plugin.cookie_jar<1,>=0.2.2; extra == "cookie"
Provides-Extra: search
Requires-Dist: ocyan.plugin.oscar_elasticsearch<3,>=2.1.1; extra == "search"
Dynamic: author
Dynamic: author-email
Dynamic: classifier
Dynamic: description
Dynamic: description-content-type
Dynamic: home-page
Dynamic: provides-extra
Dynamic: requires-dist
Dynamic: requires-python
Dynamic: summary

Ocyan plugin varnish
====================

Support contract
----------------
The Python integration supports Python 3.10--3.12, Django 5.x, and Django
Oscar 4.1--4.x.  It requires ``ocyan.core`` 1.2.13 or newer (before 2),
``ocyan.plugin.wagtail`` 2.0.6 or newer (before 3), Requests 2.x, and the
uwsgi spool fallback.  Elasticsearch, Cookie Jar, and theme integrations are
optional extras and are not required for the cache middleware itself.

The Varnish service and native VMOD packages are deployment prerequisites, not
installed by this Python distribution.  The bundled theme extension is kept
only for legacy compatibility; it is not the MandelBlog frontend standard.

About varnish
-------------
fragment caching with ESI

Installation
------------
Add `ocyan.plugin.varnish` to your projects dependencies.

Clear cache
-----------

If you need to clear the cache after deployment:

http://127.0.0.1:8000/manage/clear-varnish/


Make packages
-------------

To build a package for vmod-csrftoken & vmod_vsthrottlev2 you can do the following on dev.mandelblog.com:
dev.mandelblog.com has the necessary dependencies installed to build the packages.

```
cd /root/ocyan.plugin.varnish/
# Checkout master or your branch with changes you want to build and test
git checkout <branch> && git pull

# Build vmod_csrftoken
cd vmod_csrftoken
./bootstrap
./configure
make
chown 644 src/.libs/*.so
fakeroot fpm --name=varnish-csrftoken -v 6.6.1 -d 'varnish >= 6.6.1' -s dir -t deb src/.libs/libvmod_csrftoken.so=/usr/lib/x86_64-linux-gnu/varnish/vmods/libvmod_csrftoken.so src/.libs/libvmod_csrftoken.lai=/usr/lib/x86_64-linux-gnu/varnish/vmods/libvmod_csrftoken.la

# Build vmod_vsthrottlev2
cd vmod_vsthrottlev2
./bootstrap
./configure
make
chown 644 src/.libs/*.so
fakeroot fpm --name=varnish-vsthrottlev2 -v 6.6.1 -d 'varnish >= 6.6.1' -s dir -t deb src/.libs/libvmod_vsthrottlev2.so=/usr/lib/x86_64-linux-gnu/varnish/vmods/libvmod_vsthrottlev2.so src/.libs/libvmod_vsthrottlev2.lai=/usr/lib/x86_64-linux-gnu/varnish/vmods/libvmod_vsthrottlev2.la
```

Now you'll have .deb packages in the vmod_csrftoken and vmod_vsthrottlev2 directories.

To build a package for varnish-modules

- clone the repo and checkout tag 0.18.0 for Varnish Cache 6.6
- ./bootstrap
- ./configure
- make
- chown 644 src/.libs/*.so
- fakeroot fpm --name=varnish-modules -v 6.6.1 -d 'varnish >= 6.6.1' -s dir -t deb src/.libs/libvmod_accept.so=/usr/lib/x86_64-linux-gnu/varnish/vmods/libvmod_accept.so  src/.libs/libvmod_accept.lai=/usr/lib/x86_64-linux-gnu/varnish/vmods/libvmod_accept.la src/.libs/libvmod_bodyaccess.so=/usr/lib/x86_64-linux-gnu/varnish/vmods/libvmod_bodyaccess.so src/.libs/libvmod_bodyaccess.lai=/usr/lib/x86_64-linux-gnu/varnish/vmods/libvmod_bodyaccess.la src/.libs/libvmod_header.so=/usr/lib/x86_64-linux-gnu/varnish/vmods/libvmod_header.so src/.libs/libvmod_header.lai=/usr/lib/x86_64-linux-gnu/varnish/vmods/libvmod_header.la src/.libs/libvmod_saintmode.so=/usr/lib/x86_64-linux-gnu/varnish/vmods/libvmod_saintmode.so src/.libs/libvmod_saintmode.lai=/usr/lib/x86_64-linux-gnu/varnish/vmods/libvmod_saintmode.la src/.libs/libvmod_str.so=/usr/lib/x86_64-linux-gnu/varnish/vmods/libvmod_str.so src/.libs/libvmod_str.lai=/usr/lib/x86_64-linux-gnu/varnish/vmods/libvmod_str.la src/.libs/libvmod_tcp.so=/usr/lib/x86_64-linux-gnu/varnish/vmods/libvmod_tcp.so src/.libs/libvmod_tcp.lai=/usr/lib/x86_64-linux-gnu/varnish/vmods/libvmod_tcp.la src/.libs/libvmod_var.so=/usr/lib/x86_64-linux-gnu/varnish/vmods/libvmod_var.so src/.libs/libvmod_var.lai=/usr/lib/x86_64-linux-gnu/varnish/vmods/libvmod_var.la src/.libs/libvmod_vsthrottle.so=/usr/lib/x86_64-linux-gnu/varnish/vmods/libvmod_vsthrottle.so src/.libs/libvmod_vsthrottle.lai=/usr/lib/x86_64-linux-gnu/varnish/vmods/libvmod_vsthrottle.la src/.libs/libvmod_xkey.so=/usr/lib/x86_64-linux-gnu/varnish/vmods/libvmod_xkey.so src/.libs/libvmod_xkey.lai=/usr/lib/x86_64-linux-gnu/varnish/vmods/libvmod_xkey.la

Alternatively, build the packages (vmod_csrftoken & vmod_vsthrottlev2) using Docker on your local machine:
```
docker build -f Dockerfile.vmod -t varnish-modules-image .
docker run -d --name varnish-modules-container varnish-modules-image
docker cp varnish-modules-container:/output_debs/ ./output_debs
```

Now you have the packages in the output_debs folder locally.

Run locally
-----------

Make sure to have varnish installed with all the required mods and that it is in your path

then:

make run
sudo nginx -c $PWD/vcl/nginx/nginx.conf -e /dev/stdout
uwsgi --ini vcl/uwsgi/uwsgi.ini


Run locally in a project
------------------------

First, after configuring varnish start varnish locally, make sure that you are in the
virtual environment of ocyan.plugin.varnish, then run:
- export PATH='{path to varnish}/sbin':$PATH
- make run

After that, in change directory to `ocyan.plugin.varnish/vcl/nginx/` and update
`root /srv/www/example;` to `root {path to your folder}` in `nginx.conf` and run:
- nginx -c $PWD/nginx.conf -e /dev/stdout

Then, go to the project folder and add `socket = /tmp/uwsgi.sock` in uwsgi-dev.ini file.
Now run:
- uwsgi --ini uwsgi-dev.ini


Run locally with docker
-----------------------

Make sure docker and docker-compose are installed on your machine.

Run the following commands:
```
PROJECT_PATH=/path/to/your/project/ docker-compose build
PROJECT_PATH=/path/to/your/project/ docker-compose up
```

`PROJECT_PATH` is the path to your project folder.
Eg; if you have your projects stored in `/Users/henk/projects/` and you have a project called `poep` then you should run:
```
PROJECT_PATH=/Users/henk/projects/poep/ docker-compose up
```

Make sure you have your project running with UWSGI and have the socket configuration set to;
```
# Add this to end of file of uwsgi-dev.ini
socket = /tmp/uwsgi.sock
```
And run with uwsgi by typing `uwsgi --ini uwsgi-dev.ini` in your terminal (make sure uwsgi is installed, if not run `pip install uwsgi`).

Now when you go to `http://localhost/` (Note: NO port) you should see your project running.
The project is now served with nginx, which forwards requests to varnish, which forwards requests to the uwsgi server.
