Improve Docker Deployment Script with Error Handling, Detached Mode, and Rebuild Options #1320
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This pull request enhances the existing entrypoint.sh script by introducing the following improvements for a more robust and flexible Docker-based deployment process:
Error Handling:
Added error handling to ensure that if any docker compose command fails, the script exits with a clear error message. This prevents the script from continuing execution after encountering issues, ensuring a more reliable deployment.
Detached Mode (-d):
Enabled Docker Compose to run in detached mode (-d), ensuring the containers start in the background without blocking the terminal. This makes the process more efficient, especially for long-running services.
Rebuild on Start (--build):
Introduced the --build flag to force Docker Compose to rebuild the images before starting the containers. This ensures that any changes to the Dockerfile or source code are reflected in the running containers without needing manual intervention.
Graceful Shutdown (Optional):
Added a commented-out line for a graceful shutdown using docker compose down, allowing developers to easily stop and remove containers after they are no longer needed. This can be uncommented based on the desired behavior.
Details:
Azure-Specific vs. Default Configuration:
The script still checks for the presence of Azure-related environment variables (OPENAI_API_BASE, OPENAI_API_VERSION, AZURE_DEPLOYMENT_NAME, AZURE_EMBEDDINGS_DEPLOYMENT_NAME) to determine whether to use the Azure-specific Docker Compose file (docker-compose-azure.yaml) or the default configuration.
Error Handling:
The handle_error function was introduced to capture errors from Docker Compose commands and print a clear error message to standard error (stderr). If any command fails, the script immediately exits with a failure status (exit 1).
Docker Compose Improvements:
Detached Mode: Containers are now started in the background with docker compose up -d.
Rebuild on Start: The --build flag ensures that the Docker images are rebuilt before the containers are started, reflecting any changes to the source code.