Skip to content

Commit

Permalink
use docker compose healthchecks
Browse files Browse the repository at this point in the history
  • Loading branch information
mike-marcacci committed Jan 5, 2024
1 parent beadd7a commit 362b154
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 21 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ ADD packages/strategy-saml/package.json /workspace/packages/strategy-saml/packag
ADD packages/tools/package.json /workspace/packages/tools/package.json

# Install all dependencies
RUN npm ci
RUN npm ci --ignore-scripts

# Add in the entire working directory
ADD . /workspace
Expand Down
56 changes: 39 additions & 17 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ version: "3.7"

volumes:
postgres:
authx-init:

services:

# This container runs the database.
postgres:
image: postgres:9.6.17
restart: always
Expand All @@ -20,48 +20,73 @@ services:
published: ${PUBLISH_PORT_POSTGRES}
protocol: tcp
mode: host
user: postgres
healthcheck:
test: ["CMD", "pg_isready"]
start_period: 5s
start_interval: 10s
interval: 10s
timeout: 3s
retries: 3

# This container installs node modules into the node_modules volume.
# This container installs node modules from the package-lock.json file.
installer:
image: node:16.16.0
working_dir: /workspace
command: ./scripts/install.sh

# We would rather ignore scripts, but this repo depends on bcrypt, which
# requires a build step.
# command: npm ci --ignore-scripts
command: scripts/install.sh

environment:
NODE_ENV: development
volumes:
- type: bind
source: .
target: /workspace
- type: volume
source: authx-init
target: /var/tmp/authx-init
healthcheck:
test: ["CMD", "test", "-f", "/tmp/package-lock.json"]
start_period: 5s
start_interval: 10s
interval: 10s
timeout: 3s
retries: 6

# This container watches for changes and builds the application.
builder:
depends_on:
- installer
installer:
condition: service_healthy
restart: false
image: node:16.16.0
working_dir: /workspace
entrypoint: ./scripts/await.sh /var/tmp/authx-init/installer-complete
command: npm run build:development:chained
environment:
NODE_ENV: development
volumes:
- type: bind
source: .
target: /workspace
- type: volume
source: authx-init
target: /var/tmp/authx-init
healthcheck:
test: ["CMD", "test", "-f", "dist/server.js"]
start_period: 5s
start_interval: 10s
interval: 10s
timeout: 3s
retries: 6

# This container runs the server.
server:
depends_on:
- builder
- postgres
builder:
condition: service_healthy
restart: false
postgres:
condition: service_healthy
restart: false
image: node:16.16.0
working_dir: /workspace
entrypoint: ./scripts/await.sh /var/tmp/authx-init/installer-complete ./scripts/await.sh dist/server.js
command: npm run start:development
environment:
NODE_ENV: development
Expand All @@ -72,9 +97,6 @@ services:
- type: bind
source: .
target: /workspace
- type: volume
source: authx-init
target: /var/tmp/authx-init
ports:
- target: 80
published: ${PUBLISH_PORT_HTTP}
Expand Down
6 changes: 3 additions & 3 deletions scripts/install.sh
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
while true; do
# Check if the current and previous package-lock.json are the same
if ( [ -f /var/tmp/authx-init/installer-complete ] && cmp -s ./package-lock.json /var/tmp/authx-init/installer-complete ); then
if ( [ -f /tmp/package-lock.json ] && cmp -s ./package-lock.json /tmp/package-lock.json ); then
echo "No changes detected in package-lock.json; sleeping..."
sleep 10
continue
fi

# Install dependencies and copy the new package-lock.json
echo "Changes detected in package-lock.json; installing packages..."
rm -f /var/tmp/authx-init/installer-complete
npm ci && cp package-lock.json /var/tmp/authx-init/installer-complete
rm -f /tmp/package-lock.json
npm install --package-lock-only && cp package-lock.json /tmp/package-lock.json
sleep 10
done

0 comments on commit 362b154

Please sign in to comment.