-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add sites-enabled ENV variable interpolation
All credit to shepmaster/nginx-template-image for the implementation
- Loading branch information
1 parent
7c1ca3a
commit b87d6ba
Showing
9 changed files
with
126 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,9 @@ MAINTAINER Abe Voelker <[email protected]> | |
# Provide a custom nginx.conf, tweaked for Docker use | ||
COPY nginx.conf /data/conf/ | ||
|
||
# Add nginx templating helper scripts | ||
COPY bin/ /usr/sbin/ | ||
|
||
# Ensure UTF-8 locale | ||
COPY locale /etc/default/locale | ||
RUN \ | ||
|
@@ -20,13 +23,17 @@ RUN \ | |
DEBIAN_FRONTEND=noninteractive apt-get install -y nginx &&\ | ||
# Copy default config files to /data | ||
/bin/bash -c "cp -a /etc/nginx/{conf.d,sites-enabled} /data/" &&\ | ||
# Create /data/sites-templates directory | ||
mkdir /data/sites-templates &&\ | ||
chmod 0755 /data/sites-templates &&\ | ||
# Clean up APT and temporary files when done | ||
apt-get clean &&\ | ||
DEBIAN_FRONTEND=noninteractive apt-get remove --purge -y software-properties-common &&\ | ||
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* | ||
|
||
VOLUME ["/var/cache/nginx", "/var/log/nginx"] | ||
|
||
ENTRYPOINT ["entrypoint.sh"] | ||
CMD ["nginx", "-c", "/data/conf/nginx.conf"] | ||
|
||
EXPOSE 80 443 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#!/bin/bash | ||
|
||
set -eu | ||
|
||
render-templates.sh /data/sites-templates /data/sites-enabled | ||
exec $@ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#!/bin/bash | ||
|
||
set -eu | ||
|
||
indir="${1}" | ||
outdir="${2}" | ||
|
||
function template_files() { | ||
find "${indir}" \ | ||
-mindepth 1 \ | ||
-maxdepth 1 \ | ||
-name '*.tmpl' \ | ||
-print0 | ||
} | ||
|
||
function non_template_files() { | ||
find "${indir}" \ | ||
-mindepth 1 \ | ||
-maxdepth 1 \ | ||
-not \ | ||
-name '*.tmpl' \ | ||
-print0 | ||
} | ||
|
||
rm -rf "${outdir}" | ||
mkdir -p "${outdir}" | ||
template_files | xargs -0 substitute-env-vars.sh "${outdir}" | ||
non_template_files | xargs -0 -I{} ln -s {} "${outdir}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#!/bin/bash | ||
|
||
set -eu | ||
|
||
output_dir=$1 | ||
shift | ||
files=$@ | ||
|
||
function fill_in() { | ||
perl -p -e 's/\$\{([^}]+)\}/defined $ENV{$1} ? $ENV{$1} : "\${$1}"/eg' "${1}" | ||
} | ||
|
||
function output_filename { | ||
local destname=$(basename "${1}" '.tmpl') | ||
echo "${output_dir}/${destname}" | ||
} | ||
|
||
for file in $files; do | ||
fill_in "${file}" > $(output_filename "${file}") | ||
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,9 @@ MAINTAINER Abe Voelker <[email protected]> | |
# Provide a custom nginx.conf, tweaked for Docker use | ||
COPY nginx.conf /data/conf/ | ||
|
||
# Add nginx templating helper scripts | ||
COPY bin/ /usr/sbin/ | ||
|
||
# Ensure UTF-8 locale | ||
COPY locale /etc/default/locale | ||
RUN \ | ||
|
@@ -20,13 +23,17 @@ RUN \ | |
DEBIAN_FRONTEND=noninteractive apt-get install -y nginx &&\ | ||
# Copy default config files to /data | ||
/bin/bash -c "cp -a /etc/nginx/{conf.d,sites-enabled} /data/" &&\ | ||
# Create /data/sites-templates directory | ||
mkdir /data/sites-templates &&\ | ||
chmod 0755 /data/sites-templates &&\ | ||
# Clean up APT and temporary files when done | ||
apt-get clean &&\ | ||
DEBIAN_FRONTEND=noninteractive apt-get remove --purge -y software-properties-common &&\ | ||
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* | ||
|
||
VOLUME ["/var/cache/nginx", "/var/log/nginx"] | ||
|
||
ENTRYPOINT ["entrypoint.sh"] | ||
CMD ["nginx", "-c", "/data/conf/nginx.conf"] | ||
|
||
EXPOSE 80 443 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#!/bin/bash | ||
|
||
set -eu | ||
|
||
render-templates.sh /data/sites-templates /data/sites-enabled | ||
exec $@ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#!/bin/bash | ||
|
||
set -eu | ||
|
||
indir="${1}" | ||
outdir="${2}" | ||
|
||
function template_files() { | ||
find "${indir}" \ | ||
-mindepth 1 \ | ||
-maxdepth 1 \ | ||
-name '*.tmpl' \ | ||
-print0 | ||
} | ||
|
||
function non_template_files() { | ||
find "${indir}" \ | ||
-mindepth 1 \ | ||
-maxdepth 1 \ | ||
-not \ | ||
-name '*.tmpl' \ | ||
-print0 | ||
} | ||
|
||
rm -rf "${outdir}" | ||
mkdir -p "${outdir}" | ||
template_files | xargs -0 substitute-env-vars.sh "${outdir}" | ||
non_template_files | xargs -0 -I{} ln -s {} "${outdir}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#!/bin/bash | ||
|
||
set -eu | ||
|
||
output_dir=$1 | ||
shift | ||
files=$@ | ||
|
||
function fill_in() { | ||
perl -p -e 's/\$\{([^}]+)\}/defined $ENV{$1} ? $ENV{$1} : "\${$1}"/eg' "${1}" | ||
} | ||
|
||
function output_filename { | ||
local destname=$(basename "${1}" '.tmpl') | ||
echo "${output_dir}/${destname}" | ||
} | ||
|
||
for file in $files; do | ||
fill_in "${file}" > $(output_filename "${file}") | ||
done |