I have a project that is a full stack web application consisting of a frontend (vite ecs container) and backend (java spring boot ecs container). An ALB will point to the frontend, and backend. My terraform file feeds the ALB URL into the frontend’s task definition as an environment variable so that it can make this connection. My containers are stored in AWS ECR. I want this to be an easy process so that I can simply build containers on my machine, and run the terraform.
My main issue is that vite uses environment variables at BUILD TIME, not RUN TIME. So when I run npm build, it injects the environment variables on my LOCAL machine into the newly created image (not correct!). I want it to use the environment variables fed into the task definition! else I have to run the deploy script, build a new image with manually updated URL, and then run deploy script again
Can I have it be so that my image is built on the docker image? Or is there a better way to pull this URL down?
I looked into this package and could not get it to work, seems to not fit this purpose: https://github.com/andrewmclagan/react-env
I also looked into possibly having it uploaded on nginx.conf but this seems to be a very difficult thing to figure out.
Similarly for docker-in-docker.
5
Reading between the lines, it looks like this is actually an nginx container, serving a React application? If this is being served by the same load balancer as the backend, can’t you have your react code simply check what the current hostname is (window.location.hostname), and use that to build the backend API URLs? –
Mark B
Commented 14 hours ago