Skip to content

Commit

Permalink
feat(nginx): add auto-reloading (#64)
Browse files Browse the repository at this point in the history
  • Loading branch information
damienwebdev committed Aug 4, 2022
1 parent 1f00d6b commit 8637597
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 3 deletions.
10 changes: 8 additions & 2 deletions nginx/1.18/alpine-develop/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,24 @@ FROM nginx:1.18-alpine

MAINTAINER Damien Retzinger <[email protected]>

RUN apk update && apk add openssl
RUN apk update && apk add --no-cache inotify-tools openssl
RUN mkdir /etc/nginx/certs \
&& echo -e "\n\n\n\n\n\n\n" | openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /etc/nginx/certs/nginx.key -out /etc/nginx/certs/nginx.crt

COPY ./conf/nginx.conf /etc/nginx/
COPY ./conf/default.conf.template /etc/nginx/templates/

COPY scripts/entrypoint.sh /docker-entrypoint.d/
COPY scripts/nginxReloader.sh /root/scripts/

RUN chmod +x /docker-entrypoint.d/entrypoint.sh
RUN chmod +x /root/scripts/nginxReloader.sh

ENV MAGENTO2_UPSTREAM=localhost
ENV MAGENTO2_UPSTREAM_PORT=9000
ENV NGINX_PORT=8000
ENV NGINX_TLS_PORT=8443

EXPOSE 8443

WORKDIR /var/www/html
WORKDIR /var/www/html
4 changes: 4 additions & 0 deletions nginx/1.18/alpine-develop/scripts/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/sh
set -e

sh -c "/root/scripts/nginxReloader.sh &"
13 changes: 13 additions & 0 deletions nginx/1.18/alpine-develop/scripts/nginxReloader.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/sh

while true
do
inotifywait --include="(nginx\.conf\.sample|nginx\.conf)" -e create -e modify -e delete -e move /var/www/html/
nginx -t
if [ $? -eq 0 ]
then
echo "Detected Nginx Configuration Change"
echo "Executing: nginx -s reload"
nginx -s reload
fi
done
8 changes: 7 additions & 1 deletion nginx/1.19/alpine-develop/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,19 @@ FROM nginx:1.19-alpine

MAINTAINER Damien Retzinger <[email protected]>

RUN apk update && apk add openssl
RUN apk update && apk add --no-cache inotify-tools openssl
RUN mkdir /etc/nginx/certs \
&& echo -e "\n\n\n\n\n\n\n" | openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /etc/nginx/certs/nginx.key -out /etc/nginx/certs/nginx.crt

COPY ./conf/nginx.conf /etc/nginx/
COPY ./conf/default.conf.template /etc/nginx/templates/

COPY scripts/entrypoint.sh /docker-entrypoint.d/
COPY scripts/nginxReloader.sh /root/scripts/

RUN chmod +x /docker-entrypoint.d/entrypoint.sh
RUN chmod +x /root/scripts/nginxReloader.sh

ENV MAGENTO2_UPSTREAM=localhost
ENV MAGENTO2_UPSTREAM_PORT=9000
ENV NGINX_PORT=8000
Expand Down
4 changes: 4 additions & 0 deletions nginx/1.19/alpine-develop/scripts/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/sh
set -e

sh -c "/root/scripts/nginxReloader.sh &"
13 changes: 13 additions & 0 deletions nginx/1.19/alpine-develop/scripts/nginxReloader.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/sh

while true
do
inotifywait --include="(nginx\.conf\.sample|nginx\.conf)" -e create -e modify -e delete -e move /var/www/html/
nginx -t
if [ $? -eq 0 ]
then
echo "Detected Nginx Configuration Change"
echo "Executing: nginx -s reload"
nginx -s reload
fi
done

0 comments on commit 8637597

Please sign in to comment.