Issue Configuring MEDPLUM_BASE_URL for medplum/med...
# dev
l
I'm deploying the medplum/medplum-app:latest Docker image to Google Cloud Run and trying to configure the backend API URL using the MEDPLUM_BASE_URL environment variable. The image includes the standard docker-entrypoint.sh that uses sed to replace placeholders like __MEDPLUM_BASE_URL__ in the static assets. I've set MEDPLUM_BASE_URL=https://fhir.precisionlongevity.io/ in my Cloud Run service configuration. I've even added debug echo statements to a custom version of the entrypoint script (based on the public one), and my Cloud Run container logs confirm: MY_DEBUG_ENTRYPOINT: Initial MEDPLUM_BASE_URL from environment is [https://fhir.precisionlongevity.io/] MY_DEBUG_ENTRYPOINT: MEDPLUM_BASE_URL after default assignment is [https://fhir.precisionlongevity.io/] The entrypoint script appears to complete, and echo "Environment variable replacement complete." is logged before Nginx starts. Despite this, when I access the deployed medplum-app UI in my browser (after IAP authentication), the browser console shows the error: Error: Base URL must start with http or https. Even when I remove MEDPLUM_BASE_URL from my Cloud Run environment variables (which should cause the entrypoint script's default of http://localhost:8103/ to be used for the sed replacement), I still get the exact same "Base URL must start with http or https" error. This leads me to believe that the __MEDPLUM_BASE_URL__ placeholder (and possibly others) might be missing from the static JavaScript assets within the current medplum/medplum-app:latest image, or there's another issue preventing the sed replacement from taking effect on the client-side bundle. Could you confirm if the __MEDPLUM_BASE_URL__ placeholder is expected to be in the JS assets of medplum/medplum-app:latest for the entrypoint script's sed replacement to work? Is there an alternative or recommended way to provide this runtime configuration for the Docker image on platforms like Cloud Run? Thanks for any insights!
f
Hey @loesche, sorry about this. Have you tried to run the medplum/medplum-app:latest Docker image locally while pointing the MEDPLUM_BASE_URL=https://fhir.precisionlongevity.io/ ? I am wondering if we can start by isolating the problem to either the way that your environment variables are being specified or the setup in Google Cloud Run.
l
Yes I did and it wasn't working yesterday. I would get the error about needing to start with http. Today, I tried the latest medplum-app and now I don't get that error. It does however continue to point to localhost. The medplum base url is being set in the deployment UI under the environment variables tab. I tried it with the google cloud cli and got the same result.
f
Got it. And how are you specifying your environment variables for the app when running the medplum/medplum-app:latest image locally?
l
I am not running it locally. I am deploying on Cloud Run straight from the publicly available medplum/medplum-app image on Docker.
f
Can you try starting fresh? The image expects to find a literal placeholder (__MEDPLUM_BASE_URL__) in its static JS files so that the docker-entrypoint.sh script can sed-replace it at container startup. If you already replaced it once, then it won't find anything to replace.
l
Yeah, I have tried starting fresh a few times. I have used every version 4.1-4.1.4 and had the same result. They don't seem to be replacing the default values with the environment variables. That's why I tried doing some debugging to find where the issue was. What I know is that I am successfully getting the environment variables in because I can see that in the console. It seems there is something broken in taking the environment variable and updating the defaults when the server starts.
It looks like this was an issue for somebody else too, but it is unclear how it got fixed. https://discord.com/channels/905144809105260605/1362870024355975380
For full disclosure, I am running it on a GCP Cloud Run not the full terraform based install that is on the documentation.
f
Ok, gotcha
Sounds like a bug. I am going to try to reproduce in Google Cloud Run, and if I get that same error, I can file a github issue to get this fixed
I filed an issue for this [here](https://github.com/medplum/medplum/issues/6567)
l
Thank you!
Also, this happened with the mepdlum-server, but I was able to fix it with by adding "env" to the entrypoint script. Wondering if it is the same or similar issue.
f
OK gotcha! Thanks for all the info @loesche !
l
Hey, I wanted to follow up here. You all definitely fixed the server problem - AMAZING! But.... the app issue persists. I have been investigating and I think I may have found a clue. After the build step, I don't see any of the placeholders available to be replaced by the entrypoint script sed command. I think it may have to do with the build step wehre Vite is replacing things like "process.env.MEDPLUM_BASE_URL" with the default environment variables instead of the placeholder "__MEDPLUM_BASE_URL__". This would prevent anybody from using any runtime env variables during deployment because there is no placeholder to replace with the entrypoint script. Let me know if I'm way off here. Thanks for all of your support!
161 Views