mikexstudios / dokku-nginx-alt

Alternative nginx plugin for dokku. Supports multiple domains and custom nginx.conf.
35 stars 26 forks source link

Use envsubst rather than perl #9

Closed stuartpb closed 10 years ago

stuartpb commented 10 years ago

Withdrawn, templates would need to be changed.

mikexstudios commented 10 years ago

Thanks @stuartpb. Yes, I originally used envsubst but found that it would conflict with nginx variables (that look like bash vars). So I went with the perl solution instead, having ${myvar} be bash vars and $myvar untouched for nginx vars.

stuartpb commented 10 years ago

You should be able to backslash-escape the nginx variables, akin to the way they're written in the heredoc versions of the templates. But yes, the curly-brace-restricted version does make the templates a little cleaner looking (although my personal tastes hew closer to wider compatibility).

mikexstudios commented 10 years ago

I recall trying that, but for some reason it did not work. It think it was that the version of envsubst in ubuntu 13.10 had some bug or was too old and ended up ignoring the backslash. I did not check to see if 14.04 resolved the issue.

stuartpb commented 10 years ago

Haha, wow, guess I spoke too soon (I hadn't tried using it and it has essentially no documentation, so I just assumed like an ass). Just tested it and can confirm I encountered the same issue. (Checking the source confirms this is the expected behavior.)

Anyway, if you'd still like to use $VAR-style substitutions and backslash-escapes, here's an extended version of the Perl one-liner I wrote yesterday to handle that:

perl -pie 's;(\\*)(\$([a-zA-Z_][a-zA-Z_0-9]*)|\$\{([a-zA-Z_][a-zA-Z_0-9]*)\})?;substr($1,0,int(length($1)/2)).($2&&length($1)%2?$2:$ENV{$3||$4});eg'
mikexstudios commented 10 years ago

No worries, thanks for the updated one-liner. I'll test envsubst again sometime and if that works on 14.04, I'll use your perl one-liner as a fallback for 13.10.

stuartpb commented 10 years ago

I doubt envsubst will be getting backslash escapes any time soon, as its source code gives no indication that it would be under consideration.

mikexstudios commented 10 years ago

Ah, I see. Thank you for taking the time to check envsubst's source.