From ad0cdfe1d9265288408f6e3538c5315ce7a7d747 Mon Sep 17 00:00:00 2001 From: chamiakJ Date: Mon, 28 Apr 2025 21:54:31 +0530 Subject: [PATCH 1/2] Enhance startup scripts with environment update checks and service URL clarity - Added checks for the existence of the update-docker-env.sh script in both start.bat and start.sh, providing guidance for updating environment variables. - Removed legacy .env file checks from both scripts to streamline the startup process. - Updated service URL outputs to clarify SSL options for both frontend and backend services. - Improved user instructions for stopping services and updating environment variables. --- start.bat | 24 +++++++++++------------- start.sh | 21 +++++++++------------ 2 files changed, 20 insertions(+), 25 deletions(-) diff --git a/start.bat b/start.bat index 78f6837a..9c324fd9 100644 --- a/start.bat +++ b/start.bat @@ -39,6 +39,12 @@ IF %ERRORLEVEL% NEQ 0 ( echo docker-compose is installed >> worklenz_startup.log ) +REM Check for update-docker-env.sh +IF EXIST update-docker-env.sh ( + echo [94mFound update-docker-env.sh script. You can use it to update environment variables.[0m + echo Found update-docker-env.sh script >> worklenz_startup.log +) + REM Run preflight checks echo Running Docker daemon check... docker info >nul 2>>worklenz_startup.log @@ -52,17 +58,6 @@ IF %ERRORLEVEL% NEQ 0 ( echo Docker daemon is running >> worklenz_startup.log ) -REM Check if .env file exists -IF NOT EXIST .env ( - echo Warning: .env file not found. Using default configuration. - echo Warning: .env file not found. Using default configuration. >> worklenz_startup.log - IF EXIST .env.example ( - copy .env.example .env - echo Created .env file from .env.example - echo Created .env file from .env.example >> worklenz_startup.log - ) -) - REM Stop any running containers echo Stopping any running containers... docker-compose down > nul 2>>worklenz_startup.log @@ -111,7 +106,7 @@ REM Check frontend findstr /C:"frontend" running_services.txt > nul IF %ERRORLEVEL% EQU 0 ( echo [92m^✓[0m Frontend is running - echo Frontend URL: http://localhost:5000 + echo Frontend URL: http://localhost:5000 (or https://localhost:5000 if SSL is enabled) echo Frontend is running >> worklenz_startup.log ) ELSE ( echo [91m^✗[0m Frontend service failed to start @@ -122,7 +117,7 @@ REM Check backend findstr /C:"backend" running_services.txt > nul IF %ERRORLEVEL% EQU 0 ( echo [92m^✓[0m Backend is running - echo Backend URL: http://localhost:3000 + echo Backend URL: http://localhost:3000 (or https://localhost:3000 if SSL is enabled) echo Backend is running >> worklenz_startup.log ) ELSE ( echo [91m^✗[0m Backend service failed to start @@ -180,6 +175,9 @@ IF %allRunning% EQU 1 ( echo You can access the application at: http://localhost:5000 echo To stop the services, run: stop.bat +echo To update environment variables, run: update-docker-env.sh +echo. +echo Note: To enable SSL, set ENABLE_SSL=true in your .env file and run update-docker-env.sh echo. echo For any errors, check worklenz_startup.log file echo. diff --git a/start.sh b/start.sh index b1b8b12d..47d88bae 100755 --- a/start.sh +++ b/start.sh @@ -20,14 +20,9 @@ echo " W O R K L E N Z " echo -e "${NC}" echo "Starting Worklenz Docker Environment..." -# Check if .env file exists -if [ ! -f .env ]; then - echo -e "${YELLOW}Warning: .env file not found. Using default configuration.${NC}" - # Copy the example .env file if it exists - if [ -f .env.example ]; then - cp .env.example .env - echo "Created .env file from .env.example" - fi +# Check if update-docker-env.sh exists and is executable +if [ -f update-docker-env.sh ] && [ -x update-docker-env.sh ]; then + echo -e "${BLUE}Found update-docker-env.sh script. You can use it to update environment variables.${NC}" fi # Function to check if a service is running @@ -129,7 +124,7 @@ DB_STATUS=$? check_service "MinIO" "worklenz_minio" "http://localhost:9000/minio/health/live" MINIO_STATUS=$? -check_service "Backend" "worklenz_backend" "http://localhost:3000/api/health" +check_service "Backend" "worklenz_backend" "http://localhost:3000/public/health" BACKEND_STATUS=$? check_service "Frontend" "worklenz_frontend" "http://localhost:5000" @@ -137,8 +132,8 @@ FRONTEND_STATUS=$? # Display service URLs echo -e "\n${BLUE}Service URLs:${NC}" -[ $FRONTEND_STATUS -eq 0 ] && echo " • Frontend: http://localhost:5000" -[ $BACKEND_STATUS -eq 0 ] && echo " • Backend API: http://localhost:3000" +[ $FRONTEND_STATUS -eq 0 ] && echo " • Frontend: http://localhost:5000 (or https://localhost:5000 if SSL is enabled)" +[ $BACKEND_STATUS -eq 0 ] && echo " • Backend API: http://localhost:3000 (or https://localhost:3000 if SSL is enabled)" [ $MINIO_STATUS -eq 0 ] && echo " • MinIO Console: http://localhost:9001 (login: minioadmin/minioadmin)" # Check if all services are up @@ -151,4 +146,6 @@ fi echo -e "\n${BLUE}Useful commands:${NC}" echo " • View logs: $DOCKER_COMPOSE_CMD logs -f" -echo " • Stop services: ./stop.sh" \ No newline at end of file +echo " • Stop services: ./stop.sh" +echo " • Update environment variables: ./update-docker-env.sh" +echo -e "\n${YELLOW}Note:${NC} To enable SSL, set ENABLE_SSL=true in your .env file and run ./update-docker-env.sh" \ No newline at end of file From b48ac450855e5b4a31d451022beac8ef97df99e7 Mon Sep 17 00:00:00 2001 From: chamiakJ Date: Mon, 28 Apr 2025 22:04:00 +0530 Subject: [PATCH 2/2] Refactor Dockerfile to streamline environment configuration - Introduced a new env-config.sh script to handle runtime environment variable updates for VITE_API_URL and VITE_SOCKET_URL. - Updated start.sh to execute env-config.sh, improving script organization and clarity. - Enhanced the overall structure of the Dockerfile for better maintainability. --- worklenz-frontend/Dockerfile | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/worklenz-frontend/Dockerfile b/worklenz-frontend/Dockerfile index 37dffae6..a32f879e 100644 --- a/worklenz-frontend/Dockerfile +++ b/worklenz-frontend/Dockerfile @@ -23,13 +23,20 @@ RUN npm install -g serve COPY --from=build /app/build /app/build COPY --from=build /app/public/env-config.js /app/build/env-config.js +# Create env-config.sh script +RUN echo '#!/bin/sh' > /app/env-config.sh && \ + echo '# Update env-config.js with runtime environment variables' >> /app/env-config.sh && \ + echo 'cat > /app/build/env-config.js << EOL' >> /app/env-config.sh && \ + echo 'window.VITE_API_URL="${VITE_API_URL:-http://backend:3000}";' >> /app/env-config.sh && \ + echo 'window.VITE_SOCKET_URL="${VITE_SOCKET_URL:-ws://backend:3000}";' >> /app/env-config.sh && \ + echo 'EOL' >> /app/env-config.sh && \ + chmod +x /app/env-config.sh + # Create start.sh script RUN echo '#!/bin/sh' > /app/start.sh && \ - echo '# Update env-config.js with runtime environment variables' >> /app/start.sh && \ - echo 'cat > /app/build/env-config.js << EOL' >> /app/start.sh && \ - echo 'window.VITE_API_URL="${VITE_API_URL:-http://backend:3000}";' >> /app/start.sh && \ - echo 'window.VITE_SOCKET_URL="${VITE_SOCKET_URL:-ws://backend:3000}";' >> /app/start.sh && \ - echo 'EOL' >> /app/start.sh && \ + echo '# Run environment configuration' >> /app/start.sh && \ + echo '/app/env-config.sh' >> /app/start.sh && \ + echo '# Start the server' >> /app/start.sh && \ echo 'exec serve -s build -l 5000' >> /app/start.sh && \ chmod +x /app/start.sh