Mailing List Archive

RE: varnish-misc Digest, Vol 160, Issue 3
Sent from my Galaxy Tab A (2016)-------- Original message --------From: varnish-misc-request@varnish-cache.org Date: 9/10/2019 12:38 PM (GMT+05:45) To: varnish-misc@varnish-cache.org Subject: varnish-misc Digest, Vol 160, Issue 3 Send varnish-misc mailing list submissions to varnish-misc@varnish-cache.orgTo subscribe or unsubscribe via the World Wide Web, visit https://www.varnish-cache.org/lists/mailman/listinfo/varnish-miscor, via email, send a message with subject or body 'help' to varnish-misc-request@varnish-cache.orgYou can reach the person managing the list at varnish-misc-owner@varnish-cache.orgWhen replying, please edit your Subject line so it is more specificthan "Re: Contents of varnish-misc digest..."Today's Topics:   1. Re: Environment variables in VCL (Bender, Charles)   2. Re: Environment variables in VCL (Guillaume Quintard)   3. Re: Environment variables in VCL (Poul-Henning Kamp)   4. Re: Environment variables in VCL (Guillaume Quintard)----------------------------------------------------------------------Message: 1Date: Tue, 10 Sep 2019 00:15:42 +0000From: "Bender, Charles" <charles@beachcamera.com>To: Hugues Alary <hugues@betabrand.com>, varnish-misc <varnish-misc@varnish-cache.org>Subject: Re: Environment variables in VCLMessage-ID: <DAF960C1-B889-4942-A60B-3FCC64695A8D@beachcamera.com>Content-Type: text/plain; charset="utf-8"Looking at a VCL I use to set hostname and this seems to work-sub vcl_deliver {  set resp.http.X-Cache-Node = server.hostname;}Maybe you can use in form of server.environmental_variableFrom: varnish-misc <varnish-misc-bounces+charles=beachcamera.com@varnish-cache.org> on behalf of Hugues Alary <hugues@betabrand.com>Date: Monday, September 9, 2019 at 6:09 PMTo: varnish-misc <varnish-misc@varnish-cache.org>Subject: Environment variables in VCLHi there,I'm using Varnish in a Kubernetes cluster and my configuration needs to use environment variables.More specifically, I'm trying to declare a `backend` with a `.host` whose value is an environment variable.backend b0 {  .host = "$ENVIRONMENT_VARIABLE_HOSTNAME";  .port = "80";  .connect_timeout = 300s;  .first_byte_timeout = 300s;  .between_bytes_timeout = 300s;}This doesn't work. It tried using the std.get_env() function but it doesn't work in this context.Is there any way to use environment variables in VCL, or do I have to create a configuration template?Thanks for your help,Cheers,-Hugues-------------- next part --------------An HTML attachment was scrubbed...URL: <https://www.varnish-cache.org/lists/pipermail/varnish-misc/attachments/20190910/672db2ce/attachment-0001.html>------------------------------Message: 2Date: Tue, 10 Sep 2019 07:38:44 +0200From: Guillaume Quintard <guillaume@varnish-software.com>To: "Bender, Charles" <charles@beachcamera.com>Cc: Hugues Alary <hugues@betabrand.com>, varnish-misc <varnish-misc@varnish-cache.org>Subject: Re: Environment variables in VCLMessage-ID: <CAJ6ZYQy5RnBjfCs88re6-hMfsQvyuzbOkHoofQ_c+suQNRQjig@mail.gmail.com>Content-Type: text/plain; charset="utf-8"Hi,The trouble is that the backends are C structures created when you compilethe VCL, but std.getenv() is called when you use the compile VCL, so thatway too late.I see two ways:- use a dynamic backend vmod (like vmod_goto), allowing you to regularlyinterrogate DNS a build an elastic director- create a static backend point to you k8s proxy, and just setreq.http.host to whatever value you want.The last one is two of course create a template, but remember that varnishresolves domain names in static backend when it compiles the VCL, so theresolved IP may not be right all the time.-- Guillaume QuintardOn Tue, Sep 10, 2019 at 2:17 AM Bender, Charles <charles@beachcamera.com>wrote:> Looking at a VCL I use to set hostname and this seems to work->>>> sub vcl_deliver {>>   set resp.http.X-Cache-Node = server.hostname;>> }>>>> Maybe you can use in form of server.environmental_variable>>>> *From: *varnish-misc <varnish-misc-bounces+charles=> beachcamera.com@varnish-cache.org> on behalf of Hugues Alary <> hugues@betabrand.com>> *Date: *Monday, September 9, 2019 at 6:09 PM> *To: *varnish-misc <varnish-misc@varnish-cache.org>> *Subject: *Environment variables in VCL>>>> Hi there,>>>> I'm using Varnish in a Kubernetes cluster and my configuration needs to> use environment variables.>>>> More specifically, I'm trying to declare a `backend` with a `.host` whose> value is an environment variable.>>> backend b0 {>   .host = "*$ENVIRONMENT_VARIABLE_HOSTNAME*";>   .port = "80";>   .connect_timeout = 300s;>   .first_byte_timeout = 300s;>   .between_bytes_timeout = 300s;>> }>>>> This doesn't work. It tried using the std.get_env() function but it> doesn't work in this context.>>>> *Is there any way to use environment variables in VCL, or do I have to> create a configuration template?*>>>> Thanks for your help,>>>> Cheers,>> -Hugues>>> _______________________________________________> varnish-misc mailing list> varnish-misc@varnish-cache.org> https://www.varnish-cache.org/lists/mailman/listinfo/varnish-misc>-------------- next part --------------An HTML attachment was scrubbed...URL: <https://www.varnish-cache.org/lists/pipermail/varnish-misc/attachments/20190910/15f9a551/attachment-0001.html>------------------------------Message: 3Date: Tue, 10 Sep 2019 06:44:45 +0000From: "Poul-Henning Kamp" <phk@phk.freebsd.dk>To: Guillaume Quintard <guillaume@varnish-software.com>Cc: "Bender, Charles" <charles@beachcamera.com>, varnish-misc <varnish-misc@varnish-cache.org>Subject: Re: Environment variables in VCLMessage-ID: <14936.1568097885@critter.freebsd.dk>Content-Type: text/plain; charset="us-ascii"--------In message <CAJ6ZYQy5RnBjfCs88re6-hMfsQvyuzbOkHoofQ_c+suQNRQjig@mail.gmail.com>, Guillaume Quintard writes:>I see two ways:There is a third way:You can use: include "somefile"anywhere and everywhere in a VCL program.Before you start your varnishd, do this in a shell script: echo "\"$ENVIRONMENT_VARIABLE_HOSTNAME\"" > /somewhere/hostname.vclThen in VCL: backend b0 { .host = include "/somewhere/hostname.vcl" ; .port 80 ...-- Poul-Henning Kamp       | UNIX since Zilog Zeus 3.20phk@FreeBSD.ORG         | TCP/IP since RFC 956FreeBSD committer       | BSD since 4.3-tahoe    Never attribute to malice what can adequately be explained by incompetence.------------------------------Message: 4Date: Tue, 10 Sep 2019 08:52:53 +0200From: Guillaume Quintard <guillaume@varnish-software.com>To: Poul-Henning Kamp <phk@phk.freebsd.dk>Cc: "Bender, Charles" <charles@beachcamera.com>, varnish-misc <varnish-misc@varnish-cache.org>Subject: Re: Environment variables in VCLMessage-ID: <CAJ6ZYQzhdbagqWzVmBDbs7uOS+SY+0BNUCYaJn3fVpXBqkfDCQ@mail.gmail.com>Content-Type: text/plain; charset="utf-8"True, but that amounts to template processing :-)-- Guillaume QuintardOn Tue, Sep 10, 2019 at 8:44 AM Poul-Henning Kamp <phk@phk.freebsd.dk>wrote:> --------> In message <> CAJ6ZYQy5RnBjfCs88re6-hMfsQvyuzbOkHoofQ_c+suQNRQjig@mail.gmail.com>> , Guillaume Quintard writes:>> >I see two ways:>> There is a third way:>> You can use:>>         include "somefile">> anywhere and everywhere in a VCL program.>> Before you start your varnishd, do this in a shell script:>>         echo "\"$ENVIRONMENT_VARIABLE_HOSTNAME\"" > /somewhere/hostname.vcl>> Then in VCL:>>         backend b0 {>                 .host = include "/somewhere/hostname.vcl" ;>                 .port 80>                 ...>>>> --> Poul-Henning Kamp       | UNIX since Zilog Zeus 3.20> phk@FreeBSD.ORG         | TCP/IP since RFC 956> FreeBSD committer       | BSD since 4.3-tahoe> Never attribute to malice what can adequately be explained by incompetence.>-------------- next part --------------An HTML attachment was scrubbed...URL: <https://www.varnish-cache.org/lists/pipermail/varnish-misc/attachments/20190910/9d6ef430/attachment.html>------------------------------Subject: Digest Footer_______________________________________________varnish-misc mailing listvarnish-misc@varnish-cache.orghttps://www.varnish-cache.org/lists/mailman/listinfo/varnish-misc------------------------------End of varnish-misc Digest, Vol 160, Issue 3********************************************