Skip to content

Commit

Permalink
enhance compose with a node container to watch for changes, rebuild t…
Browse files Browse the repository at this point in the history
…he .js, and notify nginx to reload
  • Loading branch information
zsteinkamp committed Jun 14, 2023
1 parent b595572 commit 4525c7b
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 23 deletions.
22 changes: 2 additions & 20 deletions Dockerfile
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/
25 changes: 22 additions & 3 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
version: '3'
services:
pebble:
image: letsencrypt/pebble:latest
platform: linux/amd64
command: pebble -config /etc/pebble/config.json
hostname: pebble
volumes:
Expand All @@ -12,18 +12,35 @@ services:
- 15000:15000 # HTTPS Management API
challtestsrv:
image: letsencrypt/pebble-challtestsrv:latest
platform: linux/amd64
command: pebble-challtestsrv -defaultIPv6 "" -defaultIPv4 10.30.50.3
hostname: challtestsrv
ports:
- 8055:8055 # HTTP Management API
node:
build:
context: .
dockerfile_inline: |
FROM node:18
WORKDIR /app
COPY package*.json .
RUN npm ci
CMD npm run watch
volumes:
- .:/app
- node_modules:/app/node_modules
- node_dist:/app/dist
nginx:
image: nginxinc/njs-acme-experemental
build: .
command: nginx -c examples/nginx.conf
command: /nginx_wait_for_js nginx -c examples/nginx.conf
depends_on:
- node
hostname: proxy.nginx.com
volumes:
- ./examples:/etc/nginx/examples/
# - ./dist:/etc/nginx/dist/
- ./nginx_wait_for_js:/nginx_wait_for_js
- node_dist:/usr/lib/nginx/njs_modules/
- certs:/etc/letsencrypt/
environment:
- NJS_ACME_DIR=/etc/letsencrypt/
Expand All @@ -41,3 +58,5 @@ services:
start_period: 10s
volumes:
certs:
node_modules:
node_dist:
24 changes: 24 additions & 0 deletions nginx_wait_for_js
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

0 comments on commit 4525c7b

Please sign in to comment.