generated from nginx/template-repository
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
enhance compose with a node container to watch for changes, rebuild t…
…he .js, and notify nginx to reload
- Loading branch information
1 parent
b595572
commit 4525c7b
Showing
3 changed files
with
48 additions
and
23 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,14 @@ | ||
|
||
ARG NGINX_VERSION=1.24.0 | ||
|
||
FROM node:20.2.0-bullseye AS builder | ||
ENV NODE_ENV=development | ||
WORKDIR /app | ||
COPY package.json package-lock.json* ./ | ||
RUN npm ci | ||
COPY ./.mocharc.js ./ | ||
COPY ./babel.config.js ./ | ||
COPY ./rollup.config.js ./ | ||
COPY ./tsconfig.json ./ | ||
COPY ./src ./src | ||
|
||
RUN npm run build | ||
|
||
FROM nginx:${NGINX_VERSION} | ||
ARG NGINX_VERSION | ||
FROM nginx:1.24.0 | ||
|
||
# following installation steps from http://nginx.org/en/linux_packages.html#Debian | ||
RUN --mount=type=cache,target=/var/cache/apt <<EOF | ||
set -eux | ||
export DEBIAN_FRONTEND=noninteractive | ||
apt-get -qq update | ||
apt-get -qq install --yes --no-install-recommends --no-install-suggests \ | ||
curl gnupg2 ca-certificates debian-archive-keyring | ||
curl gnupg2 ca-certificates debian-archive-keyring inotify-tools | ||
update-ca-certificates | ||
apt-get remove --purge --auto-remove --yes | ||
rm -rf /var/lib/apt/lists/* /etc/apt/sources.list.d/nginx.list | ||
EOF | ||
RUN mkdir -p /usr/lib/nginx/njs_modules | ||
COPY --from=builder /app/dist/* /usr/lib/nginx/njs_modules/ |
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 |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#!/bin/sh | ||
JS_FILE=/usr/lib/nginx/njs_modules/acme.js | ||
|
||
# wait until the .js file appears | ||
while ! [ -f $JS_FILE ] | ||
do | ||
echo "Waiting for $JS_FILE to appear..." | ||
sleep 1 | ||
done | ||
|
||
# start nginx in background | ||
echo "Starting nginx..." | ||
$@ & | ||
|
||
sleep 3 | ||
|
||
echo "Watching for changes..." | ||
|
||
# when the .js file is modified, reload nginx | ||
inotifywait -m -e create,modify $JS_FILE | | ||
while read filename | ||
do | ||
nginx -s reload | ||
done |