Home About News Products Blog

Variables in external files


#1

Hey,

We’re using the devpop locally against a local version of our site for development. We’re also using a Dev branch on the aperture Git repository.

I’m wondering how I can store two domains for each environment in an external file in the repository, include those variables in my defaul.vcl so that I don’t have to worry about screwing up the domains when I’m moving stuff from Dev branch to Production branch.

I got it working with the following:

# values.vcl
vcl 4.0;
import var;
sub vcl_recv {
    var.set("www-domain", "www.domain.local");
    var.set("admin-domain", "admin.domain.local");
}

Then:

# default.vcl
vcl 4.0;
sub vcl_deliver {
    set resp.http.varnish-debug-www-domain = var.get("www-domain");
    set resp.http.varnish-debug-admin-domain = var.get("admin-domain");
}

This works, I tried to use vcl_init in values.vcl, but it didn’t work. Is there a better way?


#2

Hey Scott,

That looks the right way to do it. One thing you can do is to set global variables that persist across requests. Here is some documentation on how to do it : https://github.com/varnish/varnish-modules/blob/master/docs/vmod_var.rst


#3

Excellent, I used those in vcl_init and it worked perfectly. Thanks!