Add script to inject environment variables in Dockerfile

- Created a start.sh script to set environment variables for the application.
- Updated CMD to execute the new script instead of directly serving the build.
This commit is contained in:
chamikaJ
2025-04-25 16:42:45 +05:30
parent a328da679c
commit 9c27c41a5e

View File

@@ -16,5 +16,16 @@ WORKDIR /app
RUN npm install -g serve
COPY --from=build /app/build /app/build
# Create a script to inject environment variables
RUN echo '#!/bin/sh\n\
cat > /app/build/env.js << EOL\n\
window.env = {\n\
VITE_API_URL: "${VITE_API_URL}"\n\
};\n\
EOL\n\
exec serve -s build -l 5000' > /app/start.sh && \
chmod +x /app/start.sh
EXPOSE 5000
CMD ["serve", "-s", "build", "-l", "5000"]
CMD ["/app/start.sh"]