add a docker config for a monolithic app

This commit is contained in:
Alex Holliday
2025-05-19 15:00:11 -07:00
parent 885c63b147
commit 72cd3b592e
5 changed files with 94 additions and 0 deletions

View File

@@ -0,0 +1,29 @@
#!/bin/bash
# Change directory to root Server directory for correct Docker Context
cd "$(dirname "$0")"
cd ../..
# Define service names and their corresponding Dockerfiles in parallel arrays
services=("mono_mongo" "mono_redis" "mono_server")
dockerfiles=(
"./docker/dist-mono/mongoDB.Dockerfile"
"./docker/dist-mono/redis.Dockerfile"
"./docker/dist-mono/server.Dockerfile"
)
# Loop through each service and build the corresponding image
for i in "${!services[@]}"; do
service="${services[$i]}"
dockerfile="${dockerfiles[$i]}"
docker build -f "$dockerfile" -t "$service" .
# Check if the build succeeded
if [ $? -ne 0 ]; then
echo "Error building $service image. Exiting..."
exit 1
fi
done
echo "All images built successfully"

View File

@@ -0,0 +1,35 @@
services:
server:
image: mono_server:latest
restart: always
ports:
- "52345:52345"
env_file:
- server.env
depends_on:
- redis
- mongodb
redis:
image: mono_redis:latest
restart: always
volumes:
- ./redis/data:/data
healthcheck:
test: ["CMD", "redis-cli", "ping"]
interval: 30s
timeout: 10s
retries: 5
start_period: 5s
mongodb:
image: mono_mongo:latest
restart: always
command: ["mongod", "--quiet", "--replSet", "rs0", "--bind_ip_all"]
volumes:
- ./mongo/data:/data/db
healthcheck:
test: echo "try { rs.status() } catch (err) { rs.initiate({_id:'rs0',members:[{_id:0,host:'mongodb:27017'}]}) }" | mongosh --port 27017 --quiet
interval: 5s
timeout: 30s
start_period: 0s
start_interval: 1s
retries: 30

View File

@@ -0,0 +1,3 @@
FROM mongo
EXPOSE 27017
CMD ["mongod"]

View File

@@ -0,0 +1,2 @@
FROM redis
EXPOSE 6379

View File

@@ -0,0 +1,25 @@
FROM node:20-alpine AS frontend-build
WORKDIR /app/client
COPY client/package*.json ./
RUN npm install
COPY client ./
RUN npm run build
FROM node:20-alpine AS app
WORKDIR /app/server
COPY server ./
COPY --from=frontend-build /app/client/dist ./public
RUN npm install
RUN chmod +x ./scripts/inject-vars.sh
EXPOSE 52345
CMD ./scripts/inject-vars.sh && node ./index.js