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.
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user