Refactor start.sh script creation in Dockerfile
- Updated the Dockerfile to create the start.sh script in a more structured manner, improving readability and maintainability. - Ensured that the script dynamically updates env-config.js with runtime environment variables for API and WebSocket URLs.
This commit is contained in:
@@ -23,15 +23,15 @@ RUN npm install -g serve
|
|||||||
COPY --from=build /app/build /app/build
|
COPY --from=build /app/build /app/build
|
||||||
COPY --from=build /app/public/env-config.js /app/build/env-config.js
|
COPY --from=build /app/public/env-config.js /app/build/env-config.js
|
||||||
|
|
||||||
# Create a script to start server and dynamically update env-config.js
|
# Create start.sh script
|
||||||
RUN echo '#!/bin/sh\n\
|
RUN echo '#!/bin/sh' > /app/start.sh && \
|
||||||
# Update env-config.js with runtime environment variables\n\
|
echo '# Update env-config.js with runtime environment variables' >> /app/start.sh && \
|
||||||
cat > /app/build/env-config.js << EOL\n\
|
echo 'cat > /app/build/env-config.js << EOL' >> /app/start.sh && \
|
||||||
window.VITE_API_URL="${VITE_API_URL:-http://backend:3000}";\n\
|
echo 'window.VITE_API_URL="${VITE_API_URL:-http://backend:3000}";' >> /app/start.sh && \
|
||||||
window.VITE_SOCKET_URL="${VITE_SOCKET_URL:-ws://backend:3000}";\n\
|
echo 'window.VITE_SOCKET_URL="${VITE_SOCKET_URL:-ws://backend:3000}";' >> /app/start.sh && \
|
||||||
EOL\n\
|
echo 'EOL' >> /app/start.sh && \
|
||||||
exec serve -s build -l 5000' > /app/start.sh && \
|
echo 'exec serve -s build -l 5000' >> /app/start.sh && \
|
||||||
chmod +x /app/start.sh
|
chmod +x /app/start.sh
|
||||||
|
|
||||||
EXPOSE 5000
|
EXPOSE 5000
|
||||||
CMD ["/app/start.sh"]
|
CMD ["/app/start.sh"]
|
||||||
Reference in New Issue
Block a user