<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html;
      charset=windows-1252">
  </head>
  <body>
    <p>Hi,</p>
    <p>I did a similar thing with mapfiles and substituted colors and
      other info with sed. I had the values in a csv file. Then read the
      values into a <span class="pl-c">associative array in bash.</span></p>
    <p><span class="pl-c">Finally I had a very long sed script to do the
        substitutitons. <br>
      </span></p>
    <p><span class="pl-c">You can find the example here: 
<a class="moz-txt-link-freetext" href="https://github.com/LarsSchy/SMAC-M/blob/master/chart-installation/generate_map_files/scripts/process_layer_colors.sh#L69">https://github.com/LarsSchy/SMAC-M/blob/master/chart-installation/generate_map_files/scripts/process_layer_colors.sh#L69</a>
        <br>
      </span></p>
    <p><span class="pl-c">The reading of values into the array, Line
        71-77 and the sed part Line 108-240.   The template mapfile had
        the variables to be substitued in curli brackets, ie </span><span
        class="pl-c"><span class="pl-s">{PATH} .<br>
        </span></span></p>
    <p><span class="pl-c">Just food for thought.</span></p>
    <p><span class="pl-c">/Lars S.<br>
      </span></p>
    <div class="moz-cite-prefix">Den 2020-12-18 kl. 11:02, skrev Schmid
      Andreas:<br>
    </div>
    <blockquote type="cite"
      cite="mid:2eec1b1cf26e42fbb317c53af4cecb78@bd.so.ch">
      <pre class="moz-quote-pre" wrap="">Thank you, Dave, for sharing your solution. So as the differences between my config files are small, I guess I'm going to solve it with a sed script that reads the actual values from environment variables. And the templating language approach for sure would be the way to go for more complex cases.

I'm actually using this in a MapCache Docker image too, that should include the config file for convenience.

Best regards,
Andy


</pre>
      <blockquote type="cite">
        <pre class="moz-quote-pre" wrap="">-----Ursprüngliche Nachricht-----
Von: mapserver-users <a class="moz-txt-link-rfc2396E" href="mailto:mapserver-users-bounces@lists.osgeo.org"><mapserver-users-bounces@lists.osgeo.org></a> Im Auftrag
von David Hoese
Gesendet: Donnerstag, 17. Dezember 2020 16:48
An: <a class="moz-txt-link-abbreviated" href="mailto:mapserver-users@lists.osgeo.org">mapserver-users@lists.osgeo.org</a>
Betreff: Re: [mapserver-users] Parametrizing a MapCache config file

Hi,

I had a similar need where I was running MapCache in a docker container
and needed the config to change based on some user-provided environment
variables. I ended up writing a python script that uses the Jinja
templating language. That way I could write a really complex config
"template" and run my python script when the docker container started and
produce the desired output config. It was extra nice for me because my
jinja template allowed me to do "for" loops and in my case I had a lot of
the same grids and tilesets that were only different by one or two
parameters.

It would be nice if there was something builtin, but I think a sed script
or something like my Jinja templating are the easiest solutions.

Dave

Example
-------

     <!--    Overlays -->
     <source name="{{ plat }}_{{ inst }}_borders" type="wms">
         <getmap>
             <params>
                 <FORMAT>rgba</FORMAT>
                 <LAYERS>bw_map</LAYERS>
             </params>
         </getmap>
         <http>
             <url>http://{{ wms_host }}:{{ wms_port }}/wms/borders</url>
             <connection_timeout>10</connection_timeout>
             <timeout>15</timeout>
         </http>
     </source>

Python (trimmed down)
---------------------

     tmpl_vars = {'wms_host': 'my_host', 'wms_port': 8888, 'plat':
'test', 'inst': 'example'}
     with open(args.template_fn, 'r') as tmpl_file:
         template = jinja2.Template(tmpl_file.read())
         print(template.render(tmpl_vars))

I then run it like:

python render.py > /path/to/output_config.xml

On 12/17/20 7:26 AM, Schmid Andreas wrote:
</pre>
        <blockquote type="cite">
          <pre class="moz-quote-pre" wrap="">Hi list

I'm looking for a way how I could parametrize a MapCache XML config
</pre>
        </blockquote>
        <pre class="moz-quote-pre" wrap="">file. Up to now, I have three config files: One that I use for development
purposes, one for running MapCache in the test environment, and one for
the production environment. The files differ only in the URL of the
service metadata, the URL of the http-source, and whether the demo service
is enabled. So when I change something in the file, I always need to make
sure that I make the same change in the other files. Which I don't really
like because it's error-prone.
</pre>
        <blockquote type="cite">
          <pre class="moz-quote-pre" wrap="">
One solution that I can think of is keeping only one file and putting
</pre>
        </blockquote>
        <pre class="moz-quote-pre" wrap="">placeholders in the appropriate places. And then running a sed-Script over
it before deploying it.
</pre>
        <blockquote type="cite">
          <pre class="moz-quote-pre" wrap="">
But maybe someone knows of a smarter idea for this?

Thanks a lot,
Andy

_______________________________________________
mapserver-users mailing list
<a class="moz-txt-link-abbreviated" href="mailto:mapserver-users@lists.osgeo.org">mapserver-users@lists.osgeo.org</a>
<a class="moz-txt-link-freetext" href="https://lists.osgeo.org/mailman/listinfo/mapserver-users">https://lists.osgeo.org/mailman/listinfo/mapserver-users</a>

</pre>
        </blockquote>
        <pre class="moz-quote-pre" wrap="">_______________________________________________
mapserver-users mailing list
<a class="moz-txt-link-abbreviated" href="mailto:mapserver-users@lists.osgeo.org">mapserver-users@lists.osgeo.org</a>
<a class="moz-txt-link-freetext" href="https://lists.osgeo.org/mailman/listinfo/mapserver-users">https://lists.osgeo.org/mailman/listinfo/mapserver-users</a>
</pre>
      </blockquote>
      <pre class="moz-quote-pre" wrap="">_______________________________________________
mapserver-users mailing list
<a class="moz-txt-link-abbreviated" href="mailto:mapserver-users@lists.osgeo.org">mapserver-users@lists.osgeo.org</a>
<a class="moz-txt-link-freetext" href="https://lists.osgeo.org/mailman/listinfo/mapserver-users">https://lists.osgeo.org/mailman/listinfo/mapserver-users</a>
</pre>
    </blockquote>
  </body>
</html>