Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize Docker Build Script for Maintainability and Error Handling #989

Merged
merged 6 commits into from
Oct 21, 2024
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 20 additions & 19 deletions Docker/dev/build_images.sh
Original file line number Diff line number Diff line change
@@ -1,24 +1,25 @@

#!/bin/bash

# Change directory to root Server directory for correct Docker Context
cd ../..

#Client
client="./Docker/dev/client.Dockerfile"

# MongoDB
mongoDB="./Docker/dev/mongoDB.Dockerfile"

# Redis
redis="./Docker/dev/redis.Dockerfile"

# Server
server="./Docker/dev/server.Dockerfile"

docker build -f $client -t uptime_client .
docker build -f $mongoDB -t uptime_database_mongo .
docker build -f $redis -t uptime_redis .
docker build -f $server -t uptime_server .

echo "All images built"
# Define an array of services and their Dockerfiles
declare -A services=(
["uptime_client"]="./Docker/dev/client.Dockerfile"
["uptime_database_mongo"]="./Docker/dev/mongoDB.Dockerfile"
["uptime_redis"]="./Docker/dev/redis.Dockerfile"
["uptime_server"]="./Docker/dev/server.Dockerfile"
)

# Loop through each service and build the corresponding image
for service in "${!services[@]}"; do
docker build -f "${services[$service]}" -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"